【问题标题】:Spring Integration call Web serviceSpring集成调用Web服务
【发布时间】:2014-02-20 18:52:10
【问题描述】:

我还是 Spring Integration 的新手,我没有几个问题。

我在 tomcat 服务器中部署了一个带有 WSDL 的服务。

我想将参数从我的 spring 集成流发送到该服务并接收 响应返回以执行流程中的下一步操作。

我应该使用出站 WS 网关来执行此操作,对吗? 以及如何配置xml来做到这一点?

我尝试了温度示例,但仍然不明白。

谢谢。

/////////////////////////////////////// ///////////////

这是我的配置:

     <int:gateway service-interface="com.app.service.IRequester" id="IRequester"
    default-request-channel="requestChannel"  
    default-reply-channel="responseChannel"
    error-channel="errorChannel" >
 </int:gateway>

 <int:service-activator input-channel="requestChannel" id="bu1"
     ref="BU1" method="bu1Method"
     output-channel="buChannel">
</int:service-activator>

 <int:service-activator input-channel="errorChannel" 
      ref="handlerError" method="errorReturnToGateway"
      output-channel="responseChannel" >
  </int:service-activator>

 <int:router id="routingChannel" input-channel="buChannel" ref="RoutingChannel"     method="routingChannel">
     <int:mapping value="firstChannel" channel="channelFirst" />
     <int:mapping value="otherChannel" channel="channelOther" />
 </int:router>

 <int:service-activator id="firstBU" input-channel="channelFirst"
        ref="FirstBU" method="doSomething" output-channel="responseChannel">
 </int:service-activator>
 <int:service-activator id="otherBU" input-channel="channelOther"
        ref="OtherBU" method="doSomething" output-channel="responseChannel">
 </int:service-activator>

我需要更改 firstBU 和 otherBU 激活器的输出通道以调用 Web 服务,该服务将参数发送到该服务(参数类型为 Hashmap)并接收相同类型的响应。

我不知道如何使用 ws:outbound-gateway 调用 web 服务。因为我只知道通过生成客户端 java 类使用 java 方式调用 web 服务,我可能会在方法 doSomething 中调用服务。

就我而言,您认为哪种方式更好? 我仍然想知道如何通过使用 ws:outbound-gateway 来解决这个问题。

谢谢。

【问题讨论】:

    标签: spring spring-integration


    【解决方案1】:

    只要是 SOAP,您就可以处理 XML。并且您的 WSDL 为您提供合同 - 一个 XSD,其中 XML 应该被发送到服务,并将作为响应返回。

    因此,您的任务是配置&lt;int-ws:outbound-gateway&gt; 并将正确的XML 作为消息payload 提供给该组件的request-channel

    关于响应也是如此:您会得到一个 XML 格式为payload

    但是,它适用于 simple WS 出站网关。您可以使用marshaller 对其进行配置并将其发送到request-channel 一些域POJO,而marshaller 负责将该POJO 转换为SOAP 请求的XML 表示。

    请显示您的配置,也许我们可以为您的具体问题提供更多帮助。

    【讨论】:

    • 感谢您的回复。我已经在我的主题帖子中完成了更新配置。
    • 如果您没有足够的时间,您可以继续进行代码生成并使用通用&lt;service-activator&gt;。否则你需要研究一下Contract First是什么以及Spring WS是如何实现的。 Spring Integration WS 模块完全基于 Spring WS 项目。
    • 再次感谢您,代码生成方式运行良好,我也会按照您的建议学习 Spring WS。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    • 1970-01-01
    • 2015-10-21
    • 1970-01-01
    • 2013-06-06
    • 2013-11-28
    • 1970-01-01
    相关资源
    最近更新 更多