Web services Handler Chains tutorial
| Article Index |
|---|
| Web services Handler Chains tutorial |
| Handler chains vs Apache Interceptors |
| All Pages |
Web Services and their clients may need to access the SOAP message for additional processing of the message request or response. You can create SOAP message handlers to enable Web Services and clients to perform this additional processing on the SOAP message. A SOAP message handler provides a mechanism for intercepting the SOAP message in both the request and response of the Web Service.
In order to use Handler chains in your Web service you have to add the @javax.jws.HandlerChain annotation at class level:
Ok, now your Web service will be proxied by one or more Handler defined in the handler-chain.xml configuration file.
In earlier releases of JBoss you had to place this file beneath the META-INF folder of your Web application. When using JBoss 7 just place it in the package folder which is included in the file property (In our example com/sample/ws).
Here is the handler-chain.xml which defines a Logging Handler:
And this is the Handler Class:
The above Handler will just print out all the SOAP incoming messages which are gathered as InputStream and finally converted to String using the ByteArrayOutputStream utility class from Apache Commons IO.
You can use SOAP message Handlers as well to improve the performance of your Web Service. After your Web Service has been deployed, you might discover that many consumers invoke it with the same parameters. You could improve the performance of your Web Service by caching the results of popular invokes of the Web Service (assuming the results are static) and immediately returning these results when appropriate, without ever invoking the back-end components that implement the Web Service. You implement this performance improvement by using handlers to check the request SOAP message to see if it contains the popular parameters.

