带有Springframework的Apache CXF 2.6.3 SOAP WS抛出cvc-elt.1:找不到元素'ns2:blah'的声明

问题描述 投票:0回答:1

我使用Apache CXF 2.6.3和Springframework通过XSD创建了简单的SOAP Web服务。

我正面临着XSD架构验证的问题。我认为这可能是一个XSD问题,我无法确定它。我的眼睛很累,任何帮助都是最受欢迎的。

这是通过SOAP-UI提交的请求。

SOAP请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://schema.promoteproduct.services.mas.cms.ravs.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <sch:promoteProductWebserviceRequest>
     <productName>MyMerc</productName>
     <reqReceivedDate>12/13/2017</reqReceivedDate>
      </sch:promoteProductWebserviceRequest>
   </soapenv:Body>
</soapenv:Envelope>

下面是收到的响应,当schema-validation-enabled设置为false然后设置为true时。

当schema-validation-enabled设置为false时,一切正常。

请注意,响应将出现具有命名空间:

ns2:promoteProductWebserviceResponse

即使响应对象PromoteProductResponse.xsd有自己的命名空间:

"http://schema.promoteproduct.services.mas.cms.ravs.com/"

SOAP响应:(当启用模式验证时为false)

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:promoteProductWebserviceResponse xmlns:ns2="http://schema.promoteproduct.services.mas.cms.ravs.com/">
         <transactionStatus>true</transactionStatus>
         <transactionId>1000</transactionId>
         <messageList>
            <ns2:errorMessage/>
         </messageList>
      </ns2:promoteProductWebserviceResponse>
   </soap:Body>
</soap:Envelope>

SOAP响应:带故障字符串(在启用模式验证时为true)

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>Marshalling Error: cvc-elt.1: Cannot find the declaration of element 'ns2:promoteProductWebserviceResponse'.</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

下面是Spring beans.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:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml" />

    <jaxws:endpoint 
      id="promoteProduct" 
      implementor="com.ravs.cms.mas.services.promoteproduct.PromoteProductWebServiceProvider" 
      address="/PromoteProduct">
        <jaxws:properties>
          <entry key="schema-validation-enabled" value="true" />
        </jaxws:properties>
    </jaxws:endpoint>

</beans>

下面是WSDL: http://localhost:8080/PromoteProduct-WS-0.0.1-SNAPSHOT/PromoteProduct?wsdl

<?xml version="1.0" ?><wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://schema.promoteproduct.services.mas.cms.ravs.com/" xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mas="http://schema.promoteproduct.services.mas.cms.ravs.com/" name="PromoteProductWebService" targetNamespace="http://schema.promoteproduct.services.mas.cms.ravs.com/">
  <wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://schema.promoteproduct.services.mas.cms.ravs.com/" xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mas="http://schema.promoteproduct.services.mas.cms.ravs.com/">

      <xsd:import namespace="http://schema.promoteproduct.services.mas.cms.ravs.com/" schemaLocation="http://localhost:8080/PromoteProduct-WS-0.0.1-SNAPSHOT/PromoteProduct?xsd=xmlSchema/PromoteProductRequest.xsd"></xsd:import>

      <xsd:import namespace="http://schema.promoteproduct.services.mas.cms.ravs.com/" schemaLocation="http://localhost:8080/PromoteProduct-WS-0.0.1-SNAPSHOT/PromoteProduct?xsd=xmlSchema/PromoteProductResponse.xsd"></xsd:import>

      <xsd:import namespace="http://schema.promoteproduct.services.mas.cms.ravs.com/" schemaLocation="http://localhost:8080/PromoteProduct-WS-0.0.1-SNAPSHOT/PromoteProduct?xsd=xmlSchema/PromoteProductWebserviceException.xsd"></xsd:import> 

    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="promoteProductWebserviceReq">
    <wsdl:part element="tns:promoteProductWebserviceRequest" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="promoteProductWebserviceEx">
    <wsdl:part element="tns:promoteProductWebserviceException" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="promoteProductWebserviceRes">
    <wsdl:part element="tns:promoteProductWebserviceResponse" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="PromoteProductWebService">
    <wsdl:operation name="getPromoteProduct">
      <wsdl:input message="tns:promoteProductWebserviceReq">
    </wsdl:input>
      <wsdl:output message="tns:promoteProductWebserviceRes">
    </wsdl:output>
      <wsdl:fault message="tns:promoteProductWebserviceEx" name="promoteProductWebserviceEx">
    </wsdl:fault>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="PromoteProductWebService" type="tns:PromoteProductWebService">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"></soap:binding>
    <wsdl:operation name="getPromoteProduct">
      <soap:operation soapAction="getPromoteProduct" style="document"></soap:operation>
      <wsdl:input>
        <soap:body use="literal"></soap:body>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"></soap:body>
      </wsdl:output>
      <wsdl:fault name="promoteProductWebserviceEx">
        <soap:fault name="promoteProductWebserviceEx" use="literal"></soap:fault>
      </wsdl:fault>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="PromoteProductWebService">
    <wsdl:port binding="tns:PromoteProductWebService" name="PromoteProductWebService">
      <soap:address location="http://localhost:8080/PromoteProduct-WS-0.0.1-SNAPSHOT/PromoteProduct"></soap:address>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

