Using JAX-WS handlers with HTTP Binding Component
In JAX-WS, there is the concept of handlers
which are really interceptors to inject application logic to alter the protocol or payload messages before and/or after service
invocations. These are application level implementations which can be invoked at strategic places to extend the message processing capabilities.
Check this out for more elaborate overviews of the JAX-WS handlers.
How to enable JAX-WS handlers in OpenESB
In OpenESB, we allow user handler implementations to be plugged into JAX-WS runtime through HTTP BC. Here are a few things worth mentioning:
- Handlers can be implemented in Java SE project(s) or any other standalone environment, i.e. handler implementation(s) can also be compiled outside of the IDE.
- Handler is an user implemented class with the only requirement of implementing the well-defined JAX-WS handler interface (SOAPHandler, LogicalHandler, and the optimized version of the SOAPHandler called MessageHandler)
- Handler implementation and configuration does not affect the application composition, i.e. building a BPEL process which adds a webservice request message
handler to tweak the SOAP headers before invoking a remote service should/would not affect the BPEL logic.
- Handler configuration, i.e. the particular handler class(es) to invoke, will be done on the SOAP binding in CASA editor
How to configure JAX-WS handlers in OpenESB
- As mentioned earlier, handlers can be configured on the SOAP binding in CASA. Since it is a port (endpoint) level configuration, the handler configuration is enabled on the SOAP
endpoint icon (i.e. the "greenish" and the "pupleish" arrows), as shown in the screen shot below:
- Clicking on the "..." button in the endpoint property sheet for "Handlers" will bring up the handler configuration editor:
- Clicking on the "Add" button will bring up a file chooser window. From here, user can browse to a NetBeans Java SE project, or a file directory containing the jar file(s) for
the handler implementation and any dependency libraries, or a single jar file containing all the handler(s) and utility classes. CASA introspects the selected project folder or
the jar file(s) and populates the "Handler Chain" list with all the JAX-WS handlers found. Specifics of the selected handler is displayed in the "Handler Details" section.
- Of course, the handlers can be managed in the configuration editor, which includes adding, removing and ordering handlers. It should be pretty intuitive...
How does the handler work (in OpenESB)
Handlers can be defined to access and/or modify incoming or outgoing SOAP messages. There can be any number of handlers, and/or any combination of the legitimate handler types defined for a SOAP endpoint.
When there are mixed handler types defined for a given endpoint, the execution order will depend on the directionality of the message: all logical handlers will be executed
before the SOAP handlers on outgoing (request and/or response) messages, and SOAP handlers will be executed before logical handlers on incoming (request and response) messages.
When there are multiple handlers defined for the same type/group, the handlers will be executed in the order they are defined in the CASA editor.
Do note that handlers for a giving endpoint will be executed on the request and response processing path. JAX-WS offers message context properties to allow the user
implementation to selectively choose which path the handler should be applied to, if that is desired.
Sometimes, handlers can be as simple as logging/tracking the message payload. Below is your typical "Hello World" kind of sample.
So as promised, we have an example of how to use handlers with OpenESB. Here we have our famous Synchronous sample, and we are going to add a couple of handlers on
the "provider" endpoint to log the SOAP messages.
We have three projects here: the Synchronous sample project which includes the BPEL and the Composite Application projects, and the Java SE project which has the handler implementations.
Not much to be said about the Synchronous sample. The Java SE project has two handlers implemented: a SOAP handler that logs the entire SOAP message, and a logical handler that
logs just the message payload (i.e. the payload in the SOAP body)
All three projects are included here in the Handler_Sample.zip .