Case Study: Clustering and Externalized Session within a Web Container

My team was recently asked to provide a solution for externalizing session storage in order to support clustering within a web application deployed on JBoss. In order to do this we decided to create a model in which the standard Java session object would be replaced by a custom session object via a RequestWrapper. The type of session object returned would be determined by the session repository configured within the web container. We provided two types of session repositories: 1) An object grid repository that returns a session object that would be stored and persisted within an external database. This type of session object would support clustering and is intended to be used within a production environment 2) An in memory session repository that returns a session object stored within the web container’s memory. This type of session object does not support clustering and would be used for ease of development only.

drawit-diagram-3

In order to use a request wrapper, within the servlet filter, we initialized it and added it to the filter chain like this:

public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
final HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(httpRequest) {
chain.doFilter(wrapper, response);
}



The diagram below shows the flow used by the RequestWrapper to retrieve the custom session object.

drawit-diagram-7

By doing this there were other challenges that presented themselves such as not being able to detect session events such createSession and destroySession through the web container’s servlet filters. Possible solutions to this would be to explicitly create listeners for each CustomSession object and then initialize these listeners for each servlet filter subsequently created. In addition we would may lose valuable session management functionality made available by the web container in terms of the  lifecycle and cleanup (i.e. session timeout, session expiry). In order to compensate we would need to implement this through our own custom design. This model, does however, allow for sessions to be maintained across a cluster.

Doing a lil research…

Since AngularJS has been described as a Superheroic JavaScript MVW Framework, I decided to give it a shot. BTW, MVW stands for “Model View Whatever”. It was termed this way since it is not close to the other MV* labels. It is not a MVC model as controllers exist for each view, so the closest thing has been described as a MVVM – where the $scope object could be considered the ViewModel that is being decorated by a function that we call a Controller. Since calling something MVVM for “Model View View Model” is a bit rediculous they decided to call the model MVW or “Model View Whatever”.

beaker

You can check out some of the apps that I dreamed up below:

Lehra application Beta 0.01

Email your MP Beta 0.01

Angular gives you a lot of flexibility to nicely separate presentation logic from business logic and presentation state. My only complaint thus far is the inability of filters to return objects rather than strings. If anyone has a solution for this I would love to hear it! I had to use a work around of creating more than 1 filter.

Responsive WordPress Websites, yes please!

Yes, I love WordPress because of the wonderful world of themes and plugins that are often developed by independents such as myself. It’s been so refreshing to email individuals responsible for developing a given theme/plugin and having them respond within a day. And the response is totally filter free, like from a real person, 0 red tape! How empowering is that?!

cut-red-tape

Another reason why I’m loving creating responsive sites because of the bright shiny world of responsive media queries. It’s easy to style a website according to the size of the screen used to display it. That’s why all of my sites are good to go on screens of any size. You can take a look at them here.

Drop me a line if you’d like to talk about getting your own custom WordPress site running.