Spring Integration ws-outbound-gateway抛出WebServiceTransportException找不到404错误

时间:2018-07-20 18:10:00

标签: spring spring-integration

我们正在使用ws-outbound-gateway通过以下方式调用Web服务。

<ws:outbound-gateway uri="http://localhost:8080/test" message-factory="messageFactory" message-sender="messageSender" ignore-empty-responses="false" requires-reply="true" />

<bean name="messageSender" class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
</bean>

<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="soapVersion">
 <util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_11"/>
 </property>
 </bean>

如果请求xml采用以下方式,则可以很好地工作。

 <?xml version="1.0" encoding="UTF-8"?>
 <m:processRequest xmlns:m="http://ws.test.com">
  <request>
  <dealerId>999852</dealerId>
              .......
              .......
   </request>
 </m:processRequest>

如果我在请求中添加 SOAP-ENV:Envelope xmlns:SOAP-ENV =“ http://schemas.xmlsoap.org/soap/envelope/”和SOAP-ENV:Body xml,它会引发如下错误:

org.springframework.ws.client.WebServiceTransportException:找不到[404]

堆栈跟踪:

org.springframework.ws.client.WebServiceTransportException: Not Found [404]
        at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:590)
        at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:514)
        at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:465)
        at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:420)
        at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:366)
        at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:351)
        at com.railinc.notifserv.services.findusrail.impl.FindUsRailContactServiceImpl.getFindUsRailContacts(FindUsRailContactServiceImpl.java:31)
        at com.railinc.notifserv.services.findusrail.impl.FindUsRailContactServiceImplTest.testGetFindUsRailContacts(FindUsRailContactServiceImplTest.java:9)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

XML错误失败:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<m:processRequest xmlns:m="http://ws.test.com">
    <request>
        <dealerId>999852</dealerId>
          .......
          .......
    </request>
</m:processRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

是否可以使用ws-outbound-gateway将请求xml和soap信封一起发送?

1 个答案:

答案 0 :(得分:0)

对于您提出的问题,我给了您一个答案:https://github.com/spring-projects/spring-integration-samples/issues/231。所以,让我在这里重复一遍!

您的问题是您不必将完全吹散的SOAP信封发送到WS Outbound Gateway。确实,您像最初一样,只需要为SOAP请求的主体发送XML。

如果您确实需要发送整个SOAP信封,则需要考虑使用MimeMessage作为请求有效负载:https://docs.spring.io/spring-integration/docs/5.0.6.RELEASE/reference/html/ws.html#mtom-support