【问题标题】:Spring Integration WS Outbound Gateway Error : InputStream does not represent a valid SOAP 1.1 MessageSpring Integration WS Outbound Gateway 错误:InputStream 不代表有效的 SOAP 1.1 消息
【发布时间】:2015-03-01 10:29:18
【问题描述】:

您好,我正在使用 Spring Integration WS Outbound 网关来调用 Soap 服务。这是 WSDL:

<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="CreatePreadvice" targetNamespace="http://www.asda.com/CreatePreadvice/" xmlns:isd="http://www.asda.com/CreatePreadvice/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <wsdl:types>
    <xsd:schema targetNamespace="http://www.asda.com/CreatePreadvice/" xmlns:Q1="http://www.asda.com/PreadviceRequest">
            <xsd:import schemaLocation="Preadvice.xsd" namespace="http://www.asda.com/PreadviceRequest"></xsd:import>
            <xsd:element name="createPreadvice">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="CreatePreadviceRequest" type="Q1:Preadvice"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name="createPreadviceResponse">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="CreatePreadviceResponse" type="isd:Response"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>

      <xsd:complexType name="Response">
        <xsd:sequence>
            <xsd:element name="ResponseCode" type="xsd:string"></xsd:element>
        </xsd:sequence>
      </xsd:complexType>
      <xsd:element name="createPreadviceFault">
        <xsd:complexType>
            <xsd:sequence>

                <xsd:element name="parcelInjectionFault"
                    type="xsd:string">
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name="createPreadviceFault1">
        <xsd:complexType>
            <xsd:sequence>

                <xsd:element name="CreatePreadviceResponse"
                    type="isd:Fault">
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
      </xsd:element>

      <xsd:complexType name="Fault">
        <xsd:sequence>
            <xsd:element name="ResponseCode" type="xsd:string"></xsd:element>
            <xsd:element name="Error" type="isd:Error"></xsd:element>
        </xsd:sequence>
      </xsd:complexType>

      <xsd:complexType name="Error">
        <xsd:sequence>
            <xsd:element name="ErrorCode" type="xsd:string"></xsd:element>
            <xsd:element name="Description" type="xsd:string"></xsd:element>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="createPreadviceRequest">
    <wsdl:part element="isd:createPreadvice" name="parameters"/>
  </wsdl:message>
  <wsdl:message name="createPreadviceResponse">
    <wsdl:part element="isd:createPreadviceResponse" name="parameters"/>
  </wsdl:message>
  <wsdl:message name="createPreadviceFault">
    <wsdl:part name="parameters" element="isd:createPreadviceFault"></wsdl:part>
  </wsdl:message>
  <wsdl:message name="createPreadviceFault1">
    <wsdl:part name="parameters" element="isd:createPreadviceFault1"></wsdl:part>
  </wsdl:message>
  <wsdl:portType name="CreatePreadvice">
    <wsdl:operation name="createPreadvice">
      <wsdl:input message="isd:createPreadviceRequest"/>
      <wsdl:output message="isd:createPreadviceResponse"/>
            <wsdl:fault name="fault" message="isd:createPreadviceFault1"></wsdl:fault>
        </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="CreatePreadviceSOAP" type="isd:CreatePreadvice">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="createPreadvice">
      <soap:operation soapAction="http://www.asda.com/CreatePreadvice/createPreadvice"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="CreatePreadvice">
    <wsdl:port binding="isd:CreatePreadviceSOAP" name="CreatePreadviceSOAP">
      <soap:address location="http://161.163.98.135:60719/"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

这是从 wsdl 类型中获取的 xsd,我用于从 JAXB 创建映射对象

<xsd:schema targetNamespace="http://www.asda.com/CreatePreadvice/"
        xmlns:Q1="http://www.asda.com/PreadviceRequest"
        xmlns:isd="http://www.asda.com/CreatePreadvice/" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:import schemaLocation="Preadvice_new.xsd"
            namespace="http://www.asda.com/PreadviceRequest"></xsd:import>
         <xsd:element name="createPreadvice">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element name="CreatePreadviceRequest" type="Q1:Preadvice" />
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
        <xsd:element name="createPreadviceResponse">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element name="CreatePreadviceResponse" type="isd:Response" />
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>

        <xsd:complexType name="Response">
            <xsd:sequence>
                <xsd:element name="ResponseCode" type="xsd:string"></xsd:element>
            </xsd:sequence>
        </xsd:complexType>
        <xsd:element name="createPreadviceFault">
            <xsd:complexType>
                <xsd:sequence>

                    <xsd:element name="parcelInjectionFault" type="xsd:string">
                    </xsd:element>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
        <xsd:element name="createPreadviceFault1">
            <xsd:complexType>
                <xsd:sequence>

                    <xsd:element name="CreatePreadviceResponse" type="isd:Fault">
                    </xsd:element>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>

        <xsd:complexType name="Fault">
            <xsd:sequence>
                <xsd:element name="ResponseCode" type="xsd:string"></xsd:element>
                <xsd:element name="Error" type="isd:Error"></xsd:element>
            </xsd:sequence>
        </xsd:complexType>

        <xsd:complexType name="Error">
            <xsd:sequence>
                <xsd:element name="ErrorCode" type="xsd:string"></xsd:element>
                <xsd:element name="Description" type="xsd:string"></xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:schema>

