Search code examples
springspring-integrationspring-integration-http

Spring Integration 6.x http outbound gateway http uri variable expression not evaluating application properties


We are using xml based configuration in our spring integration application. Code is being upgraded from Spring Integration v5.x to v6.x. With this we see while using http outbound gateway -> http uri variable is not evaluating application properties via expression that worked earlier. This results in error - URI is not absolute.

Following is example of the application configuration:

<int-http:outbound-gateway id="sampleGateway"
    request-channel="jsonInputChannel"
    url="{url}/call-some-api"
    http-method="POST"
    expected-response-type="java.lang.String"
    charset="UTF-8"
    reply-timeout="30000"
    reply-channel="nullChannel">
    <int-http:uri-variable name="url" expression="${sample.api.url}"/>
</int-http:outbound-gateway>

Here sample.api.url is defined in application.properties for environment specific base url.

${sample.api.url} should resolve from application properties and url="{url}/call-some-api" should construct proper url for the gateway. This worked with v5.x and should work with 6.x too. There is no documentation about this ability being removed.

We used logging adaptor to make sure the expression evaluates the application properties and has appropriate value.


Solution

  • Thank you for the sample project.

    After debugging I see that property placeholder is resolved correctly. But then when come to the RestTemplate.execute(), there is this logic:

    URI url = getUriTemplateHandler().expand(uriTemplate, uriVariables);
    

    And the result is like this:

    https%3A%2F%2Fgoogle.com%2Fsearch/call-some-api
    

    So, all those non-standard symbols (: and /) are encoded.

    You can add encoding-mode="NONE" to that <int-http:outbound-gateway> or consider to use url-expression instead of url.

    See more info in docs: https://docs.spring.io/spring-integration/reference/http/namespace.html#http-uri-encoding