JAX-WS Handlers - Part 1 of 3
Java API for XML-Based Web Services (JAX-WS) is the next generation Web services programming model and is a Java programming language API for creating Web services. JAX-WS handlers are interceptors that can be plugged into the JAX-WS runtime environment to do additional processing of inbound and outbound messages. They are independent of the application level code and can provide low-level message processing capabilities. The handler framework in the JAX-WS allows applications to address cross-cutting and/or system-level concerns by opening the service and client runtimes for applications to plug in modular components. Reusability of these components across the services portfolio is one benefit that this framework brings to service delivery.
I have divided the entire article into a three part series like any other developer Works article. The first part of series will give a brief introduction on what JAX-WS handlers are and types of handlers. The second will cover how to write handlers and lifecycle. Final part will have some examples on how to add handlers to your client and server implementation using annotations and programmatically.
This is the exact agenda I will cover in this entire series.
* Handler Types
o Protocol handlers
o Logical handlers
* Handler Lifecycle
* Writing Handlers
* Adding @PostConstruct & @PreDestroy to a method
* Handler Execution
* Message Context
* Handler Configuration
o Creating/Setting/Getting Handler Chain
o Creating Custom Handler Resolvers
o Configure Handlers using Metadata
o Configure Handlers programatically
* Add Custom Handler Resolver to the service class
* Downloads and References
JAX-WS provides a flexible plug-in framework for message processing modules, known as handlers, which may be used to extend the capabilities of a JAX-WS runtime system. The following section will provide additional details into the JAX-WS Handler Framework.
The two handler types JAX-WS 2.0 supports include the following:
Protocol handlers are specific to a protocol such as SOAP and operate on message context properties and protocol-specific messages. They can access or change any part of the message, including protocol-specific parts such as the message header. There is only one protocol handler defined in the JAX-WS specification:
These handlers are limited to SOAP-specific configurations and are often referred to as "SOAP handlers". SOAP handlers are generally used to process SOAP-specific information, such as SOAP headers. For example, a SOAP handler can process security headers in a message and pass the request to the endpoint if the message has the required credentials.
Logical handlers can process the message payload and the properties stored in the message context. Logical handlers can communicate without a defined protocol and are commonly used if the processing does not need access to SOAP headers, for validation of the payload, and with Representational State Transfer (REST) style Web services. These handlers cannot change any protocol-specific parts of a message.
In addition, logical handlers can use Java Architecture for XML Binding (JAXB) for processing the payload. If you have the JAXBContext object, it's simple to alter something in a message with a logical handler. You can get the JAXB objects and call Java methods on them rather than dealing with Source objects or SOAPMessage objects using the SOAP with Attachments API for Java (SAAJ) in a SOAP handler..
(Note: A part of the content has been referenced from The Java API for XML-Based Web Services (JAX-WS) 2.0 Specification)
Please write in your comments if you have any suggestions and advice. Thanks.