首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >泛化http:outbound-gateway回复通道

泛化http:outbound-gateway回复通道
EN

Stack Overflow用户
提问于 2011-08-20 13:04:39
回答 1查看 3.4K关注 0票数 0

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

我目前可以接收到groovy script (2)的响应,但它似乎不想将结果返回给调用服务的实际方法

任何帮助都将不胜感激。谢谢!

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-08-21 04:25:16

执行以下操作:

网关的每个方法都应该使用一些唯一的'routing‘头值来丰富消息:

代码语言:javascript
复制
<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>

然后将消息直接发送到出站网关:

代码语言:javascript
复制
<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。连接到此通道的是标头值路由器,它基于路由标头的值,将消息发送(路由)到适当的通道:

代码语言:javascript
复制
<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的hacks更简单,我自己也在使用它--事实证明它是有效的;)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7129792

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档