Example usage for org.apache.wicket Application getSessionStore

List of usage examples for org.apache.wicket Application getSessionStore

Introduction

In this page you can find the example usage for org.apache.wicket Application getSessionStore.

Prototype

public final ISessionStore getSessionStore() 

Source Link

Document

Gets the facade object for working getting/ storing session instances.

Usage

From source file:com.vanillasource.jaywire.wicket.WicketModule.java

License:Open Source License

private void registerInfrastructure(Application application) {
    application.getRequestCycleListeners().add(new AbstractRequestCycleListener() {
        @Override//from  ww  w  . j  a  v  a2 s  . co  m
        public void onBeginRequest(RequestCycle requestCycle) {
            if (requestCycle.getRequest() != null && requestCycle.getRequest() instanceof ServletWebRequest) {
                ServletRequest request = ((ServletWebRequest) requestCycle.getRequest()).getContainerRequest();
                getServletRequestScope().setStorage(request);
                // Force creation of session
                if (request instanceof HttpServletRequest) {
                    application.getSessionStore().getSessionId(requestCycle.getRequest(), true);
                    Session session = application.fetchCreateAndSetSession(requestCycle);
                    if (session == null) {
                        throw new WicketRuntimeException(
                                "Could not create session, which is necessary for JayWire session scope.");
                    }
                    getHttpSessionScope().setStorage(((HttpServletRequest) request).getSession());
                }
            }
        }

        @Override
        public void onEndRequest(RequestCycle requestCycle) {
            getHttpSessionScope().clearStorage();
            getServletRequestScope().clearStorage();
        }
    });
    application.getApplicationListeners().add(new IApplicationListener() {
        @Override
        public void onAfterInitialized(Application application) {
        }

        @Override
        public void onBeforeDestroyed(Application application) {
            try {
                close();
            } catch (Exception e) {
                throw new WicketRuntimeException("Could not close JayWire module", e);
            }
        }
    });
}