A Technology Blog About Code Development, Architecture, Operating System, Hardware, Tips and Tutorials for Developers.

Sunday, December 19, 2010

JSESSIONID & APACHE STICKY SESSION

3:45:00 PM Posted by Satish Kumar , , , 1 comment
Recently I and my team implemented the sticky session feature from apache to our application. After that we started getting frequent session time out issue from testing team. After a long analysis we found, the browser is not flushing the JSESSIONID each time the new session get created from the server. So if the cached session is of node 1 and new session is get created from node 2 the user used to get the session time out problem as apache used to redirect the request to node 1, where there is no session available.We found out this after analyzing the request header and server logs.

So we came up with a solution to flush the JSESSIONID each time the user comes to login page. Bellow is the java script code for the same.


<script>
setCookiesecure("JSESSIONID", getCookie("JSESSIONID"), -1, "/", null, true);
</script>


function setCookiesecure (name,value,expires,path,domain,secure) {

document.cookie = name + "=" + value + ((expires) ? "; expires=" + expires : "") + ((path) ? ";path=" +      path : "") + ((domain) ? "; domain=" +domain :"") + ((secure) ? "; secure" : "");
}


function getCookie( name )
{
        var start = document.cookie.indexOf( name + "=" );
        var len = start + name.length + 1;
        if ( ( !start ) && ( name != document.cookie.substring(0, name.length ) ) ) { 
        return null; 
        }

        if ( start == -1 ) return null;

        var end = document.cookie.indexOf( ";", len ); 
        if ( end == -1 ) end = document.cookie.length;
        return unescape( document.cookie.substring( len, end ) );
}



1 comment:

  1. Hi there I am so thrilled I found your web site, I really
    found you by mistake, while I was looking on Yahoo for something else, Nonetheless I
    am here now and would just like to say kudos for a remarkable post and a all
    round thrilling blog (I also love the theme/design), I don’t have
    time to read through it all at the moment but I have saved
    it and also added your RSS feeds, so when I have time I will be
    back to read much more, Please do keep up the superb b.

    Here is my web site :: www.leefmurphy.com

    ReplyDelete