2 Replies Latest reply on May 20, 2009 11:06 AM by Preetam Palwe

    JAX-WS Session management in JBOSS5

    Preetam Palwe Newbie

      Hi all

      With reference to Rama's article http://weblogs.java.net/blog/ramapulavarthi/archive/2006/06/maintaining_ses.html i am trying session management in JBOSS5.

      In my case the session is getting created successfully but for the next subsequent request i am not able to get the session created earlier.
      I tried tracing using ethereal and i have observed that the JSESSIONID gets returned to client in first ws call. but the client is not able to forward the same JSESSIONID in next subsequent call.

      Any idea? Is this a bug in jboss5 ?
      I have attached my sample code below.

      thanks in advance.

      webservice server code

      public class sessiontestservice {

      private WebServiceContext context;

      private HttpSession checkSession() {
      MessageContext mc = context.getMessageContext();
      HttpSession session = ((HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST)).getSession(false);
      if (session == null) {
      throw new WebServiceException("No session in WebServiceContext");
      System.out.println("session exists -- " + session.getId());
      return session;

      private HttpSession createSession() {
      MessageContext mc = context.getMessageContext();
      HttpSession session = ((HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST)).getSession(true);
      System.out.println("session created -- " + session.getId());
      return session;

      * Web service operation
      @WebMethod(operationName = "createTestSession")
      public String createTestSession(@WebParam(name = "deviceId") String deviceId) {
      HttpSession hs = createSession();
      hs.setAttribute("number", deviceId);
      return hs.getId();

      * Web service operation
      @WebMethod(operationName = "accessTestSession")
      public String accessTestSession() {
      return (String) checkSession().getAttribute("number");

      client code

      try { // Call Web Service Operation
      com.test.SessiontestserviceService service = new com.test.SessiontestserviceService();
      com.test.Sessiontestservice port = service.getSessiontestservicePort();
      ((BindingProvider)port).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, new Boolean(true));
      // TODO initialize WS operation arguments here
      java.lang.String deviceId = "12345";
      // TODO process result here
      java.lang.String result = port.createTestSession(deviceId);
      System.out.println("Result = " + result);
      java.lang.String result1 = port.accessTestSession();
      System.out.println("Result = " + result1);
      } catch (Exception ex) {
      // TODO handle custom exceptions here