Archive for the ‘spring-integration’ Category

Spring Integration Http Outbound Gateway and variable url

Wednesday, September 21st, 2011
I’ve recently had to deal with spring integration and in particular the http outbound gateway component. One possible use case for it would be to have to send the message out to an arbitrary url. In order to accomplish this, we can insert the final url in a custom header (here X-CUSTOM-HTTP-REQUEST-URL) and use the Spring expression language (SpEL) to extract the header value and pass that as a variable to the url property. Sweet!

 
<http:outbound-gateway id="httpOutboundGateway" request-channel="httpOutboundGatewayRequestChannel" url="{outboundGatewayUrl}" reply-channel="httpOutboundGatewayReplyChannel" expected-response-type="java.lang.String" charset="UTF-8">
<http:uri-variable name="outboundGatewayUrl" expression="headers['X-CUSTOM-HTTP-REQUEST-URL']" />
</http:outbound-gateway>


PS. If Spring Integration seems to be eating your headers, there’s a reason for it, you need to specifically map all non standard headers. If interested post a comment.