Unfortunately, here I can't offer as much insight, especially
because I'm still on Tapestry 3.0.3. So, there might be a much cleaner
and/or better way to do this in Tapestry 4.0.
But ...
Tapestry stores everything in the session anyway as property/value
pairs. So you can just whip out your debugger and find the things you need
directly in the session. For example, to get ahold of the Tapestry engine,
this code works.
public static AbstractEngine getEngine() {
HttpSession s = (HttpSession) fCurrentSession.get();
Enumeration en = s.getAttributeNames();
while (en.hasMoreElements()) {
String attrib = (String) en.nextElement();
if (attrib.startsWith("org.apache.tapestry.engine"))
{
AbstractEngine e = (AbstractEngine)
s.getAttribute(attrib);
return e;
}
}
return null;
}
Alternately, you can just override ApplicationServlet and stuff the
data you're going to want into the session yourself, using your own session
key e.g. something like:
protected void doService(HttpServletRequest request,
HttpServletResponse response) throws IOException,
ServletException {
HttpSession s = request.getSession();
// Session ses = HibHelper.getSession();
String ip = null;
synchronized (s) {
ip = request.getRemoteAddr();
...
Clock c = new Clock();
super.doService(request, response);
String temp = "Total Render time = " + c;
Log.debug(temp);
ConnectionDescriptor d = new ConnectionDescriptor();
d.setSourceIp(ip);
d.setShardId(getCurrentShardId());
d.setUserId(getUserId());
s.setAttribute(CONNECTION_DESCRIPTOR, d);
}
}
And then later on you can query the ConnectionDescriptor back out in your
listener with something like:
for (int x = 0; x < snapShot.size(); x++) {
HttpSession s = (HttpSession) snapShot.get(x);
ConnectionDescriptor cd = (ConnectionDescriptor) s
.getAttribute(MyServlet.CONNECTION_DESCRIPTOR);
long idle = (new Date()).getTime() -
s.getLastAccessedTime();
cd.setIdleTime(idle);
rc.add(cd);
}
> -----Original Message-----
> From: Cosmin Bucur [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, November 23, 2005 6:24 AM
> To: Tapestry users
> Subject: Re: How can I do something right before a session is timedout or
> closed ?
>
> After getting some sleep , with my head clear now , I can see that I have
> another question .
>
> It's not as obvious to me how to obtain the tapestry ASO objects in the
> sessionDestroyed() method .
>
> Cosmin
> ----- Original Message -----
> From: "Patrick Casey" <[EMAIL PROTECTED]>
> To: "'Tapestry users'" <[email protected]>
> Sent: Tuesday, November 22, 2005 11:59 PM
> Subject: RE: How can I do something right before a session is timedout or
> closed ?
>
>
> >
> > Step 1: Implement javax.servlet.http.HttpSessionListener in a class.
> >
> > Step 2: Tell your web.xml to use your listener
> >
> > <listener>
> > <listener-class>
> > my.listener
> > </listener-class>
> > </listener>
> >
> > Step 3: in your sessionDestroyed() method of the listener, persist
> > whatever you want to persist.
> >
> >> -----Original Message-----
> >> From: Cosmin Bucur [mailto:[EMAIL PROTECTED]
> >> Sent: Tuesday, November 22, 2005 8:55 PM
> >> To: Tapestry users
> >> Subject: How can I do something right before a session is timedout or
> >> closed ?
> >>
> >> How can I do something right before a session is timedout or closed ?
> >>
> >> I would also like to persist it the session objects to a db , but only
> >> once
> >> before the session is closed .
> >>
> >> Thx
> >> cosmin
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]