Skip to main content

WS-Reliable Messaging and Session Support (Part3)

Posted by bhaktimehta on June 7, 2007 at 10:23 AM PDT

This is the third part of tri series blogs where in Part 1 we showed
one way
of supporting sessions with

WS Reliable Messaging. Mike showed in his href="">blog 
WS Reliable Messaging and Session Support Part 2

what are the
problems with this approach and we now
conclude with a third part where we have tried to fix some of these
problems .

Sessions are unique
ids used to identify a client. They would help
maintain state for each client.

In this sample you will see how
sessions can be supported with WS Reliable Messaging (WS RM) .

RM  is one of the
enterprise features in Project href="">Tango
which is Sun's href="">Java Web Services

interoperability project with Microsoft's
Windows Communication

The following snippets of code show how the JAX-WS Endpoint
implementation which is RM enabled

supports sessions .

This is the href="">
wsdl which shows RM is enabled in the endpoint by the presence of href="">WS-RM
Policy Assertions.

Here is endpoint implementation class


public class RMDemoImpl {



As shown in part 1 JAX-WS uses annotations defined by Common
Annotations for the Java
Platform (JSR 250),

to inject the Web ServiceContext and declare lifecycle methods. Web
ServiceContext holds the

information pertaining to a request being served. With JAX-WS Web
Service all you need to do is

mark a field or method
with @Resource.  From the WebServiceContext,  href="">MessageContext

to the the current request can be accessed.

  private context;

As mentioned above WebServiceContext exposes  the href="">MessageContext 
for the request being served when this method is called .

The session 
is obtained from the MessageContext using a jax-ws property

  private Hashtable getSession() {
      return (Hashtable)context.getMessageContext()

   } style="font-weight: bold;">

The following getter  method returns the String associated
with each request .
Correspondingly the setter method 
stores the Strings for each session in the
HashTable respectively.

private String getSessionData() {
     Hashtable sess = getSession();
     String ret = (String)sess.get("request_record");
     return ret != null ? ret : "";

  private void setSessionData(String data) {
      Hashtable session = getSession();
      session.put("request_record", data);

These addString method and getResult method are exposed by our RM
endpoint and are same as Part 1 .
The method addString  takes a
as entered by a user and adds it to the Strings stored in the session
data for that session.

The getResult will return all the strings entered by the user during
that session.

 style="font-weight: normal;">  @WebMethod style="font-weight: normal;">  public void addString(String s )--> style="font-weight: normal;">
      setSessionData(getSessionData() + " " + s); style="font-weight: normal;">
style="font-weight: normal;">  } style="font-weight: normal;">
style="font-weight: normal;">  @WebMethod style="font-weight: normal;">  public String getResult() { style="font-weight: normal;">       return getSessionData();  style="font-weight: normal;">
style="font-weight: normal;">  }

Full source code for the href=""> 
is here.


Here the Session is created every time a new CreateSequence request is
received and gets terminated everytime there is a
request. This way the resource management issue as mentioned by Mike is

Client Code

is the source code for the client. The client enters  various
input Strings and finally hits carriage

return to terminate the client application and all the Strings received
so far for that client will be returned by
server. style="font-weight: bold;">

Sample will be bundled in the wsit workspace and this is
the href="">README
to run the samples. style="font-weight: bold;">

style="font-weight: bold;">Additional sources of information


Check this website for latest source code,
samples,documentation style="font-weight: bold;">

Project GlassFish
Open Source App Server

All WSIT technologies can be installed on this FREE app

Netbeans IDE Module:

All WSIT technologies available today can be
configured visuall
using this Netbeans module. style="font-weight: bold;">


Session With JAX-WS
style="font-weight: bold;">