In this tutorial we create a basic JAX-WS web service with a handler chain. SOAP Handlers are similar to Servlet Filters or EJB/CDI Interceptor. They can intercept and alter incomming and outgoing SOAP messages. JAX-WS defines a Handler interface with subinterfaces LogicalHandler and SOAPHandler. The SOAPHandler has access to the full SOAP Message, including the headers. The LogicalHandler only has access to the Payload of the message.
To create a Handler we need to implement the javax.xml.ws.handler.Handler interface or any of its subinterfaces.
SOAPHandler: SOAP handlers can access the entire SOAP message, including the message headers and body.
LogicalHandler: Logical handlers can access the payload of the message only, and cannot change any protocol-specific information (like headers) in a message.
Warning: In order for the handler chain to register for your web service the handlers.xml file needs to be in the same package as your web service on the classpath. This means for every service you need to add a handler chain this file must exist.
To register a SOAP Handler with our Web Service we need to specify a @HandlerChain() annotation in our class. As said before, the handlers.xml file must be in the same package on your classpath as the web service. For our example this means that the file must exist in com.memorynotfound.ws in the resources folder.