Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

6. Creating Web Service Applications wit... > Sharing Data Between Handler Invocat...

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 message 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);
.
}

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint