Spring Integration - 如何保留原始有效负载并在以后使用它? [英] Spring Integration - how to keep the orginal payload and use it later?

查看:22
本文介绍了Spring Integration - 如何保留原始有效负载并在以后使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保留原始请求的原始负载,并将其放在 xslt-transformer 或其他操作中.我丢失了它,因为我使用了 xslt-transformer,并且我只需要转换中的一些元素.所以我的场景是:

I would like to keep the original payload of the original requests and ise it in a xslt-transformer or in other operation. I lose it because I use an xslt-transformer and I need just some of the elements in the transformation. So my scenario is:

1.inbound-gateway(传入 WS 请求)-> 2.xslt-transformer(调用外部 WS 的映射)-> 3.outbound-gateway(调用外部 WS)-> 4.xslt-transformer(创建来自外部 WS 和原始请求的响应)

1.inbound-gateway (incoming WS req) -> 2.xslt-transformer (mapping for calling an external WS) -> 3.outbound-gateway (calling the external WS) -> 4.xslt-transformer (creating response from the resp. of the external WS and the original req)

在第 4 步,我没有原始请求,但我需要它,因为我必须将其中的值放入响应中.我该如何实施?

At the 4th step I don't have the original req but I'd need it as I have to put values from it to the response. How could I implement it?

谢谢,五、

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration" xmlns:int-ws="http://www.springframework.org/schema/integration/ws" xmlns:int-xml="http://www.springframework.org/schema/integration/xml" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/integration/ws http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd                        http://www.springframework.org/schema/integration/xml http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

<bean id="authenticator" class="uk.co.virginmedia.test.Authenticator"/>
<bean id="webserviceDestinationProvider" class="uk.co.virginmedia.test.WebserviceDestinationProvider"/>
<bean id="resultToDocumentTransformer" class="org.springframework.integration.xml.transformer.ResultToDocumentTransformer"/>

<util:map id="orderNamespaceMap">
    <entry key="res" value="http://schema/ReserveAppointment/2/0" />
</util:map>

<int-ws:inbound-gateway id="ws-gateway-for-rbta" request-channel="incoming-req-channel" reply-channel=""/>

<int:channel id="incoming-req-channel"/>

<int:service-activator id="authentication" input-channel="incoming-req-channel" ref="authenticator" method="authenticate" output-channel="authenticated-channel" />

<int:channel id="authenticated-channel"/>

<int-xml:xpath-router id="servicetype-router" input-channel="authenticated-channel" evaluate-as-string="true">
    <int-xml:xpath-expression expression="//res:ReserveAppointmentRequest/res:serviceType/text()" ns-prefix="res" ns-uri="http://schema/ReserveAppointment/2/0"/>
    <int-xml:mapping value="Broadband" channel="broadband-channel"/>
    <int-xml:mapping value="FTTC+WholesaleLineRental" channel="fttc-wlr-channel"/>
</int-xml:xpath-router>

<int:channel id="broadband-channel"/>

<int-xml:xslt-transformer id="req_for_bt_xslt_transformer" input-channel="broadband-channel" output-channel="domresult_for_bt_channel" xsl-resource="classpath:/xsl/ToBTReq.xsl" result-type="StringResult"/>

<int:channel id="domresult_for_bt_channel"/>

<int:transformer input-channel="domresult_for_bt_channel" output-channel="document_for_bt_channel" expression="payload.toString()"/>

<int:channel id="document_for_bt_channel"/>

<int-ws:outbound-gateway request-channel="document_for_bt_channel" reply-channel="resp_from_bt_channel" destination-provider="webserviceDestinationProvider" id="call_bt-outbound_gateway" />

<int:channel id="resp_from_bt_channel"/>

<int-xml:xslt-transformer id="resp_for_rbta_xslt_transformer" input-channel="resp_from_bt_channel" output-channel="resp_for_rbta_channel" xsl-resource="classpath:/xsl/ToBTReq.xsl" result-type="StringResult"/>

推荐答案

由于您的原始消息只是文本,您可以将其复制到标题字段.只要您在存储和随后检索之间不做任何特殊操作,这应该有效.

Since your original message is just text you could copy it to a header field. This should work as long as you don't do anything special in between when you store and afterwards retrieve it.

所以我会尝试的是:

<int:header-enricher input-channel="authenticated-channel" output-channel="pre-routing-channel">
   <int:header name="original-payload" expression="payload.toString()" />
</int:header-enricher>

<!-- changed input channel of router -->
<int-xml:xpath-router id="servicetype-router" input-channel="pre-routing-channel" evaluate-as-string="true">

如果这对您不起作用(可能是因为您必须在两者之间做一些更特殊的事情或有效负载太大),您仍然可以选择使用 ClaimCheck.这实际上正是您所要求的.为此,您需要一个 MessageStore 然后在修改它之前存储消息有效负载.因此,您将调用

If this is not working for you (maybe because you have to do something more special in between or the payload is too big), you still have the option to use a ClaimCheck. Which is actually exactly what you are asking for. For this you'll need a MessageStore and then just store the message payload before modifying it. So instead of the header-enricher you will call

<int:claim-check-in input-channel="authenticated-channel" output-channel="pre-routing-channel" message-store="payloadstore" />

<!-- MessageStore definition storing payload using in memory map -->
<bean id="simpleMessageStore"
    class="org.springframework.integration.store.SimpleMessageStore"/>

这篇关于Spring Integration - 如何保留原始有效负载并在以后使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