Spring Integration Http Outbound Gateway and variable url


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.

Comments

Miki said…
I completely agree with you!
That's how it should work. Spring integration.
I love spring!

Popular posts from this blog

Relaxing SSL validation for JaxWS

Kaspersky Anti Virus 6 and Subversion problems

Search and Replace in ODT using AODL