Reputation: 131
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) :
javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error: unexpected element (uri:"url3", local:"cap"). Expected elements are <{url1}descComune>....<{url1}cap>...
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">
the extended xs is like :
<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>
and the extending one is :
<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>
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?
Upvotes: 3
Views: 11200
Reputation: 25
Below settings allowed to disable unexpected elements error.
// see com.sun.xml.internal.ws.developer.JAXWSProperties
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
Map<String, Object> properties = new HashMap<>();
properties.put("javax.xml.ws.client.connectionTimeout", params.toMillis(params.connectTimeout));
properties.put("javax.xml.ws.client.receiveTimeout", params.toMillis(params.readTimeout));
//Below two properties to disable exceptions related to unexpected elements in the response.
**properties.put("soap.no.validate.parts", "true");
properties.put("set-jaxb-validation-event-handler", "false");**
factory.setProperties(properties);
Upvotes: 0
Reputation: 131
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.
Upvotes: 8