ws:outbound-gateway为消息添加额外的SOAP信封和标头

时间:2017-08-23 19:58:57

标签: spring spring-integration

我是弹簧集成和弹簧启动的新手。而且,我的用例是在JMS队列中轮询消息,并使用来自JMS队列的消息有效负载XML调用另一个Web服务。 XML有效负载包含SOAP信封,正文和SAML标头。

我可以使用SOAP UI工具使用XML有效负载来访问Web服务。

这是我的spring集成配置文件。

=============================================== =====

<beans:beans xmlns="http://www.springframework.org/schema/integration"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:http="http://www.springframework.org/schema/integration/http"
    xmlns:jms="http://www.springframework.org/schema/integration/jms"
    xmlns:ws="http://www.springframework.org/schema/integration/ws"
    xmlns:stream="http://www.springframework.org/schema/integration/stream"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/integration
            http://www.springframework.org/schema/integration/spring-integration.xsd
            http://www.springframework.org/schema/integration/http 
            http://www.springframework.org/schema/integration/http/spring-integration-http.xsd
            http://www.springframework.org/schema/integration/jms
            http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
            http://www.springframework.org/schema/integration/ws
            http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd
            http://www.springframework.org/schema/integration/stream
            http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd">
    <jms:message-driven-channel-adapter id="jmsIn"
            destination-name="requestQueue"
            channel="jmsInChannel"
            error-channel = "error-Channel" />


<channel id="error-Channel"/>
<stream:stdout-channel-adapter id="error-Channel"/>

<channel id="jmsInChannel">
    <interceptors>
        <wire-tap channel="loggerChannel"/>
    </interceptors>
</channel>

<logging-channel-adapter id="loggerChannel" level="INFO"/>

<beans:bean id="MY.SOAP-MessageSender"
  class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
  <beans:property name="connectionTimeout" value="30000" />
  <beans:property name="readTimeout" value="50000" />
 </beans:bean>
    <chain input-channel="jmsInChannel" output-channel="outChannel">
        <header-enricher>
             <header name="Content-Type" value="text/xml;charset=UTF-8" />
             <header name="SOAPAction" value="soapaction"/>
        </header-enricher>
        <ws:outbound-gateway  message-sender="MY.SOAP-MessageSender" uri="http://localhost:8080/soapws-endpoint"/>
    </chain>

    <!-- The response from the service is logged to the console. -->
    <!-- <stream:stdout-channel-adapter id="outChannel"/> -->
    <channel id="outChannel">
        <interceptors>
            <wire-tap channel="loggerChannel2"/>
        </interceptors>
    </channel>
<logging-channel-adapter id="loggerChannel2" level="INFO"/> 

<beans:bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <!-- brokerURL, You may have different IP or port -->
    <beans:constructor-arg index="0" value="tcp://localhost:61616" />
</beans:bean>

  <!-- Spring JMS Template -->
  <beans:bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate" >

    <beans:property name="connectionFactory" ref="connectionFactory"/>

  </beans:bean>
</beans:beans>

=============================================== ==============

我可以看到Spring正在为现有的XML有效负载(已经有SOAP信封和有效负载)添加额外的SOAP信封和Header。

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/>
<SOAP-ENV:Body><soapenv:Envelope xmlns:head="http://header" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://typ">
   <soapenv:Header>
.
.
. WS security hader
     </soapenv:Header>
</soapenv:Body>
</soapenv:Envelope>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

问题: 如何删除要添加的额外SOAP信封和SOAP标头。我可以使用的配置中是否有任何开箱即用的属性。如果没有,请提供我可以使用的示例代码。 请帮忙......提前致谢。

2 个答案:

答案 0 :(得分:1)

它是如何设计的;您只需要发送内容,网关将添加SOAP信封。它基于Spring Web Services

如果要滚动自己的SOAP处理,请使用简单的http出站网关。

答案 1 :(得分:0)

谢谢加里。我使用了以下配置

<header-enricher input-channel="jmsInChannel"
output-channel="jmsOutChannel">
             <header name="Content-Type" value="text/xml;charset=UTF-8" />
             <header name="SOAPAction" value="soapaction"/>
        </header-enricher>
        <int:channel id="jmsOutChannel" />
<http:outbound-gateway  extract-request-payload="true" id="webservice.outbound.gateway" request-channel="jmsOutChannel" reply-channel="celsiusChannel" url="http://localhost:8080/soa-ws" expected-response-type="java.lang.String" />

取代

<chain input-channel="jmsInChannel" output-channel="celsiusChannel">
        <header-enricher>
             <header name="Content-Type" value="text/xml;charset=UTF-8" />
             <header name="SOAPAction" value="soapaction"/>
        </header-enricher>
        <ws:outbound-gateway  message-sender="MY.SOAP-MessageSender" uri="http://localhost:8080/soa-ws"/>
    </chain>

我认为http:outbound-gateway的属性extract-request-payload =“true”就可以了。现在没有添加额外的SOAP标头和信封。

相关问题