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

    JBOSS-WS Client not sending COOKIE after 2 calls

    fredash

      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.


        • 1. Re: JBOSS-WS Client not sending COOKIE after 2 calls
          fredash

          Hi,

          I just installed JBoss-ws 2.0 GA and the problem is just the same :
          the client doesn't send the JSESSIONID COOKIE after the second call, so a new HTTP session is created by the server.

          Can someone confirm this problem please ?
          Thanks,

          Fred.

          • 2. Re: JBOSS-WS Client not sending COOKIE after 2 calls
            thomas.diesler

            I'll look into it

            • 3. Re: JBOSS-WS Client not sending COOKIE after 2 calls
              thomas.diesler
              • 4. Re: JBOSS-WS Client not sending COOKIE after 2 calls
                thomas.diesler

                You can use this preinstalled AS5.0 tag

                svn co https://svn.jboss.org/repos/jbossas/tags/JBoss_5_0_0_Beta2_JBossWS_2_0_0_GA

                The AS5.0 trunk recently changed its deployer architecture. It can only be used with jbossws/trunk not jbossws-2.0.0.GA

                • 5. Re: JBOSS-WS Client not sending COOKIE after 2 calls
                  fredash

                  Thank you for your support.

                  I am developping on Mac OS X 10.4.10 with Jboss AS 4.0.5, the AS 5.0 installer is not yet available for my platform.

                  How can i install that new version on Mac OS X ?

                  • 6. Re: JBOSS-WS Client not sending COOKIE after 2 calls
                    lowecg2004

                    Hello,

                    I'm using 2.0.0 web services in a similar way to the author but I'm getting some slightly different problems with sessions.

                    I call a web service method that creates a HttpSession and saves some state to that session using httpSession.setAttribute("userId", userId). At the client, I get JSESSIONID back from a HTTP cookie which I pass on to a subsequent call to a servlet that is part of the same JEE context. In the servlet I verify that httpSession.getId() matches the session ID created in the web service, however a call to httpSession.getAttribute("userId") is null.

                    Could this be part of the same problem? The web service is declared under Seam 2.0.0b1, so is it possible that this could also be part of the problem?

                    To try and see if I could work around the issue, I thought I would experiment and create a jsession in a separate servlet call and then make the web service call participate in the existing session (rather than rely on the web service creating the session). Now I cannot even get a cookie (or any other HTTP header value for that matter) to pass to the server.

                    After reading the following:

                    https://jax-ws.dev.java.net/guide/HTTP_compression.html

                    I thought that this code would work:

                    final DevelopmentService_Service service = new DevelopmentService_Service();
                    final DevelopmentService proxy = service.getDevelopmentServicePort();
                    ((BindingProvider)proxy).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
                    
                    final HttpCookie jSessionId = getJSessionId();
                     ((BindingProvider)proxy).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS,
                     Collections.singletonMap("Cookie",Collections.singletonList(jSessionId.toString())));


                    But no joy. Incidentally, the HTTP compression example given at the URL above doesn't work either.

                    Should I be able to pass HTTP parameters from the client to the server in this way?

                    Cheers,

                    Chris.

                    Clients were generated using wsconsume
                    JBossWS 2.0.0.GA
                    JBossAS 4.2.0.GA
                    JBoss Seam 2.0.0.b1
                    Java 1.6.0_02 client and server

                    • 7. Re: JBOSS-WS Client not sending COOKIE after 2 calls
                      lowecg2004

                      Hello All,

                      I really could use some help on this, I've exausted all my avenues of investigation and have become stuck. As I understand it, getting the client to pass on a JSESSIONID cookie to the server is the only way I can use the JBossWS clients with a Seam web service. I also believe it could offer a work around to the author's issue too.

                      Kind Regards,

                      Chris.

                      • 8. Re: JBOSS-WS Client not sending COOKIE after 2 calls
                        richard_opalka

                        The issue was fixed and fix will be available in next release of JBossWS

                        • 9. Re: JBOSS-WS Client not sending COOKIE after 2 calls
                          thoism

                          There is a workaround. Use the AXIS2 JAX-WS libraries.

                           

                          I did not check which of the jars are the ones that make the difference but I just added the AXIS2 libraries in the class path of my client and the session works fine.

                           

                          If I have time I will investigate further which jar(r) are responsible for making it work and I will post it here.

                           

                          I also tested the client with Glassfish 2.0/3.0 and it works fine without the AXIS2 JAX-WS libraries.

                           

                          Note that our JBoss version is 4.2.3