问题
My application used CXF WSDL2JAVA to generate the Java classes from a client supplied WSDL.
They've now changed their webservice to have 3 additional string fields in the response. It would be a bit of rework for us to regenerate the java classes, but we're getting an exception:
javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error: unexpected element (newElement)
Is there a way to get CXF to ignore the extra elements in the response?
回答1:
If you add an endpoint property of:
"set-jaxb-validation-event-handler" to "false"
then CXF will not add an event handler into the JAXB unmarshaller and the unexpected elements are silently ignored. You'll need to make sure the rest of the message is exactly correct though as you will not get any errors or anything if the message isn't correct. For example, the common thing to happen is someone sends qualified elements when JAXB is expecting unqualified elements. Without setting the handler, all the fields in the object would end up as "null". With the handler, you would get a message like:
unexpected element (uri:"http://my.namespace.com", local:"myField"). Expected elements are <{}myField>
so you can see that the namespace qualification is the reason.
来源:https://stackoverflow.com/questions/17798196/cxf-webservice-endpoint-has-changed-wsdl-has-not