9 Replies Latest reply on Jun 1, 2010 4:31 AM by Tim Tim

    JBOSS-WS Client not sending COOKIE after 2 calls

    Frédéric Humblet Newbie

      Hi,

      I just tested under JBoss AS 4.0.5 & JBossWS 1.2.1 a session mecanism based on the HTTP Session Cookie (with a code sample from Rama Pulavarthi's blog).

      Here is the Web Service code:

      @WebService
      public class Hello {
       @Resource
       private WebServiceContext wsContext;
       public int getCounter(){
       MessageContext mc = wsContext.getMessageContext();
       HttpSession session = ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession();
       // Get a session property "counter" from context
       if (session == null)
       throw new WebServiceException("No session in WebServiceContext");
       Integer counter = (Integer)session.getAttribute("counter");
       if (counter == null) {
       counter = new Integer(0);
       System.out.println("Starting the Session");
       }
       counter = new Integer(counter.intValue() + 1);
       session.setAttribute("counter", counter);
       return counter;
       }
      }
      


      Here is the Web Service Client code:
      Hello proxy = new HelloService().getHelloPort();
      ((BindingProvider)proxy).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY,true);
      int result = proxy.getCounter();
      System.out.println(result);
      result = proxy.getCounter();
      System.out.println(result);
      result = proxy.getCounter();
      System.out.println(result);
      


      The first 2 calls to proxy.getCounter() method just worked as expected : On the first call, a new session is created by the Web-Service and a SET-COOKIE is sent by the HTTP transport layer to the Client.

      The second call to proxy.getCounter() generates a SOAP message with the COOKIE received after the first call.

      BUT, when a 3rd call is fired, the client do not send anymore the COOKIE and then the server re-creates a new session.

      The problem seems to be at the client level, when the client stops to send the COOKIE value after the second call.

      ** BTW, this code is for testing purpose and i know that the session mecanism in Web Services should ideally be implemented with the WS-Addressing mecanism.

      Thanks in advance for your suggestions.

      Fred.