Spring Integration - 如何保留原始有效负载并在以后使用它?

时间:2013-08-01 15:24:37

标签: spring-integration

我想保留原始请求的原始有效负载,并且它是在xslt-transformer或其他操作中。我失去了它因为我使用了xslt-transformer而我只需要转换中的一些元素。所以我的方案是:

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

在第4步我没有原始的req,但是我需要它,因为我必须将它的值放到响应中。我怎么能实现它?

谢谢, 诉

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

1 个答案:

答案 0 :(得分:4)

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

所以我会尝试的是:

<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,然后在修改之前只存储消息有效负载。因此,您将调用

而不是标题扩充器
<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"/>