Change the definition of
public SessionContext() {
super();
//at this point httpSession is null
}
to
public SessionContext(HttpSession httpSession) {
super();
this.httpSession = httpSession;
//check session here
}
Also use constructor injection
Otherwise provide a setter method for httpSession