Java Reference
In-Depth Information
Sharing Data Between Handler Invocations
Problem
You want to share data between invocations of your handlers within a chain during processing,
but handler instances cannot rely on thread-local state.
Solution
Obtain the message context from the parameter to your handler, and add data to it. There are
predefined properties you can set and access later, or you can add your own. These properties
are exposed as a map.
The following code illustrates using a custom property and a built-in property with the mes-
sage context to share data between two handlers defined on the same service.
Your test client adds the handler resolver to the service before getting the port:
@Test
public void testMessageContext(){
HelloWSService service = new HelloWSService();
//Set handler resolver into service.
service.setHandlerResolver(new MultipleHandlerResolver());
// Get the Hello stub
Hello hello = service.getHelloWSPort();
//Invoke the business method
String result = hello.sayHello(name);
assertEquals("Hello, " + name + "!", result);
.
}
This is a new handler resolver that defines more than one handler:
public class MultipleHandlerResolver implements HandlerResolver {
private static final Logger LOGGER =
Logger.getLogger(MultipleHandlerResolver.class);
private final List<Handler> chain;
//constructor. we'll set up chain here.
Search WWH ::




Custom Search