You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by mojoRising <jp...@averoinc.com> on 2008/04/30 17:48:51 UTC

Best way to access Session with regards to cluster

I have read much about how to access the session from actions and
interceptors, but I still have some confusion about the proper way to do
this so that my session values will be available and replicated properly in
a cluster environment. Specifically, if a user is logged in and making
requests, and then the server they are on goes down, I want their next
request to fail-over to the next server and  have the session identically
available to the framework.

I definitely need access to the session in two key places: In my
authentication Interceptor, which checks if the userObject is in the
session, and in my action classes. I understand that I must get access to
the session differently in an interceptor as opposed to an action. 

 I have seen many ways to do it, including the documentation at:
http://struts.apache.org/2.x/docs/how-do-we-get-access-to-the-session.html.

I am most in need of knowing which method is correct, cluster fail-over
proof - for my interceptor and my action. Can anyone clear this up for me?
These are the methods I have seen so far:

1. ActionContext.getContext().getSession();
2. ActionContext.getSession();
3. invocation.getInvocationContext().getSession();

4. ServletActionContext.getRequest().getSession() 
5. ServletActionContext.getSession() 
6. Implement SessionAware, then use the sessionMap
7. Implement ServletRequestAware: the get the request object, then call
request.getSession()
-- 
View this message in context: http://www.nabble.com/Best-way-to-access-Session-with-regards-to-cluster-tp16985836p16985836.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Best way to access Session with regards to cluster

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
My vote goes to option 3.

On Wed, Apr 30, 2008 at 7:24 PM, mojoRising <jp...@averoinc.com> wrote:
>
>  Let me try to narrow the scope a little then: Which of the following is the
>  better way to get the session in an Interceptor:
>
>
>  1. ActionContext.getContext().getSession();
>  2. ActionContext.getSession();
>  3. invocation.getInvocationContext().getSession();
>  4. ServletActionContext.getRequest().getSession()
>  5. ServletActionContext.getSession()
>
>  --
>  View this message in context: http://www.nabble.com/Best-way-to-access-Session-with-regards-to-cluster-tp16985836p16987714.html
>
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
>  ---------------------------------------------------------------------
>
>
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>  For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Best way to access Session with regards to cluster

Posted by mojoRising <jp...@averoinc.com>.
Let me try to narrow the scope a little then: Which of the following is the
better way to get the session in an Interceptor:

1. ActionContext.getContext().getSession(); 
2. ActionContext.getSession(); 
3. invocation.getInvocationContext().getSession(); 
4. ServletActionContext.getRequest().getSession() 
5. ServletActionContext.getSession() 

-- 
View this message in context: http://www.nabble.com/Best-way-to-access-Session-with-regards-to-cluster-tp16985836p16987714.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Best way to access Session with regards to cluster

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
Clustering is the responsibility of the application server. Struts 2
has no role in that. Just follow the general guidelines of clustering
of web applications.

Nils-H

On Wed, Apr 30, 2008 at 6:40 PM, Brad A Cupit <br...@lsu.edu> wrote:
> > but I still have some confusion about the proper way to do
>  > this so that my session values will be available and
>  > replicated properly in a cluster environment.
>
>  The Struts 2 session maps are actually just wrappers around the real
>  underlying session. The methods that return (or set) a
>  HttpServletRequest should provide the actual http session.
>
>  Basically, once you have setup replicated sessions in your app server,
>  Struts 2 should work with it automatically, no matter which method you
>  choose to get the session.
>
>  I believe implementing SessionAware is the recommended approach, as it
>  doesn't tie your actions to the servlet api (making them more portable
>  and easier to test).
>
>  Not sure about getting the session in an interceptor though...
>
>  Brad Cupit
>  Louisiana State University - UIS
>
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>  For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Best way to access Session with regards to cluster

Posted by Brad A Cupit <br...@lsu.edu>.
> The latter assuming you are implementing
> StrutsStatics in the interceptor.
or using Java 5's static imports  :-)

Brad Cupit
Louisiana State University - UIS

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Best way to access Session with regards to cluster

Posted by Randy Burgess <RB...@nuvox.com>.
ActionInvocation.getInvocationContext().getSession() or

final HttpServletRequest request = (HttpServletRequest)
context.get(HTTP_REQUEST);
HttpSession session = request.getSession();

will do it in an interceptor. The latter assuming you are implementing
StrutsStatics in the interceptor.

Regards,
Randy Burgess
Sr. Web Applications Developer
Nuvox Communications



> From: Brad A Cupit <br...@lsu.edu>
> Reply-To: Struts Users Mailing List <us...@struts.apache.org>
> Date: Wed, 30 Apr 2008 11:40:49 -0500
> To: Struts Users Mailing List <us...@struts.apache.org>
> Subject: RE: Best way to access Session with regards to cluster
> 
>> but I still have some confusion about the proper way to do
>> this so that my session values will be available and
>> replicated properly in a cluster environment.
> 
> The Struts 2 session maps are actually just wrappers around the real
> underlying session. The methods that return (or set) a
> HttpServletRequest should provide the actual http session.
> 
> Basically, once you have setup replicated sessions in your app server,
> Struts 2 should work with it automatically, no matter which method you
> choose to get the session.
> 
> I believe implementing SessionAware is the recommended approach, as it
> doesn't tie your actions to the servlet api (making them more portable
> and easier to test).
> 
> Not sure about getting the session in an interceptor though...
> 
> Brad Cupit
> Louisiana State University - UIS
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 



This email and any attachments ("Message") may contain legally privileged and/or confidential information.  If you are not the addressee, or if this Message has been addressed to you in error, you are not authorized to read, copy, or distribute it, and we ask that you please delete it (including all copies) and notify the sender by return email.  Delivery of this Message to any person other than the intended recipient(s) shall not be deemed a waiver of confidentiality and/or a privilege.


This email and any attachments ("Message") may contain legally privileged and/or confidential information.  If you are not the addressee, or if this Message has been addressed to you in error, you are not authorized to read, copy, or distribute it, and we ask that you please delete it (including all copies) and notify the sender by return email.  Delivery of this Message to any person other than the intended recipient(s) shall not be deemed a waiver of confidentiality and/or a privilege.

RE: Best way to access Session with regards to cluster

Posted by Brad A Cupit <br...@lsu.edu>.
> but I still have some confusion about the proper way to do
> this so that my session values will be available and
> replicated properly in a cluster environment.

The Struts 2 session maps are actually just wrappers around the real
underlying session. The methods that return (or set) a
HttpServletRequest should provide the actual http session.

Basically, once you have setup replicated sessions in your app server,
Struts 2 should work with it automatically, no matter which method you
choose to get the session.

I believe implementing SessionAware is the recommended approach, as it
doesn't tie your actions to the servlet api (making them more portable
and easier to test).

Not sure about getting the session in an interceptor though...

Brad Cupit
Louisiana State University - UIS

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org