8 Replies Latest reply on Sep 19, 2006 4:59 PM by thomas.diesler

    Reading cookies in a web service

    djhititup

      I am new to JBoss and JBossWS. The problem i am having is I need to pull the cookie information from the HTTPRequest object ( or any other object) from within a web service. How do i do this?

        • 1. Re: Reading cookies in a web service
          perrucci

          On jsr181 ws you can implement javax.xml.rpc.server.ServiceLifecycle and use this code in init(Object object) method:

          context = (ServletEndpointContext) object;
          httpSession = context.getHttpSession();
          httpServletRequest = (HttpServletRequest) context.getMessageContext().getProperty("javax.xml.ws.servlet.request");
          httpServletResponse = (HttpServletResponse) context.getMessageContext().getProperty("javax.xml.ws.servlet.response");

          Paolo

          • 2. Re: Reading cookies in a web service
            djhititup

            Could you not use ( or in anothe way how is this used) when using the @Resource annotation like in the example below:

            import java.rmi.RemoteException;
            import java.util.Map;
            import javax.annotation.Resource;
            import javax.jws.WebMethod;
            import javax.jws.WebService;
            import javax.jws.soap.SOAPBinding;
            import javax.xml.ws.handler.MessageContext;
            import javax.xml.ws.WebServiceContext;

            @WebService(name="TestWebService", targetNamespace="http://www.co mpany.com/department/testwebservice/", serviceName="TestWebService")
            @SOAPBinding(style = SOAPBinding.Style.RPC)
            public class TestWebService {

            @Resource
            WebServiceContext wsContext;


            @WebMethod
            public String hello(String name) throws RemoteException {
            MessageContext context = wsContext.getMessageContext();
            Map requestHeaders = (Map) context.get(MessageContext.HTTP_REQUEST_HEADERS) ;
            return "Hello "+name+"!";
            }
            }

            • 3. Re: Reading cookies in a web service
              cnbs

              JBoss threw an exception when i tried to use this:
              @Resource
              WebServiceContext wsctx;

              Initially Jboss doesn't know anything about this interface, its library jbossws-client.jar is allocated in jboss/client directory.. I copied it in jboss/server/all/lib and it threw a NoClassDefFoundError error in a deplyment time..
              And i think it is not right to use libraries from /client directory, am i wrong?

              • 4. Re: Reading cookies in a web service
                cnbs

                 

                "cnbs" wrote:
                JBoss threw an exception when i tried to use this:
                @Resource
                WebServiceContext wsctx;

                Initially Jboss doesn't know anything about this interface, its library jbossws-client.jar is allocated in jboss/client directory.. I copied it in jboss/server/all/lib and it threw a NoClassDefFoundError error in a deplyment time..
                And i think it is not right to use libraries from /client directory, am i wrong?


                I've made a mistake.
                NoClassDefFoundError was thrown before i placed jbossws-client.jar in the jboss/client directory. After placing it there deployment fails with another exception...

                • 5. Re: Reading cookies in a web service
                  djhititup

                  It deploys with no errors for me. When I call the "hello" web service I get a null exception due to the wsContext being null b/c JBoss (I assume) is not loading this resource into the web service OR I am using it incorrectly.

                  Is there anyone who can shed some light on this?

                  • 6. Re: Reading cookies in a web service
                    thomas.diesler

                    http://jira.jboss.org/jira/browse/JBWS-1022

                    Note, this is resolved in 2.0Beta

                    • 7. Re: Reading cookies in a web service
                      djhititup

                      Thomas,

                      Will this be resolved in any of the next releases of JBossWS? Like version 1.0.3 or 1.0.4? If it helps any I'd like to say this would be awesome for me if it could be fixed by 1.0.4. thanks.

                      • 8. Re: Reading cookies in a web service
                        thomas.diesler

                        WebServiceContext is JAXWS specific, it'll not go in jbossws-1.x