在 Spring 集成 outbound-gateway 中将参数从 Java 传递到 url-expression
Passing arguments from Java to url-expression in Spring Integration outbound-gateway
RequestGateway.Java
public interface RequestGateway {
String echo(Map<String, String> request);
String echo(String request);
}
Test.java
Map<String, String> requestMap = new HashMap<String, String>();
requestMap.put("acccountId", "1111222233334444");
requestMap.put("currencyCode", "USD");
requestMap.put("paymentAmount", "100.00");
RequestGateway paymentRequestGateway = context.getBean("paymentRequestGateway", RequestGateway.class);
String availableCreditBalance = paymentRequestGateway.echo(requestMap);
SIConfig.xml
<int:gateway id="paymentRequestGateway"
service-interface="com.api.orchestration.api.RequestGateway"
default-request-channel="PaymentAuthRequestChannel"
default-reply-channel="ResponseChannel">
<int:default-header name="Accept" value="application/json; v=3"/>
<int:default-header name="Content-Type" value="application/json"/>
<int:default-header name="accountId" expression="payload.get('acccountId')"/>
</int:gateway>
<int-http:outbound-gateway
id="IG2 Outbound Gateway"
request-channel="IG2RequestChannel"
reply-channel="ResponseChannel"
header-mapper="headerMapper"
url-expression="'http://localhost:9090/balance/account/'+ headers['accountId']"
http-method="GET"
expected-response-type="java.lang.String">
</int-http:outbound-gateway>
如何从 Java 代码向 url-expression 传递参数,我可能在 default-header 中的表达式做错了什么?
这适用于 http:outbound-gateway
中的 url-expression
< int:default-header name="accountId" value="1111222233334444"/>
这不..
< int:default-header name="accountId" expression="payload.get('acccountId')"/>
"Error: EL1007E:(pos 0): Property or field 'payload' cannot be found on null"
你不能使用
< int:default-header name="accountId" expression="payload.get('acccountId')"/>
创建消息时;消息(以及有效负载)尚不存在。
您应该可以使用 #args[0]['accountId']
。
没有#root
object评价。请参阅 表达式和 "Global" Headers here。
RequestGateway.Java
public interface RequestGateway {
String echo(Map<String, String> request);
String echo(String request);
}
Test.java
Map<String, String> requestMap = new HashMap<String, String>();
requestMap.put("acccountId", "1111222233334444");
requestMap.put("currencyCode", "USD");
requestMap.put("paymentAmount", "100.00");
RequestGateway paymentRequestGateway = context.getBean("paymentRequestGateway", RequestGateway.class);
String availableCreditBalance = paymentRequestGateway.echo(requestMap);
SIConfig.xml
<int:gateway id="paymentRequestGateway"
service-interface="com.api.orchestration.api.RequestGateway"
default-request-channel="PaymentAuthRequestChannel"
default-reply-channel="ResponseChannel">
<int:default-header name="Accept" value="application/json; v=3"/>
<int:default-header name="Content-Type" value="application/json"/>
<int:default-header name="accountId" expression="payload.get('acccountId')"/>
</int:gateway>
<int-http:outbound-gateway
id="IG2 Outbound Gateway"
request-channel="IG2RequestChannel"
reply-channel="ResponseChannel"
header-mapper="headerMapper"
url-expression="'http://localhost:9090/balance/account/'+ headers['accountId']"
http-method="GET"
expected-response-type="java.lang.String">
</int-http:outbound-gateway>
如何从 Java 代码向 url-expression 传递参数,我可能在 default-header 中的表达式做错了什么?
这适用于 http:outbound-gateway
中的 url-expression< int:default-header name="accountId" value="1111222233334444"/>
这不..
< int:default-header name="accountId" expression="payload.get('acccountId')"/>
"Error: EL1007E:(pos 0): Property or field 'payload' cannot be found on null"
你不能使用
< int:default-header name="accountId" expression="payload.get('acccountId')"/>
创建消息时;消息(以及有效负载)尚不存在。
您应该可以使用 #args[0]['accountId']
。
没有#root
object评价。请参阅 表达式和 "Global" Headers here。