Search code examples
javaweb-servicescxfwsdl2java

How to configure CXF to not worry about unknown elements?


My service is consuming a soap service. The target service could add new fields which shouldnt break our service as long as we receive all the fields we need. I am using CXF to generate java code from WSDL and it breaks whenever it finds a new field. Is it possible to configure CXF to ignore new fields?

The error is something like

org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected element (uri:"http://www.a.com/sed/b/products/2014/03/types", local:"BidOnly"). Expected elements are <{http://www.a.com/sed/b/products/2014/03/types}SaleTeam>,
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:905) ~[cxf-rt-databinding-jaxb-3.2.0.jar:3.2.0]
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:711) ~[cxf-rt-databinding-jaxb-3.2.0.jar:3.2.0]
    at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:172) ~[cxf-rt-databinding-jaxb-3.2.0.jar:3.2.0]

Solution

  • I tried to solve the same problem and stumbled upon this question:

    CXF - webservice endpoint has changed, WSDL has not

    Apparently if you set "set-jaxb-validation-event-handler" to "false" it disables this validation for the unmarshaler. So in my code I added this:

    import org.apache.cxf.jaxws.EndpointImpl;
    
    ...
    
    EndpointImpl endpoint = new EndpointImpl(...);
    endpoint.getProperties().put("set-jaxb-validation-event-handler", "false");
    

    I know I'm answering an old question, but perhaps it will be useful to someone.