Spring integration outbound-gateway want to use URL as dynamic like

折月煮酒 提交于 2019-12-06 07:28:47

You can set meta data like URL or http method as headers. You can even use Spring EL when setting the header, f.e.

<int:header-enricher>
    <int:header name="url" value="${url.base}/reports/"/>
</int:header-enricher>

and then use an expression for the outbound gateway

 <int-http:outbound-gateway id='httpGateway'
 url-expression="headers['url']"
...
  />

The http-method is not part of the URI; it does not support or use uri-variables.

Use http-method-expression="payload.reqMethod" instead.

Similarly, Accept is not part of the uri - set the Accept header in the outbound message, it will be mapped.

EDIT

You are confusing runtime expressions with bean declaration expressions and, as I said, you need to use method expression if you want a runtime method selection.

However, since you are using a bean for your Requestvalues you don't need runtime expressions at all.

<int-http:outbound-gateway
            request-channel="reqChannel" url="#{requestValues.getUrl()}"
            http-method=""#{requestValues.getReqMethod()}" expected-response-type="java.lang.String"  header-mapper="headerMapper"
            charset="UTF-8" reply-timeout="5000" reply-channel="responseChannel"  >
</int-http:outbound-gateway>

If you want to select the method and url at runtime, based on the message, you would use something like...

<int-http:outbound-gateway
            request-channel="reqChannel" url="${UrlValue}"
            http-method-expression="headers['method']" expected-response-type="java.lang.String"  header-mapper="headerMapper"
            charset="UTF-8" reply-timeout="5000" reply-channel="responseChannel"  >
        <int-http:uri-variable name="UrlValue" expression="headers['url']" />
</int-http:outbound-gateway>

Where the headers are set dynamically somewhere upstream, or

<int-http:outbound-gateway
            request-channel="reqChannel" url="${UrlValue}"
            http-method-expression="@requestValues.getReqMethod()" expected-response-type="java.lang.String"  header-mapper="headerMapper"
            charset="UTF-8" reply-timeout="5000" reply-channel="responseChannel"  >
        <int-http:uri-variable name="UrlValue" expression="@requestValues.getUrl()" />
</int-http:outbound-gateway>

Notice the use of @ to refer to beans in runtime expressions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!