SOAP message handlers enable Web Services and clients to perform additional processing on the SOAP message request or response, by intercepting the SOAP message in both the request and response of the Web Service.
JAX-WS supports two types of SOAP message handlers:
SOAP handlers can access the entire SOAP message, including the message headers and body.
Logical handlers can access the payload of the message only, and cannot change any protocol-specific information (like headers) in a message.
SOAPHandlers in the order specified in configuration are executed first and then the LogicalHandlers specified in the order get executed.
Java EE container does not automatically processes the handlers packaged in the application and configures it on the applicable endpoint, you will need to configure using one of the available ways.
Handlers can be configured for:
endpoints configured with @WebService
endpoints configured with @WebServiceProvider
endpoints in the deployment descriptor (webservices.xml)
In bottom up web service development, Handlers can be configured using @HandlerChain annotation on endpoints configured with @WebService or wit.h @WebServiceProvider.
The file attribute is used to specify an external file that contains the configuration of the handler chain.
The external handler chain configuration file contains configuration information for the handler chain such as the list of handlers in the handler chain, the order in which they execute, the initialization parameters, and so on.
It is an error to specify more than one @HandlerChain annotation in a single Java file.
In top down web service development, handler chain configuration can be done through WSDL customizations.
A <handlerChains> element is added to the customization file.
Multiple handler-chain elements may exist within the handler-chains element.
These may optionally use a service name, port name, or protocol pattern in their description to apply some chains to certain ports and protocols only, through the use of <service-name-pattern> element.
We can configuring handlers on a Web Service client in one of the following ways:
Create a handlerchain as list of handlers and call setHandlerChain() with that list on the Binding object.
Programmatically configure the handlers by setting a custom HandlerResolver on the service instance and create proxies from that service.
Specify handlers in handler chain configuration XML file and add @HandlerChain referencing handler configuration file to the Web Service references for clients running in JavaEE Container.
@WebService(name = "Handler", targetNamespace = "http://javajee.com")
Here, the <service-name-pattern> element applies the handlers in the specified in the <handler-chain> element to the service whose name begins with Hello and targetNamespace is http://javajee.com/handlers.