2013-08-01 66 views
6

我想保留原始請求的原始有效載荷,並將它放在xslt-transformer或其他操作中。我失去了它,因爲我使用了一個xslt-transformer,並且我只需要轉換中的一些元素。所以我的方案是:Spring集成 - 如何保留原始有效負載並在以後使用它?

1.inbound-gateway(傳入WS req) - > 2.xslt-transformer(調用外部WS的映射) - > 3.outbound-gateway(調用外部WS) - > 4 .xslt-transformer(創建外部WS響應和原始請求響應)

在第4步,我沒有原始請求,但我需要它,因爲我必須從中提取值到響應。我怎麼能實現它?

感謝, 五

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

回答

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,然後在修改它之前只存儲消息有效載荷。所以,而不是頭header-richher你會打電話

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

謝謝,這就是我需要! – Viktor

相關問題