Soap cxf解组错误:意外元素
我正在尝试使用SOAP服务,使用maven cxf codegen插件生成存根。 除了一个丑陋的服务外,大多数服务都可以。 在这种情况下,当调用时,服务发送正确的响应,但我生成的存根无法将其解组生成异常,如(为了简短起见,我将URL替换为urlx这样的名称): javax.xml.ws.soap.SOAPFaultException:解组错误:意外元素(uri:“url3”,local:“cap”)。预期要素为 实际上,意外字段是具有不同于扩展元素的指定命名空间的扩展的一部分。 以下是名称空间定义:Soap cxf解组错误:意外元素,soap,cxf,unmarshalling,Soap,Cxf,Unmarshalling,我正在尝试使用SOAP服务,使用maven cxf codegen插件生成存根。 除了一个丑陋的服务外,大多数服务都可以。 在这种情况下,当调用时,服务发送正确的响应,但我生成的存根无法将其解组生成异常,如(为了简短起见,我将URL替换为urlx这样的名称): javax.xml.ws.soap.SOAPFaultException:解组错误:意外元素(uri:“url3”,local:“cap”)。预期要素为 实际上,意外字段是具有不同于扩展元素的指定命名空间的扩展的一部分。 以下是名称空间定
<?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">
WSDatiPersonali酒店
扩展的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无法在子名称空间下找到它
有没有关于修复它的想法?最后,我找到了某种方法来禁用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();
JaxWsProxyFactoryBean工厂=新的JaxWsProxyFactoryBean(); setServiceClass(YourServiceClass.class); setAddress(this.constants.SOME_URL); Map properties=factory.getProperties(); 如果(属性==null){ properties=newhashmap(); } properties.put(“soap.no.validate.parts”、“true”); /** *另一个选择是: *put(“设置jaxb验证事件处理程序”,“false”); */ 工厂设置属性(属性); WSDatiPersonaliPortType端口=(WSDatiPersonaliPortType)工厂。创建();
我希望这对其他人有用。最后,我找到了某种方法来禁用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();
JaxWsProxyFactoryBean工厂=新的JaxWsProxyFactoryBean(); setServiceClass(YourServiceClass.class); setAddress(this.constants.SOME_URL); Map properties=factory.getProperties(); 如果(属性==null){ properties=newhashmap(); } properties.put(“soap.no.validate.parts”、“true”); /** *另一个选择是: *put(“设置jaxb验证事件处理程序”,“false”); */ 工厂设置属性(属性); WSDatiPersonaliPortType端口=(WSDatiPersonaliPortType)工厂。创建();
我希望这对其他人有用。你得到元素了吗?例如,使用以下命令:properties.put(“setjaxb验证事件处理程序”,“false”);我只得到了空对象。我放弃了使用JAXB,最终得到了XMLBeans。你得到元素了吗?例如,使用以下命令:properties.put(“setjaxb验证事件处理程序”,“false”);我只得到了空对象,我放弃了使用JAXB,最终得到了XMLBeans。