1. PromoteProductRequest.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema 
  targetNamespace="http://schema.promoteproduct.services.mas.cms.ravs.com/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:xmime="http://www.w3.org/2005/05/xmlmime"
  xmlns:mas="http://schema.promoteproduct.services.mas.cms.ravs.com/">  

  <xsd:element name="promoteProductWebserviceRequest" type="mas:promoteProductWebserviceRequest">
  </xsd:element>

  <xsd:complexType name="promoteProductWebserviceRequest">

    <xsd:sequence>

      <xsd:element name="productName"  maxOccurs="1" minOccurs="1">
        <xsd:simpleType>
          <xsd:restriction base="xsd:string">
            <xsd:minLength value="1" />
            <xsd:maxLength value="30" />
          </xsd:restriction>
        </xsd:simpleType>
      </xsd:element>

      <xsd:element name="reqReceivedDate" maxOccurs="1" minOccurs="1">
        <xsd:simpleType>
          <xsd:restriction base="xsd:string">
            <xsd:minLength value="1" />
            <xsd:maxLength value="10" />
          </xsd:restriction>
        </xsd:simpleType>
      </xsd:element>

    </xsd:sequence>

  </xsd:complexType>

</xsd:schema>

2. PromoteProductResponse.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema 
  targetNamespace="http://schema.promoteproduct.services.mas.cms.ravs.com/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:xmime="http://www.w3.org/2005/05/xmlmime"
  xmlns:mas="http://schema.promoteproduct.services.mas.cms.ravs.com/">

    <xsd:include schemaLocation="PromoteProductMessage.xsd"></xsd:include>

  <xsd:element name="promoteProductWebserviceResponse" type="mas:promoteProductWebserviceResponse">
  </xsd:element>

    <xsd:complexType name="promoteProductWebserviceResponse" xmlns:mas="http://schema.promoteproduct.services.mas.cms.ravs.com/">

      <xsd:sequence>        
        <xsd:element name="transactionStatus" type="xsd:boolean" maxOccurs="1" minOccurs="1"></xsd:element>
        <xsd:element name="transactionId" type="xsd:long" maxOccurs="1" minOccurs="1"></xsd:element>
        <xsd:element name="messageList" type="mas:messageList" maxOccurs="1" minOccurs="0"></xsd:element>
      </xsd:sequence>

    </xsd:complexType>

</xsd:schema>

3. PromoteProductMessage.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema 
  elementFormDefault="qualified" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  targetNamespace="http://schema.promoteproduct.services.mas.cms.ravs.com/" 
  xmlns:mas="http://schema.promoteproduct.services.mas.cms.ravs.com/">

     <xsd:complexType name="messageList">
      <xsd:sequence>
        <xsd:element name="errorMessage" type="mas:messageDetail" maxOccurs="unbounded" minOccurs="0"></xsd:element>
      </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="messageDetail">
      <xsd:sequence>
        <xsd:element name="errorCode" type="xsd:string"></xsd:element>
        <xsd:element name="errorMessage" type="xsd:string"></xsd:element>
      </xsd:sequence>
    </xsd:complexType>

</xsd:schema>

4. PromoteProductWebserviceException.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://schema.promoteproduct.services.mas.cms.ravs.com/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xmime="http://www.w3.org/2005/05/xmlmime"
  xmlns:mas="http://schema.promoteproduct.services.mas.cms.ravs.com/">

    <xsd:include schemaLocation="PromoteProductMessage.xsd"></xsd:include>  

    <xsd:element name="promoteProductWebserviceException">
    <xsd:complexType>  
      <xsd:sequence>                  
          <xsd:element minOccurs="0" maxOccurs="1"
            name="errMsgList" type="mas:messageList">
          </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>
spring soap cxf xsd-validation spring-ws
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.