-->

春天WebServiceTemplate的SOAPAction缺少HTTP标头(Spring Web

2019-09-20 02:47发布

我有呼吁通过Spring-WS WebServiceTemplate一个SOAP 1.2 WebService的难度。 所取得的请求缺少SOAPAction的HTTP标头中,服务器抛出一个错误“无法处理请求没有有效动作参数,请提供一个有效的SOAP动作。” 我可以通过Wireshark的监控弄清楚SOAP动作失踪。 我也并不落后任何代理。

我已经确定了SOAP XML我想送是通过TCP周一运行的请求(工具,如SOAP UI)有效,并能得到响应。

这里是我的Spring配置:

<?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans  
                        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                        http://www.springframework.org/schema/util
                        http://www.springframework.org/schema/util/spring-util-3.0.xsd">

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

<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
 <constructor-arg ref="messageFactory" />
<property name="defaultUri" value="https://ecomapi.networksolutions.com/soapservice.asmx" />
<property name="messageSender">
    <bean class="org.springframework.ws.transport.http.CommonsHttpMessageSender" />     </property>
</bean>

这是我的Java代码:

            public void simpleSendAndReceive() {
            try{
            StreamSource source = new StreamSource(new StringReader(MESSAGE));
            StreamResult result = new StreamResult(System.out);
            SoapActionCallback actionCallBack = new SoapActionCallback("https://ecomapi.networksolutions.com/soapservice.asmx") {
                public void doWithMessage(WebServiceMessage msg) {
                    SoapMessage smsg = (SoapMessage)msg;
                    smsg.setSoapAction("http://networksolutions.com/ReadOrder");
                }
            };
            webServiceTemplate.sendSourceAndReceiveToResult(
                    "https://ecomapi.networksolutions.com/soapservice.asmx",
                     source,
                     new SoapActionCallback("http://networksolutions.com/ReadOrder"),
     //                      actionCallBack,
                     result);


            System.out.println(source.getInputStream().toString());
            System.out.println(result.getWriter().toString());

            }catch (SoapFaultClientException e) {
                System.out.println(e.getFaultCode());
                System.out.println(e.getFaultStringOrReason());
                System.out.println(e.fillInStackTrace().getLocalizedMessage());
            } catch (WebServiceIOException we) {
                System.out.println(we.getRootCause());
            }
        }

Answer 1:

我面临着同样的问题,我在1.3.2版本中com.sun.xml.messaging.saaj.soap.MessageImpl实施追溯回一个bug( http://java.net/jira/browse/SAAJ- 37 )。 我升级到1.3.19版本和所有被罚款。

问题 : -

写入请求到输出流之前,调用SaveChanges()方法被调用。 1.3.2版本的这个类的被覆盖“的Content-Type”请求头,在它的实施“的SaveChanges”的方法。



Answer 2:

我有一个类似的问题,这是由于的XmlSchema注释在package-info.java文件的命名空间是从我试图打电话给预期的SOAP服务不同。 这使用XJC以从,我已经从WSDL部分缝制在一起的XSD加上从先前的服务,我的接口,所以它是纯剪切和粘贴错误在我的部分XSD头JAXB的请求和响应对象源于我,但在这里说一下命名空间以前的答案是什么赶紧避让我在我的错误。



Answer 3:

SOAPAction的是强制性只有在SOAP 1.1,看到部分内容类型 。

的SOAP 1.1强制性SOAPAction HTTP头已在SOAP 1.2被移除。 在它的位置是在应用/肥皂+ xml的媒体类型的可选动作参数。



文章来源: Spring WebServiceTemplate SOAPAction missing in HTTP Header