这是spring集成配置

<int:chain input-channel="createPreadviceServiceRequestChannel"
        output-channel="createPreadviceServiceReplyChannel">
        <ws:header-enricher>
            <ws:soap-action value="http://www.asda.com/CreatePreadvice/createPreadvice" />
        </ws:header-enricher>
        <ws:outbound-gateway
            uri="${returndropoff.parceldroppost.createpreadvice.stubUrl}"
            marshaller="jaxbsoapunmarshaller" unmarshaller="jaxbsoapunmarshaller" />
    </int:chain>

<bean id="jaxbsoapunmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="classesToBeBound"
            value="com.asda.connect.returnanddropoffs.dto.post.createpreadvice.Preadvice,com.asda.connect.returnanddropoffs.dto.post.createpreadvice.Address,
com.asda.connect.returnanddropoffs.dto.post.createpreadvice.ClientDetails,com.asda.connect.returnanddropoffs.dto.post.createpreadvice.Consignee,
com.asda.connect.returnanddropoffs.dto.post.createpreadvice.Consignment,com.asda.connect.returnanddropoffs.dto.post.createpreadvice.Consignments,com.asda.connect.returnanddropoffs.dto.post.createpreadvice.Consignor,
com.asda.connect.returnanddropoffs.dto.post.createpreadvice.ConsumerDetails,com.asda.connect.returnanddropoffs.dto.post.createpreadvice.Contact,
com.asda.connect.returnanddropoffs.dto.post.createpreadvice.Container,com.asda.connect.returnanddropoffs.dto.post.createpreadvice.Containers,
com.asda.connect.returnanddropoffs.dto.post.createpreadvice.Contents,com.asda.connect.returnanddropoffs.dto.post.createpreadvice.Header,
com.asda.connect.returnanddropoffs.dto.post.createpreadvice.Message,com.asda.connect.returnanddropoffs.dto.post.createpreadvice.ParcelAttributes,
com.asda.connect.returnanddropoffs.dto.post.createpreadvice.Services,com.asda.connect.returnanddropoffs.dto.post.createpreadvice.CreatePreadvice,
com.asda.connect.returnanddropoffs.dto.post.createpreadvice.CreatePreadviceFault,com.asda.connect.returnanddropoffs.dto.post.createpreadvice.CreatePreadviceFault1,
com.asda.connect.returnanddropoffs.dto.post.createpreadvice.CreatePreadviceResponse,com.asda.connect.returnanddropoffs.dto.post.createpreadvice.Error,
com.asda.connect.returnanddropoffs.dto.post.createpreadvice.Fault,com.asda.connect.returnanddropoffs.dto.post.createpreadvice.Response" />
    </bean>

并且 returndropoff.parceldroppost.createpreadvice.stubUrl 是端点 url。任何人都可以帮忙解决问题。为什么我得到 InputStream 并不代表来自 WS 网关的有效 SOAP 1.1 消息异常。

异常堆栈跟踪

Caused by: javax.xml.soap.SOAPException: InputStream does not represent a valid SOAP 1.1 Message
            at com.sun.xml.messaging.saaj.soap.ver1_1.SOAPPart1_1Impl.createEnvelopeFromSource(SOAPPart1_1Impl.java:88)
            at com.sun.xml.messaging.saaj.soap.SOAPPartImpl.getEnvelope(SOAPPartImpl.java:143)
            at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:189)
            ... 279 more

【问题讨论】:

  • 您的returndropoff.parceldroppost.createpreadvice.stubUrl 是否等于来自WSDL 的addresshttp://161.163.98.135:60719/?您是否使用 SOAP-UI 测试过目标服务?看起来您的服务返回无效的Response。请分享更多 StackTrace 以确保问题出在 Response 上。
  • 嗨,Artem...非常感谢您的指针...我检查了来自soap客户端的响应,它返回了soap版本1.2的响应,而SaajSoapMessageFactory默认为1.1。配置相同1.2 现在可以正常工作了。

标签: spring-integration spring-ws


【解决方案1】:

SaajSoapMessageFactory 默认使用 SOAP 1.1。确保服务响应使用适当的版本或 1.2。如果是最后一个,您应该将 SaajSoapMessageFactory bean 注入具有适当属性的 &lt;ws:outbound-gateway&gt;

<bean id="messageFactory" class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory"
          p:payloadCaching="true"
          p:soapVersion="#{T(org.springframework.ws.soap.SoapVersion).SOAP_12}"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多