Quantcast

Servlet Session Handling

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Servlet Session Handling

raja
hi all,
Is there any way to get/set session attribute(Session Handling) in camel Servlet?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Servlet Session Handling

Claus Ibsen-2
Hi

Yeah you can get that via HttpMessage which is the message
implementation when using camel-servlet.

HttpMessage hm = exchange.getIn(HttpMessage.class);
HttpSession = hm.getRequest().getSession();



On Wed, May 17, 2017 at 11:55 AM, raja <[hidden email]> wrote:
> hi all,
> Is there any way to get/set session attribute(Session Handling) in camel
> Servlet?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Servlet-Session-Handling-tp5799692.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Servlet Session Handling

raja
This post was updated on .
Thank u bro,
  It works Fine.But in the following case

  <route>
        <from uri="servlet:login?httpMethodRestrict=POST"/>
        <to uri="bean:sessionProcessor"/>       
        <setBody>JDBC_QUERY</setBody>
        <to uri="jdbc:ds"/>
        <to uri="bean:sessionProcessor"/>                       
   </route>

         In the first sessionProcessor I can able to get httpsession but in the second sessionProcessor i can't get httpsession.I think its because of the jdbc component setting the Message Body.  But How can I get/Maintain session in this real life situation.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Servlet Session Handling

raja
In the previous post I told about a Problem getting HttpSession after JDBCComponent.
A little hack solve the Issue but I don't know its right way or not.

The HttpRequest is kept in one of the header named "CamelHttpServletRequest".So after the JDBCComponent I try to get the HttpSession from the Header.

Modified Code:
<route>
        <from uri="servlet:login?httpMethodRestrict=POST"/>
        <to uri="bean:sessionProcessor"/>       
        <setBody>JDBC_QUERY</setBody>
        <to uri="jdbc:ds"/>
        <to uri="bean:sessionProcessor1"/>                       
   </route>

sessionProcessor:
 HttpSession session=exchange.getIn(HttpMessage.class).getRequest().getSession();

sessionProcessor1:
HttpServletRequest req=(HttpServletRequest)exchange.getIn().getHeader("CamelHttpServletRequest");
HttpSession session=req.getSession();
Loading...