Hi,
Just as information... I'm not using JAX-WS. I'm using only JAX-RS.
Can anyone help or provide pointers/inputs as to how to maintain session
variables in JAX-RS service implementation class? Please refer to the thread
below for the code snippet.

Thanks.
Mani.


Sergey Beryozkin-2 wrote:
> 
> Hi,
> 
> You should probably add a jettey bean configuration and enable sessions
> there, if you use Jetty
> 
> http://cwiki.apache.org/CXF20DOC/jetty-configuration.html
> 
> see httpj:sessionSupport
> 
> Otherwise I'm not sure what else can be done - you're working directly
> against HttpServletRequest so I'm not sure why
> the session is not mantained against multiple requests...
> Does anyone know, is there anything special that JAX-WS runtime does in
> this regard ?
> 
> thanks, Sergey
>   ----- Original Message ----- 
>   From: [email protected] 
>   To: Sergey Beryozkin 
>   Sent: Wednesday, April 29, 2009 3:08 PM
>   Subject: Re: Re: Getting hold of session in JAXRS service
> 
> 
>   Hi Sergey, 
>   Thanks for your response. 
>   I was able to get HttpServletRequest but the purpose remains unresolved
> because of the following. 
>   (1) When I try to get session from HttpServletRequest, the session id is
> different for every service request from web client. 
>   public void method1 ( Parameter param) 
>   { 
>   System.out.println ("request-->"+request); 
>   System.out.println ("session id-->"+request.getSession().getId()); 
>   request.getSession().setAttribute ("sVar", "SessionVariable"); 
>   } 
> 
>   public void method2 (Parameter param) 
>   { 
>   System.out.println ("request-->"+request); 
>   System.out.println ("session id-->"+request.getSession().getId()); 
>   String svar = (String) request.getSession().getAttribute ("sVar"); 
>   System.out.println ("Session Variable-->"+svar); 
>   } 
>   In the code above, the session id in method1 is printed different for
> different client requests. 
>   (2) The string variable placed in session in method1() is not available
> in method2(). In method2(), the string variable in session is null. 
> 
>   Is there any way to have the session variable retained? 
> 
>   Thanks. 
>   Mani. 
> 
>   On Apr 29, 2009 8:57am, Sergey Beryozkin <[email protected]> wrote: 
>   > 
>   > 
>   > 
>   > 
>   > 
>   > 
>   > 
>   > 
>   > 
>   > 
>   > 
>   > 
>   > 
>   > 
>   > Hi 
>   > 
>   > 
>   >   
>   > 
>   > 
>   > 
>   > 
>   > @Resource   
>   > 
>   >         public void setContext(WebServiceContext context)    
>   > 
>   >             {   
>   > 
>   >                 System.out.println("Setting the context..." + context
> );   
>   > 
>   >                  this.request
> =(HttpServletRequest)context.getMessageContext().get(MessageContext.SERVLET_REQUEST);
>     
>   > 
>   >                  this.wsContext = context;   
>   > 
>   >             }   
>   > 
>   > 
>   >   
>   > 
>   > 
>   > This code seems wrong, as well as 
>   > 
>   > 
>   > 
>   > 
>   >   
>   > 
>   > 
>   > 
>   > 
>   > "contextBean"
> class="org.apache.cxf.jaxws.context.WebServiceContextImpl">   
>   > 
>   >      
>   > 
>   > 
>   >   
>   > 
>   > 
>   > which is a JAXWS context 
>   > 
>   > impl... 
>   > 
>   > 
>   >   
>   > 
>   > 
>   >   
>   > 
>   > 
>   > Just remove it 
>   > 
>   > and things should start working for you, you  might also want to
> change 
>   > 
>   >   
>   > 
>   > 
>   >   
>   > 
>   > 
>   > @Resource   private HttpServletRequest request;   
>   > 
>   > 
>   >   
>   > 
>   > 
>   > to 
>   > 
>   > 
>   > 
>   > 
>   >   
>   > 
>   > 
>   > 
>   > 
>   > @Context   private HttpServletRequest request;   
>   > 
>   > 
>   >   
>   > 
>   > 
>   > though it should not be 
>   > 
>   > needed 
>   > 
>   > 
>   >   
>   > 
>   > 
>   > let me know please if 
>   > 
>   > it works for you 
>   > 
>   > 
>   > Sergey 
>   > 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Re%3A-Re%3A-Getting-hold-of-session-in-JAXRS-service-tp23313710p23317706.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to