disable soap validation of a soap client using the default jaxws-ri implementation of the jdk 8

4.7k Views Asked by At

My environment is a maven project with spring boot. I am using wsimport to generate JAX-WS Code from a WSDL . i want to disable the soap validation when i receive the soap response. I am using the default implementation of jax-WS of the jdk8. the code looks like this :

// (1) Now build webservice client

MyWS_Service service = new MyWS_Service(null, new QName("http://...", "MyWS"));
MyWS port = service.getMyWSSOAP();

BindingProvider bindingProvider = (BindingProvider) port;

//(2) disable the validation

       bindingProvider.getRequestContext().put("set-jaxb-validation-event-handler", "false");
// set endpoint
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http//...endpointaddress");

//(3) perform request

respObj = port.myRequest(myRequestObj);

i searched in google and i found an option to disable the validation :

(3) bindingProvider.getRequestContext().put("set-jaxb-validation-event-handler", sc.getSocketFactory());

but i seems that this option is not accepted by the default implementation of jax-WS of the jdk8, however it's accepted by apache cxf. So, how can i disactivate the validation in the default implementation of jax-ws of the jdk8? Is there a way to load the the cxf implementation in my project so i use the previous option to disactivate the validation? is there a way to customise the xml validation?

1

There are 1 best solutions below

0
On

I didn't find a solution to disable the jaxb xml validation, but i found a way to integrate apache cxf to my project the solution was simple, i just added this to my project

    <!--apache cxf implementation -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${apache.cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${apache.cxf.version}</version>
    </dependency>

And i force the binding provider to disable the validation

bindingProvider.getRequestContext().put("set-jaxb-validation-event-handler", "false");

in fact the jdk class javax.xml.ws.spi.FactoryFinder#find will searches in the CLASSPATH for the presence of javax.xml.ws.spi.Provider file and falls back to default Sun implementation if not available.

i inspired from this link: force jax-ws apache cxf implementation

So these are all the steps :

  1. generate stub with wsimport

  2. add cxf-rt-frontend-jaxws-*.jar to the classpath (adding the cxf-rt-frontend-jaxws artifact by mvn) to force apache cxf implementation

  3. disable the validation bindingProvider.getRequestContext().put("set-jaxb-validation-event-handler", "false");