HTTP标头中缺少Spring WebServiceTemplate SOAPAction

时间:2012-07-24 13:24:29

标签: java spring soap spring-ws

我很难通过Spring-ws WebServiceTemplate调用SOAP 1.2 WebService。正在进行的请求缺少Http Header中的SOAPAction,并且服务器抛出错误“无法处理没有有效操作参数的请求。请提供有效的soap操作。”通过wireshark监控,我能够发现SOAP Action丢失了。我也不支持任何代理。

通过TCP Mon(像SOAP UI这样的工具)运行请求,我确保我尝试发送的SOAP XML是有效的,并且能够得到响应。

这是我的春季配置:

<?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());
            }
        }

3 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,并将其追溯到com.sun.xml.messaging.saaj.soap.MessageImpl实现(http://java.net/jira/browse/SAAJ-37)的1.3.2版本中的错误。  我升级到1.3.19版本,一切都很好。

问题: -

在将请求写入输出流之前,将调用saveChanges()方法。该类的1.3.2版本在其“saveChanges”方法的实现中覆盖了“Content-Type”请求标头。

答案 1 :(得分:0)

我遇到了类似的问题,这是因为package-info.java文件中的XmlSchema注释的命名空间与我试图调用的soap服务不同。这是因为我使用xjc从xsd生成jaxb请求和响应对象,我从wsdl部分缝合在一起加上我以前连接的服务的xsd头,所以这是我的一个纯粹的剪切和粘贴错误但是这里关于命名空间的上一个答案很快就让我误解了我的错误。

答案 2 :(得分:0)

SOAPAction仅在SOAP 1.1中是必需的,请参阅section Content Type

  

SOAP 1.2中已删除SOAP 1.1强制SOAPAction HTTP标头。取而代之的是application / soap + xml媒体类型上的可选动作参数。