2011-08-20 33 views
0

給定一個處理對ws服務調用的網關。我的目標是使用header-enricher,因爲我會添加多種方法來gateway,我想利用只有1 http:outbound-gateway概括http:出站網關回復通道

我目前可以接收響應提高到Groovy腳本供應http:outbound-gateway's reply-channel(2),但它沒有按似乎不想將結果返回到調用服務的實際方法

任何幫助,將不勝感激。謝謝!

<gateway id="registryService" service-interface="RegistryService"> 
<method name="create" request-channel="create-request-channel" 
     reply-channel="create-reply-channel" /> 
</gateway> 

<chain input-channel="create-request-channel" output-channel="create-request-fulfillment-channel"> 
<transformer> 
    // groovy script that contains the method to be called in the ws (1) 
</transformer> 
<object-to-json-transformer/> 
<header-enricher> 
    <reply-channel overwrite="true" ref="create-reply-fulfillment-channel" /> 
</header-enricher> 
</chain> 

<http:outbound-gateway request-channel="create-request-fulfillment-channel" 
         extract-request-payload="true" 
         expected-response-type="java.lang.String" 
         url="http://localhost:4567" http-method="POST" /> 

<chain input-channel="create-reply-fulfillment-channel" 
     output-channel="create-reply-channel"> 
     <json-to-object-transformer type="JsonRpcResponse"/> 
     <transformer> 
      //groovy script to manipulate response (2) 
     </transformer> 
</chain> 

回答

1

執行以下操作:

網關的每個方法都應該充實消息,一些獨特的「路由」標頭值:

<gateway id="registryService" service-interface="RegistryService"> 
    <method name="create" request-channel="http-request-channel" 
     reply-channel="registryService-create-responseChannel"> 
    <header name="routingHeader" value="registryService-create" /> 
    </method> 
</gateway> 

然後向前伸直髮送消息至出站網關:

<http:outbound-gateway request-channel="http-request-channel" 
         response-channel="http-response-channel" 
         extract-request-payload="true" 
         expected-response-type="java.lang.String" 
         url="http://localhost:4567" http-method="POST" /> 

Http出站網關發送請求到遠程服務器,然後f對http-response-channel的直接回應。此信道被附標頭值路由器,在路由報頭的值的基礎上,發送(路徑)消息發送到適當的信道:

<header-value-router input-channel="http-response-channel" header-name="routingHeader"> 
    <mapping value="registryService-create" channel="registryService-create-responseChannel" /> 
    <mapping value="someOtherService-otherMethod" channel="someOtherService-otherMethod-responseChannel" /> 
</header-value-router> 

當然,你不需要直接發送回網關 - 您可以在這些組件之間添加一些額外的處理,並且您始終可以根據標題值路由消息基礎。

它比groovy的黑客更簡單,我自己使用它 - 證明這是作品;)

相關問題