【问题标题】:Passing arguments from Java to url-expression in Spring Integration outbound-gateway在 Spring Integration outbound-gateway 中将参数从 Java 传递到 url-expression
【发布时间】:2015-12-19 23:53:04
【问题描述】:

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')"/>

“错误:EL1007E:(pos 0): 在 null 上找不到属性或字段‘payload’”

【问题讨论】:

    标签: spring spring-integration


    【解决方案1】:

    你不能用

    < int:default-header name="accountId" expression="payload.get('acccountId')"/>
    

    创建消息时;消息(因此有效负载)还不存在。

    你应该可以使用#args[0]['accountId']

    没有用于评估的#root 对象。请参阅表达式和“全局”标头 here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多