【问题标题】:web service integration - how to access request Object in response class?Web 服务集成 - 如何访问响应类中的请求对象?
【发布时间】:2016-09-26 12:15:18
【问题描述】:

我有一个访问网络服务的代码,这反过来又给我一个响应

<int:chain input-channel="balanceChannel" output-channel="processedItems">
		<int-ws:outbound-gateway destination-provider="myDestinationProvider" />
	</int:chain>
<int:service-activator input-channel="processedItems"
		ref="responseHandler" method="handleResponse" output-channel="nativeQlChannel" />

我能够在我的 responseHandler 中获得响应,但我还想要使用通道发送到 Web 服务的请求对象?如何在 responseHandler 中访问相同的请求对象?

【问题讨论】:

    标签: spring-integration spring-web


    【解决方案1】:

    好吧,因为所有 Spring Integration 端点都通过通道相互分离,我们可以将它们视为微服务。这是非常合乎逻辑和自然的,然后下一个端点对前一个端点的输入一无所知。

    无论如何,我们都可以通过消息头达到要求。因此,您将请求有效负载复制到标头并在下游访问它:

    <int:header-enricher> 
        <int:header name="request" expression="payload"/>
    </int:header-enricher> 
    

    您的服务方法 handleResponse 可以接受整个 Message&lt;?&gt; 以访问该标头,或者您可以使用 @Header("request") 注释再添加一个方法参数。

    【讨论】:

    • 感谢@artem-bilan,它解决了我的问题。我可以向有效负载添加更多值,记住它不应该发送到 Web 服务调用吗?有什么方法可以添加一些变量?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-28
    • 2016-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多