【问题标题】:Spring WebServiceTemplate SOAPAction missing in HTTP HeaderHTTP 标头中缺少 Spring WebServiceTemplate SOAPAction
【发布时间】:2012-07-24 13:24:28
【问题描述】:

我在通过 Spring-ws WebServiceTemplate 调用 SOAP 1.2 WebService 时遇到困难。发出的请求在 Http Header 中缺少 SOAPAction,服务器抛出错误“无法处理没有有效操作参数的请求。请提供有效的肥皂操作。”通过通过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());
            }
        }

【问题讨论】:

  • 您似乎在这里以多种方式设置 SOAP 操作标头 - 使用 actionCallBack,明确使用 new SoapActionCallback..,这两种方法都不起作用吗?
  • 没错。这两种方法都会返回相同的错误。
  • 您需要一个http://networksolutions.com/ReadOrder 正确的标题 - 您使用wireshark 在电线上看到什么标题。只是想确保您没有发送https://ecomapi.networksolutions.com/soapservice.asmx。这是一个简单的工具来捕捉来回发生的事情 - sourceforge.net/projects/nettool
  • 我附上了两个屏幕截图,显示了 HTTP 标头的差异。第一个是我从 TCP Mon !TCPMon Request Header 发送的请求的屏幕截图,第二个是从 java.!Java Request Header 发出的请求,如果您注意到,java 请求的标头中缺少 SOAPAction。
  • 我无法复制您的行为,抱歉。我尝试了您使用的相同 webserviceTemplate API - 使用您提供的显式 SOAPActionCallback 并且它对我来说干净利落,SOAPAction 标头出现在标头中。你能确认一下 Spring-WS 的版本吗?我用的是 2.1.0

标签: java spring soap spring-ws


【解决方案1】:

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

问题:-

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      SOAPAction 仅在 SOAP 1.1 中是强制性的,请参阅 section Content Type

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

      【讨论】:

        猜你喜欢
        • 2013-08-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多