本文介绍了cxf解组错误:意外元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to consume a SOAP service , generating stubs with maven cxf-codegen-plugin.Everything is ok with the most of services except an ugly one.In this case, when invoked, the service sends a correct response , but my generated stubs are unable to unmarshall it generating an exception like ( i replaced urls with a name like urlx for shortness) :

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

Actually the unexpected field is part of an extension that has a specified namespace that is different from the extended element.Here the namespaces 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无法在儿子的命名空间下找到它。

As you can see the "cap" field is inside the father and when the son's one is populated in service response, cxf is unable to find it under the son's namespace.

是否有解决问题的想法?

Any idea about fixing it?

推荐答案

最后,我发现了某种禁用肥皂验证的解决方法。
实际上,可以通过许多方式来做到这一点:

Finally i've found some sort of workaround disabling the soap validation.Actually it's possible to do it in many ways :


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

  • using an annotation on the response class like :

 @org.apache.cxf.annotations.EndpointProperty(key = "soap.no.validate.parts", value = "true")


  • 为服务存根设置属性:

  • setting properties for your service stub :

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


  • 我希望这对其他人可能有用

    I hope this could be useful to someone else.

    这篇关于cxf解组错误:意外元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-01 07:48