9.2.  Configure SOAP and logical handlers on the client side.

9.2.1.  Use deployment descriptors.

The declarative configuration works for proxy clients only and works in the same way as for the endpoint example. That is, you simply add an annotation to the client-side generated SEI, which enables the handlers for all proxies and dispatch clients that are generated by using any ports on the SEI.

9.2.2.  Use programmatic API.

The programmatic configuration works for all JAX-WS services, generated service interfaces, and the generic service. Handlers are added to the client-side service by using the following method:

Service.setHandlerResolver(HandlerResolver handlerResolver);
						

Example below shows the HelloClientWithHandler class that programmatically adds the HelloMessengerProtocolHandler to the client-side SEI:

import HelloMessenger;
import HelloMessengerService;
import java.util.Collections;
import java.util.List;
import javax.xml.ws.handler.HandlerResolver;
import javax.xml.ws.handler.PortInfo;

public class HelloClientWithHandler {

    public static void main(String... args) throws Exception {
        HelloMessengerService service = new HelloMessengerService();

        service.setHandlerResolver(new HandlerResolver() {
            public List getHandlerChain(PortInfo inf) {
                return Collections.singletonList(new HelloMessengerProtocolHandler());
            }
        });

        HelloMessenger port = service.getHelloMessengerPort();
        String message = port.sayHello("Mikalai");
        System.out.println(message);
    }
}
						

The highlighted code shows the relevant handler configuration code. The application creates a new anonymous inner HandlerResolver that returns a singleton list that contains an instance of the HelloMessengerProtocolHandler.

An advantage of the programmatic approach is that you are not required to change generated code.

Professional hosting         'Oracle Certified Expert Web Services Developer 6' Quiz     Free SCDJWS 5.0 Guide