In order to send http request to dynamic urls based on message headers…
I am trying to set the url value from Message header as follows:
<int-http:outbound-gateway id="httpOutboundGateway" request-channel="fromMyQueue"
url="{outboundGatewayUrl}" reply-channel="nullChannel"
http-method="POST" expected-response-type="java.lang.String" charset="UTF-8">
<int-http:uri-variable name="outboundGatewayUrl" expression="headers['X-CUSTOM-HTTP-REQUEST-URL']" />
But this is not working.
Apparently {outboundGatewayUrl} value is not being replaced at all.
This works if i replace the {outboundGatewayUrl} with actual URL.
Error Message:
Caused by:
org.springframework.integration.MessageHandlingException: HTTP request execution failed for URI [{outboundGatewayUrl}]...
Caused by:<br> java.lang.IllegalArgumentException: URI is not absolute
at java.net.URI.toURL(URI.java:1080)
at org.springframework.http.client.SimpleClientHttpRequestFactory.createRequest(SimpleClientHttpRequestFactory.java:109)
What am i missing here?
It looks like header X-CUSTOM-HTTP-REQUEST-URL doesn’t exist in the message.
You will get that error (URI is not absolute) if the expression returns null (i.e. if the header doesn’t exist).
I just ran a test and it worked fine for me with a proper header; if you believe the header is correct, you should break down the problem; for example by using a literal expression first…
The error message is, perhaps somewhat misleading:
because it implies the url wasn’t expanded. The problem is the expansion is done inside the RestTemplate and the adapter doesn’t have access to it.