Reputation: 31
spring Integration,in outbound-gateway want to use URL as dynamic like
<bean id="requestValues" class="com.src.model.RequestValues"/>
<int-http:outbound-gateway
request-channel="reqChannel" url="${UrlValue}"
http-method="${reqmethod}" 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:uri-variable name="reqmethod" expression="#{requestValues.getReqMethod()}" />
</int-http:outbound-gateway>
Here Requestvalues is simple POJO it like
@Data
public class Requestvalues {
public String Url;
public String reqMethod;
}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler#0': Cannot create inner bean '(inner bean)#6ea2bc93' of type [org.springframework.integration.config.ExpressionFactoryBean] while setting bean property 'uriVariableExpressions' with key [url]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#6ea2bc93': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.config.ExpressionFactoryBean]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: expressionString must not be empty or null
Upvotes: 2
Views: 2552
Reputation: 174769
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.
Upvotes: 0
Reputation: 12049
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']"
...
/>
Upvotes: 3