Java Reference
In-Depth Information
Implementing Server-Side Handler Chains
Problem
You need to specify the handlers you want your service to invoke against incoming and outgo-
ing messages, and you want your chain to be defined externally in a configuration file rather
than have it embedded in the code.
Solution
Write an XML file that defines the chain in accordance with the Java EE rules, and then add
a javax.jws.HandlerChain annotation to your web service to specify the name of the hand-
ler chain file. This file will be an XML file that you put in the WEB-INF/classesdirectory or
elsewhere on the application's classpath.
Let's look at how to do this.
If you are starting from Java, create a WAR project in whatever way you like and add a
web service POJO to it. Then add the @HandlerChain annotation to the class, and use the
file attribute to indicate the name of the XML file that lists your handlers. This is shown in
Example 7-13 .
Example7-13.HandlerService.java
package com.soacookbook;
import javax.jws.HandlerChain;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
/**
* Uses a handler chain on the server.
*/
@WebService
@HandlerChain(file="myHandlers.xml")
public class HandlerWebService {
@WebMethod(operationName = "doWork")
public String doWork(
@WebParam(name = "msg") String msg) {
System.out.println("doing work");
Search WWH ::




Custom Search