Tab based browser – session handling – Part II

In my previous article, I talked about the conceptual implementation of how one can make sure the application will work in tab based browsers. While the thoughtprocess is more at abstract level and is not attached with any real artifacts, I thought of giving it a try to check, how feasible is to implement the solution. After spending couple of hours (mostly in writing testing code), I could come up with a sample which works in any tab based browsers.
Though the example isn’t developed considering all the pitfalls it may face, it will give one a headstart to develop solution on their own. The solution doesn’t use any third party frameworks and purely relies on what is offerred in JEE. (I used Tomcat 6.0, Eclipse 3.7 and Java 1.6)

The sample code consists of following artifacts
An http request intercepting filter – responsible for performing checks like generation of Unique ID, validation (not implemented), creating wrapper request/response objects.

Wrapper HttpRequest / HttpResponse
Making use of standard HttpServletRequestWrapper & HttpServletResponseWrapper to override methods, which are frequently used in session manipulation.

Wrapper HttpSession
Inherited from standard HttpSession interface and mostly performs delegation to underlying “composed HttpSession” object.

Custom Tag
A custom JSP tag to demonstrate how to include the uid in request. I am not using JSP 2.0 tag implementation – I may append the example later to include the same.

Sample JSP / Servlet
index.jsp and IndexPageServlet – purely to demonstrate there is no specific change required in order to use this implementation. One can continue to use the existing JSPs merely by replacing the URLs with custom tags. Example servlet isn’t even aware of proxied request/response.

Configuration files (web.xml, uid-tags.tld)
Couple of configuration files to integrate all the pieces in one unit and make my example work.

Note that the solution still makes use of “HttpSession” to store/retrieve the data but just wraps the data using tokens. To make it fullproof, one need to consider all the tradeoffs of this approach & application requirements and hence one may have to make considerable changes in the sample code. On top of all, the approach presented in this article may not be feasible in terms of Performance/Security or any other NFR, please discuss with experts in your region before implementing the same. I request you to share your experience on same here, this will definately help others.

Click on following image to download the example and related files. (Rename the .zip to .war and drop it in your application server.)

By Carbon Rider

Hi this is Yogesh, welcome to my world. Being passionate about learning new technologies and building frameworks, I end up spending most of my time in front of computer. But over last few months, I realised apart from being good coder and designer (Yes I am) I have something hidden in me. And thats called ART.

Leave a Reply