cxf Unmarshalling Error:意外元素

时间:2015-07-01 15:01:39

标签: soap cxf unmarshalling

我正在尝试使用SOAP服务,使用maven cxf-codegen-plugin生成存根。 除了丑陋的服务之外,大部分服务都可以。 在这种情况下,当被调用时,服务发送一个正确的响应,但是我生成的存根无法解组它产生一个异常,例如(为了简短,我替换了名为urlx的url):

  

javax.xml.ws.soap.SOAPFaultException:Unmarshalling Error:意外元素(uri:“url3”,local:“cap”)。预期的元素是< {url1} descComune> ....< {url1} cap> ...

实际上,意外字段是扩展的一部分,该扩展具有与扩展元素不同的指定命名空间。 命名空间def:

    <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions ...xmlns:ns1="url1" ... xmlns:ns3="url3" ... targetNamespace="someUrl">
     <wsdl:documentation>WSDatiPersonali</wsdl:documentation>
    <wsdl:types>
        <xs:schema xmlns:ax226="url0" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="url0">

扩展的xs就像:

<xs:schema xmlns:ax225="url1" xmlns:ax227="url0" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="url1">
            <xs:import namespace="url0"/>
            <xs:complexType name="Indirizzo">
                <xs:sequence>
                    <xs:element minOccurs="0" name="cap" nillable="true" type="xs:string"/>

            </xs:sequence>
        </xs:complexType>

,扩展名是:

<xs:schema xmlns:ax224="url3" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="url3">
    <xs:complexType name="Indirizzo">
                <xs:complexContent>
                    <xs:extension base="ns1:Indirizzo">
                        <xs:sequence>
                         ............

                        </xs:sequence>
                    </xs:extension>
                </xs:complexContent>
     </xs:complexType>
</xs:schema>

正如您所看到的,“cap”字段位于父亲内部,当儿子的字段填充在服务响应中时,cxf无法在子命名空间下找到它。

有关修复它的想法吗?

1 个答案:

答案 0 :(得分:2)

最后,我发现了某种解决方法,禁用了soap验证。 实际上,它可以通过多种方式实现:

  • 在响应类上使用注释,如:

     @org.apache.cxf.annotations.EndpointProperty(key = "soap.no.validate.parts", value = "true") 
    
  • 设置服务存根的属性:

     JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
            factory.setServiceClass(YourServiceClass.class);            
            factory.setAddress(this.constants.SOME_URL);
            Map<String, Object> properties = factory.getProperties();
            if(properties==null){
                properties= new HashMap<String, Object>();
            }
    
            properties.put("soap.no.validate.parts", "true");
            /**
            * an other option is : 
            * properties.put("set-jaxb-validation-event-handler", "false");
            */
            factory.setProperties(properties);
            WSDatiPersonaliPortType port = (WSDatiPersonaliPortType) factory.create();
    

我希望这对其他人有用。