Question

I'm calling a SOAP web-service from JEE6-client, like:

import javax.xml.ws.Service;
...
Class<T> serviceClass;
...
Service service = Service.create(url, new QName(namespaceURI, serviceName));
T servicePort = (T) service.getPort(serviceClass);

How do I enable schema-validation on the client-side (before sending the SOAP-request to the server)?

Can I do this in java-code, or requires xml-config, etc?

EDIT - I also tried this modification:

boolean inbound = true;
boolean outbound = true;
T servicePort = (T) service.getPort(serviceClass, new SchemaValidationFeature(inbound, outbound));

but doesn't seem to have any effect... error is still thrown on the server-side if a mandatory value is missing.

I would like it to be caught on client-side and never reach the server...

Was it helpful?

Solution

As per documentation to enable schema validation for the client side you need to set jaxws property: schema-validation-enabled to true. Example XML configuration:

<jaxws:client name="{http://apache.org/hello_world_soap_http}SoapPort"
    createdFromAPI="true">
    <jaxws:properties>
        <entry key="schema-validation-enabled" value="true" />
    </jaxws:properties>
</jaxws:client>

Or either java code equivalence:

((BindingProvider)port).getRequestContext().put("schema-validation-enabled", "true");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top