You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Srinivas.N." <ns...@yahoo.com> on 2007/06/30 04:00:18 UTC

[S2] Session Invalidation through SessionAware interface

I'm using Struts 2 - I have an action class that implements the SessionAware
interface. How do I invalidate the session? I dont see any invalidate()
method there. Is just calling session.clear() enough? Does that just remove
entries from the session map or does it call the invalidate() method on the
HttpSession as well?

Thanks
Srinivas
-- 
View this message in context: http://www.nabble.com/-S2--Session-Invalidation-through-SessionAware-interface-tf4003103.html#a11369750
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: [S2] Session Invalidation through SessionAware interface

Posted by Gabriel Belingueres <be...@gmail.com>.
Changing the SessionAware interface would certainly break backward
compatibility, plus it would affect action testability.

If you don't like the downcast to SessionMap, I would rather consider
creating an additional interface, something like:

public interface SessionMapAware {
  public void setSessionMap(SessionMap map);
}

then you can safely add any methods you like to the SessionMap class.

Gabriel

2007/7/1, Srinivas.N. <ns...@yahoo.com>:
>
> Wouldn't it be cleaner if
>
> (1) the setSession(Map session) signature of SessionAware was changed to
> setSession(SessionMap session) and
> (2) the implementation of the invalidate method on internally took care of
> dealing with already timed out sessions? (if one really wanted to know if
> the session was already invalidated, it can probably return that as a
> boolean)
>
> - Srinivas
>
>
> newton.dave wrote:
> >
> > --- Ray Clough <ra...@allthisisthat.com> wrote:
> >> Then to invalidate the Session, I do this [code]
> >
> > Oh, I had no idea! If you have wiki karma maybe add a
> > FAQ entry, otherwise with your permission I'll do it.
> >
> > d.
> >
> >
> >
> >
> > ____________________________________________________________________________________
> > Moody friends. Drama queens. Your life? Nope! - their life, your story.
> > Play Sims Stories at Yahoo! Games.
> > http://sims.yahoo.com/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/-S2--Session-Invalidation-through-SessionAware-interface-tf4003103.html#a11385428
> 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: [S2] Session Invalidation through SessionAware interface

Posted by "Srinivas.N." <ns...@yahoo.com>.
Wouldn't it be cleaner if 

(1) the setSession(Map session) signature of SessionAware was changed to
setSession(SessionMap session) and 
(2) the implementation of the invalidate method on internally took care of
dealing with already timed out sessions? (if one really wanted to know if
the session was already invalidated, it can probably return that as a
boolean)

- Srinivas


newton.dave wrote:
> 
> --- Ray Clough <ra...@allthisisthat.com> wrote:
>> Then to invalidate the Session, I do this [code]
> 
> Oh, I had no idea! If you have wiki karma maybe add a
> FAQ entry, otherwise with your permission I'll do it.
> 
> d.
> 
> 
> 
>        
> ____________________________________________________________________________________
> Moody friends. Drama queens. Your life? Nope! - their life, your story.
> Play Sims Stories at Yahoo! Games.
> http://sims.yahoo.com/  
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2--Session-Invalidation-through-SessionAware-interface-tf4003103.html#a11385428
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: [S2] Session Invalidation through SessionAware interface

Posted by Dave Newton <ne...@yahoo.com>.
--- Ray Clough <ra...@allthisisthat.com> wrote:
> Then to invalidate the Session, I do this [code]

Oh, I had no idea! If you have wiki karma maybe add a
FAQ entry, otherwise with your permission I'll do it.

d.



       
____________________________________________________________________________________
Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games.
http://sims.yahoo.com/  

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


Re: [S2] Session Invalidation through SessionAware interface

Posted by Ray Clough <ra...@allthisisthat.com>.
I use the "SessionAware" interface to retrieve a Map of the session.  Then to
invalidate the Session, I do this:

		if (session instanceof org.apache.struts2.dispatcher.SessionMap) {
			// it is possible that the session will have timed-out between the
			// point at which it was acquired above and now.  Attempting to
			// invalidate an already invalid session will result in an
			// exception being thrown.
			try {
				((org.apache.struts2.dispatcher.SessionMap)session).invalidate();
			} catch (IllegalStateException ise) {
				String msg = "'LogoutAction.logout()' caught an "
					+ "IllegalStateException, possibly because the session "
					+ "has already been invalidated or timed out.";
				logger.warn(msg,ise);
			}

- Ray Clough



newton.dave wrote:
> 
> --- "Srinivas.N." <ns...@yahoo.com> wrote:
>> How do I invalidate the session?
> 
> You'd probably need to implement ServletRequestAware
> [1] and get the session from the request.
> 
> and get the session from there.
> 
> You could use ServletActionContext [2] but that might
> have a negative impact on testability; I haven't
> really given that any thought. (Has anyone else? Now
> I'm kinda curious.)
> 
> d.
> 
> [1]
> http://struts.apache.org/2.x/struts2-core/apidocs/org/apache/struts2/interceptor/ServletRequestAware.html
> [2]
> http://struts.apache.org/2.x/struts2-core/apidocs/org/apache/struts2/ServletActionContext.html
> 
> 
> 
>  
> ____________________________________________________________________________________
> Now that's room service!  Choose from over 150,000 hotels
> in 45,000 destinations on Yahoo! Travel to find your fit.
> http://farechase.yahoo.com/promo-generic-14795097
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2--Session-Invalidation-through-SessionAware-interface-tf4003103.html#a11383650
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: [S2] Session Invalidation through SessionAware interface

Posted by Dave Newton <ne...@yahoo.com>.
--- "Srinivas.N." <ns...@yahoo.com> wrote:
> How do I invalidate the session?

You'd probably need to implement ServletRequestAware
[1] and get the session from the request.

and get the session from there.

You could use ServletActionContext [2] but that might
have a negative impact on testability; I haven't
really given that any thought. (Has anyone else? Now
I'm kinda curious.)

d.

[1]
http://struts.apache.org/2.x/struts2-core/apidocs/org/apache/struts2/interceptor/ServletRequestAware.html
[2]
http://struts.apache.org/2.x/struts2-core/apidocs/org/apache/struts2/ServletActionContext.html



 
____________________________________________________________________________________
Now that's room service!  Choose from over 150,000 hotels
in 45,000 destinations on Yahoo! Travel to find your fit.
http://farechase.yahoo.com/promo-generic-14795097

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