0

给定一个网关来处理对 ws 的服务调用。我的目标是提供http:outbound-gateway's reply-channel使用header-enricher,因为我将添加多种方法gateway,我只想使用 1http:outbound-gateway

我目前可以收到对 groovy 脚本 (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>
4

1 回答 1

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 出站网关向远程服务器发送请求,然后将响应转发到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 的 hack 更简单,我自己使用它 - 证明有效;)

于 2011-08-20T20:25:16.127 回答