tags:

views:

25

answers:

0

Hi all,

I followed the following method of saving an SessionStore object to the ServletContext using a listener. Something like the following:

public class SessionStoreListener implements ServletContextListener {

private static final String SESSION_STORE = "sessionStore";

public void contextInitialized(ServletContextEvent event) {
    SessionStore sessionStoreObject = new SessionStore();
    event.getServletContext().setAttribute(SESSION_STORE, sessionStoreObject);
}

public void contextDestroyed(ServletContextEvent event) {
    try {
            event.getServletContext().removeAttribute(SESSION_STORE);
    }
}

}

All works well as long as I stay in a valve like for example:

public class LoginValidationValveImpl extends AbstractValve implements
    org.apache.jetspeed.pipeline.valve.LoginValidationValve {

...

public void invoke(final RequestContext request, final ValveContext context) throws PipelineException {

...

                //Session store procedures

                //Get the session store
                SessionStore sessionStore = (SessionStore)((((RequestContext) request).getRequest().getSession().getServletContext()))
                    .getAttribute("sessionStore");

                //Create a new SessionStoreEntry and set its values
                SessionStoreEntry sessionStoreEntry = new SessionStoreEntry();
                sessionStoreEntry.setSessionId(request.getRequest().getSession().getId());
                sessionStoreEntry.setUserId(userName);
                sessionStoreEntry.setIpAddress(request.getRequest().getRemoteAddr());
                sessionStoreEntry.setLogonTime(String.valueOf(System.currentTimeMillis()));

                //Add the SessionStoreEntry to the sessionStore
                sessionStore.addSessionToSessionStore(sessionStoreEntry);

                ((((RequestContext) request).getRequest().getSession().getServletContext()))
                .setAttribute("sessionStore", sessionStore);

...

}

but when I try to do:

FacesContext.getCurrentInstance()
        .getExternalContext().getApplicationMap().get("sessionStore");

within a portlet I get a null and when inspecting the applicationMap its empty. Any ideas on why the current FacesContext does not include the variables set in the ServletContext? Is there a better way of doing this?