|
|
||
Bhakti Mehta's BlogWS-Reliable Messaging and Session Support (Part3)Posted by bhaktimehta on June 07, 2007 at 10:23 AM | Comments (1)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 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) . WS RM is one of the enterprise features in Project Tango which is Sun's Java Web Services interoperability project with Microsoft's Windows Communication Foundation (WCF). The following snippets of code show how the JAX-WS Endpoint implementation which is RM enabled supports sessions . This is the wsdl which shows RM is enabled in the endpoint by the presence of WS-RM Policy Assertions. Here is endpoint implementation class @WebService(endpointInterface="rmdemo.server.RMDemo") 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 context 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, MessageContext pertaining to the the current request can be accessed. @Resource As mentioned above WebServiceContext exposes the MessageContext for the request being served when this method is called . The session is obtained from the MessageContext using a jax-ws property "com.sun.xml.ws.session" private Hashtable getSession() {
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() {
These addString method and getResult method are exposed by our RM endpoint and are same as Part 1 . The method addString takes a String 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. @WebMethod Full source code for the RMDemoImpl.java is here. Advantages Here the Session is created every time a new CreateSequence request is received and gets terminated everytime there is a TerminateSequence request. This way the resource management issue as mentioned by Mike is addressed. Client Code Here 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 the server. Sample will be bundled in the wsit workspace and this is the README to run the samples. Additional sources of information WSIT website Check this website for latest source code, samples,documentation All WSIT technologies can be installed on this FREE app server Netbeans IDE Module: All WSIT technologies available today can be configured visuall using this Netbeans module. Maintaining Session With JAX-WS Bookmark blog post: CommentsComments are listed in date ascending order (oldest first) | Post Comment | ||
|
|