Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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]
like image 481
Dhana Krishnasamy Avatar asked Sep 11 '25 00:09

Dhana Krishnasamy


2 Answers

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.

like image 109
jboot Avatar answered Sep 12 '25 13:09

jboot


The previous suggestion worked for me, just have to find how:

import javax.xml.ws.BindingProvider;
...
MyService myService = new MyServiceSOAP11V10().getMyServiceSOAP11V10SOAP();
BindingProvider bindingProvider = (BindingProvider) myService;
bindingProvider.getRequestContext().put("set-jaxb-validation-event-handler", "false");
like image 35
Cristiano Borges Cardoso Avatar answered Sep 12 '25 14:09

Cristiano Borges Cardoso