I doubt what I am about to write is new. In fact, I drudged up bits and pieces all over the internet from searches and kind of combined a few approaches into my own. So if you are reading this and you say to yourself "Hey, I came up with that" then I thank you. But hopefully someone can gain from this anyway.
One of the few things I despise about AJAX is handling session timeouts. Nothing about it is very graceful and my solution doesn't improve on that. However, it is simple and easy. Basically, the problem is that when a web applications session times out we typically want to redirect the user to the login page. I do this in Stripes using an Interceptor but you can think of that as a Filter or what have you. Basically, something on the server side is checking to see if the session has timed out and redirecting the request appropriately. Something kind of like this
if ( user == null && servletPath.startsWith("/admin"))
{
executionContext.getActionBeanContext().getMessages().add( new LocalizableMessage( "/AdminLogin.action.notLoggedIn" ) );
return new ForwardResolution( AdminLoginActionBean.class );
}
if ( user == null && servletPath.startsWith("/advisor"))
{
executionContext.getActionBeanContext().getMessages().add( new LocalizableMessage( "/AdvisorLogin.action.notLoggedIn" ) );
return new ForwardResolution( AdvisorLoginActionBean.class );
}
In order to get AJAX requests to change the browser location you have to rely on JavaScript, sad to say. What I do is I add 'ajax=' as a parameter to all my AJAX requests. In my Interceptor/Filter I look for this parameter. If I find it and the session has timed out, I change the HttpServletResponse.status to 403
if (map.containsKey("ajax"))
{
ajax = true;
if (session.isNew())
{
logger.debug("###########: SESSION IS NEW");
executionContext.getActionBeanContext().getResponse().setStatus(403);
return executionContext.proceed();
}
}
Using Prototype I set an on403 for all my AJAX requests and call a simple function called sessionTimeout() which does this:
window.location = window.location
What that does is refreshes the page so that the first bit of code I showed above takes over and you actually get to the correct login page.
The only problem with this approach is that if you are doing Ajax.Updater you'll get the login page in whatever DIV element you've specified before the page redirects from the sessionTimeout function. Aside from that it works great.
This evening I attended a presentation on Flex 2.0 given by James Ward at the KCJUG. In all honesty, the only reason I went tonight was because I am presenting Stripes in October and I wanted to meet some folks and get an idea of how they do their presentations. However, by the end of the presentation I was very happy I went. And no, it's not just because I won a book in a raffle.
I've been keeping an eye on Flex from a distance. I tinkered with it for an evening right around the time 2.0 was released and all the "it's free" buzz hit. I suppose I was probably more impressed with how James presented flex to a bunch of Java developers more so than Flex itself.
James introduces himself as a Flex Evangelist so I was expecting something very preachy. Something along the lines of "Flex is the next biggest and baddest thing. It wipes the floor with everything else." But it wasn't like that. James ran through a simple example using some pre-made components to show us the simplicity. Well, obviously when everything is already done, it seems pretty simple. But we'll let that slide for now since it actually worked.
What I would have liked to see during the presentation was more detailed integration with the server. Most of what we saw was simple client side demo stuff. He did one example where he grabbed some XML from a JSP. I would have liked to have seem a more detail with some Flash remoting libraries like AMF as well as some of the open source Data Source libraries.
I'm going to read my new book and play around with it. It does interest me and I do think it has merit. But it's too early for me to have a strong opinion of it one way or another. Hey, tinkering is a big step since I've never been a big fan of Flash, right?




