[英]Spring Integration - url-variable not working in http:outbound-gateway
为了将HTTP请求发送到基于消息标头的动态url ...
我正在尝试从Message标头设置url值,如下所示:
<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']" />
但这是行不通的。
显然{outboundGatewayUrl}
值根本没有被替换。
如果我将{outboundGatewayUrl}
替换为实际URL,则此方法有效。
错误信息:
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)
我在这里想念什么?
我认为您在{outboundGatewayUrl}
之前缺少$
符号,因此SEL未对其进行扩展。 错误消息中也建议这样做。
邮件中似乎没有标题X-CUSTOM-HTTP-REQUEST-URL。
如果表达式返回null(即,如果标头不存在),则会收到该错误(URI不是绝对的)。
我只是运行了一个测试,并且使用合适的标题对我来说很好用; 如果您认为标题正确,则应该解决此问题; 例如,首先使用文字表达式...
<int-http:uri-variable name="outboundGatewayUrl" expression="'http://foo/bar'" />
该错误消息可能会引起误解:
Caused by:
org.springframework.integration.MessageHandlingException: HTTP request execution failed for URI [{outboundGatewayUrl}]...
因为这表示网址未扩展。 问题是扩展是在RestTemplate内部完成的,适配器无法访问它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.