javaweb-servicesweblogicjax-wsjava-metro-framework

How to enable JAX-WS client side validation in Metro / WebLogic 11g


I want to enable client side validation of my SOAP messages before sending them to the endpoint.

How can I enable it in my client application running in WebLogic 10.3.6 / Metro provider, preferably using the JAX-WS API?

Metro version is JAX-WS RI 2.1.6 in JDK 6.

Here is a sample code of my JAX-WS client:

@WebService
public class Client {

    @WebServiceRef(wsdlLocation = "RemoteService.wsdl")
    private RemoteService_Service service;

    public void call() throws Exception {

        RemoteService port = service.getRemoteServicePort();

        // configures authentication
        auth(port);

        // builds request
        Request request = new Request();
        request.setValue(null); // this field is mandatory in server

        // client must validate and raise an exception
        port.someOperation(request);

    }

    protected void auth(RemoteService port) {
        Map<String, Object> requestContext = ((BindingProvider) port).getRequestContext();
        requestContext.put(BindingProvider.USERNAME_PROPERTY, "changeit");
        requestContext.put(BindingProvider.PASSWORD_PROPERTY, "changeit");
    }
}

Solution

  • Metro documentation Client Side Schema Validation describes how to do it:

    Proxy needs to be created with SchemaValidationFeature to enable client side validation. Both the outgoing SOAP request and incoming SOAP response will be validated.

    Example 4.9. Enabling Proxy with Schema Validation

    import com.sun.xml.ws.developer.SchemaValidationFeature;
    ...
    
    SchemaValidationFeature feature = new SchemaValidationFeature();
    HelloPort port = new HelloService.getHelloPort(feature);
    // All invocations on this port are validated