在Spring Integration的出站网关中传递多个参数

时间:2015-02-05 12:47:04

标签: spring-integration

我有以下配置:

<int-http:outbound-gateway id="opgateway" request-channel="rallyUpdateRequest"
    url="https://rally1.rallydev.com/slm/webservice/v2.0/defect/9792864541?key={key}"
    http-method="POST" request-factory="rallyHttpRequestFactory"

    expected-response-type="java.lang.String"
    transfer-cookies="true"
    reply-channel="rallyUpdateResponse">
    <int-http:uri-variable
        name="key"
        expression="payload.secondArg" /> 
</int-http:outbound-gateway>

网关界面:

//@interface
public interface RallyUpdater {
    String updateDefect(@Payload String payload, @Header String key);
}

我有主要功能:

public static void main(String... args) throws Exception {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
                "context.xml");
....
        RallyUpdater updater = ctx.getBean("rallyUpdateGateway", RallyUpdater.class);
        String res=updater.updateDefect(defect,key);

        System.out.println("Response  ::::::::::"+res);

这引发了一个错误:

*

Exception in thread "main" java.lang.IllegalArgumentException: Cannot determine header name. Possible reasons: -debug is disabled or header name is not explicitly provided via @Header annotation.
    at org.springframework.util.Assert.notNull(Assert.java:112)
    at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper.determineHeaderName(GatewayMethodInboundMessageMapper.java:229)
    at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper.access$500(GatewayMethodInboundMessageMapper.java:80)
    at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper$DefaultMethodArgsMessageMapper.toMessage(GatewayMethodInboundMessageMapper.java:300)
    at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper$DefaultMethodArgsMessageMapper.toMessage(GatewayMethodInboundMessageMapper.java:262)
    at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper.mapArgumentsToMessage(GatewayMethodInboundMessageMapper.java:163)
    at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper.toMessage(GatewayMethodInboundMessageMapper.java:158)
    at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper.toMessage(GatewayMethodInboundMessageMapper.java:80)
    at org.springframework.integration.support.converter.SimpleMessageConverter.toMessage(SimpleMessageConverter.java:82)
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.doConvert(AbstractMessageSendingTemplate.java:157)
    at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:78)
    at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:70)
    at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:347)
    at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceive(MessagingGatewaySupport.java:324)
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:414)
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:374)
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:365)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy9.updateDefect(Unknown Source)
    at com.aa.qcrallysyncmgmt.base.Main.main(Main.java:49)

* **我需要将有效负载作为发布数据和URL中的密钥传递。

为什么在我们可以提供payload.secondArg时抛出错误? 还有其他任何配置吗?

1 个答案:

答案 0 :(得分:0)

为什么不遵循StackTrace的建议?

updateDefect(@Payload String payload, @Header("key") String key);

从另一方面来看,我不清楚您将如何执行此操作payload.secondArg,因为您的有效负载为String

对我来说配置应该是这样的:

<int-http:uri-variable name="key" expression="headers.key" /> 

否则您也应该显示<gateway>配置。