Example usage for javax.servlet.http HttpSessionEvent HttpSessionEvent

List of usage examples for javax.servlet.http HttpSessionEvent HttpSessionEvent

Introduction

In this page you can find the example usage for javax.servlet.http HttpSessionEvent HttpSessionEvent.

Prototype

public HttpSessionEvent(HttpSession source) 

Source Link

Document

Construct a session event from the given source.

Usage

From source file:org.terasoluna.gfw.web.logging.HttpSessionEventLoggingListenerTest.java

@Before
public void setup() throws Exception {
    mockHttpSession = new MockHttpSession();
    httpSessionEvent = new HttpSessionEvent(mockHttpSession);
    sessionBindingEvent = new HttpSessionBindingEvent(mockHttpSession, "terasoluna", "AA");

    listener = new HttpSessionEventLoggingListener();

    @SuppressWarnings("unchecked")
    Appender<ILoggingEvent> mockAppender = mock(Appender.class);
    this.mockAppender = mockAppender;
    Logger logger = (Logger) LoggerFactory.getLogger(HttpSessionEventLoggingListener.class);
    logger.addAppender(mockAppender);//from  ww  w. j a v  a 2 s. c  o m

}

From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.AbstractSessionManager.java

public HttpSession newHttpSession(HttpServletRequest request) {
    Session session = newSession(request);
    session.setMaxInactiveInterval(_dftMaxIdleSecs);
    synchronized (__allSessions) {
        synchronized (this) {
            _sessions.put(session.getId(), session);
            __allSessions.add(session.getId(), session);
            if (_sessions.size() > this._maxSessions)
                this._maxSessions = _sessions.size();
        }/*from  w  w  w .jav a  2  s  .co m*/
    }

    HttpSessionEvent event = new HttpSessionEvent(session);

    for (int i = 0; i < _sessionListeners.size(); i++)
        ((HttpSessionListener) _sessionListeners.get(i)).sessionCreated(event);

    if (getCrossContextSessionIDs())
        request.setAttribute(__NEW_SESSION_ID, session.getId());
    return session;
}

From source file:org.apache.catalina.cluster.session.DeltaSession.java

/**
 * Inform the listeners about the new session.
 *
 *//*  w w w .j a  v  a  2  s.  c  o m*/
public void tellNew() {

    // Notify interested session event listeners
    fireSessionEvent(Session.SESSION_CREATED_EVENT, null);

    // Notify interested application event listeners
    Context context = (Context) manager.getContainer();
    Object listeners[] = context.getApplicationLifecycleListeners();
    if (listeners != null) {
        HttpSessionEvent event = new HttpSessionEvent(getSession());
        for (int i = 0; i < listeners.length; i++) {
            if (!(listeners[i] instanceof HttpSessionListener))
                continue;
            HttpSessionListener listener = (HttpSessionListener) listeners[i];
            try {
                fireContainerEvent(context, "beforeSessionCreated", listener);
                listener.sessionCreated(event);
                fireContainerEvent(context, "afterSessionCreated", listener);
            } catch (Throwable t) {
                try {
                    fireContainerEvent(context, "afterSessionCreated", listener);
                } catch (Exception e) {
                    ;
                }
                // FIXME - should we do anything besides log these?
                log.error(sm.getString("standardSession.sessionEvent"), t);
            }
        }
    }

}

From source file:org.apache.catalina.cluster.session.DeltaSession.java

public void expire(boolean notify, boolean notifyCluster) {

    // Mark this session as "being expired" if needed
    if (expiring)
        return;//from www.j  a v  a 2  s .c o m

    String expiredId = getId();

    synchronized (this) {

        if (manager == null)
            return;

        expiring = true;

        // Notify interested application event listeners
        // FIXME - Assumes we call listeners in reverse order
        Context context = (Context) manager.getContainer();
        Object listeners[] = context.getApplicationLifecycleListeners();
        if (notify && (listeners != null)) {
            HttpSessionEvent event = new HttpSessionEvent(getSession());
            for (int i = 0; i < listeners.length; i++) {
                int j = (listeners.length - 1) - i;
                if (!(listeners[j] instanceof HttpSessionListener))
                    continue;
                HttpSessionListener listener = (HttpSessionListener) listeners[j];
                try {
                    fireContainerEvent(context, "beforeSessionDestroyed", listener);
                    listener.sessionDestroyed(event);
                    fireContainerEvent(context, "afterSessionDestroyed", listener);
                } catch (Throwable t) {
                    try {
                        fireContainerEvent(context, "afterSessionDestroyed", listener);
                    } catch (Exception e) {
                        ;
                    }
                    // FIXME - should we do anything besides log these?
                    log.error(sm.getString("standardSession.sessionEvent"), t);
                }
            }
        }
        setValid(false);

        // Remove this session from our manager's active sessions
        if (manager != null)
            manager.remove(this);

        // Unbind any objects associated with this session
        String keys[] = keys();
        for (int i = 0; i < keys.length; i++)
            removeAttribute(keys[i], notify);

        // Notify interested session event listeners
        if (notify) {
            fireSessionEvent(Session.SESSION_DESTROYED_EVENT, null);
        }

        // We have completed expire of this session
        expiring = false;

        if (notifyCluster) {
            log.debug("Notifying cluster of expiration primary=" + isPrimarySession() + " id=" + expiredId);
            ((DeltaManager) manager).sessionExpired(expiredId);
        }

    }

}

From source file:org.hdiv.AbstractHDIVTestCase.java

protected final void setUp() throws Exception {

    String[] files = { "/org/hdiv/config/hdiv-core-applicationContext.xml", "/org/hdiv/config/hdiv-config.xml",
            "/org/hdiv/config/hdiv-validations.xml", "/org/hdiv/config/applicationContext-test.xml",
            "/org/hdiv/config/applicationContext-extra.xml" };

    if (this.applicationContext == null) {
        this.applicationContext = new ClassPathXmlApplicationContext(files);
    }//from  ww  w.j  a  va  2 s.c  o m

    // Servlet API mock
    HttpServletRequest request = (MockHttpServletRequest) this.applicationContext.getBean("mockRequest");
    HttpSession httpSession = request.getSession();
    ServletContext servletContext = httpSession.getServletContext();
    HDIVUtil.setHttpServletRequest(request);

    // Put Spring context on ServletContext
    StaticWebApplicationContext webApplicationContext = new StaticWebApplicationContext();
    webApplicationContext.setServletContext(servletContext);
    webApplicationContext.setParent(this.applicationContext);
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            webApplicationContext);

    // Initialize config
    this.config = (HDIVConfig) this.applicationContext.getBean("config");

    InitListener initListener = new InitListener();
    // Initialize ServletContext
    ServletContextEvent servletContextEvent = new ServletContextEvent(servletContext);
    initListener.contextInitialized(servletContextEvent);
    // Initialize HttpSession
    HttpSessionEvent httpSessionEvent = new HttpSessionEvent(httpSession);
    initListener.sessionCreated(httpSessionEvent);
    // Initialize request
    ServletRequestEvent requestEvent = new ServletRequestEvent(servletContext, request);
    initListener.requestInitialized(requestEvent);

    if (log.isDebugEnabled()) {
        log.debug("Hdiv test context initialized");
    }

    onSetUp();
}

From source file:org.hdiv.hateoas.jackson.AbstractHDIVTestCase.java

protected void setUp() throws Exception {

    String[] files = { "/org/hdiv/config/hdiv-core-applicationContext.xml", "/org/hdiv/config/hdiv-config.xml",
            "/org/hdiv/config/hdiv-validations.xml", "/org/hdiv/config/applicationContext-test.xml",
            "/org/hdiv/config/applicationContext-extra.xml" };

    if (this.applicationContext == null) {
        this.applicationContext = new ClassPathXmlApplicationContext(files);
    }//w  w w. j  a  v  a 2 s.c o m

    // Servlet API mock
    HttpServletRequest request = (MockHttpServletRequest) this.applicationContext.getBean("mockRequest");
    HttpSession httpSession = request.getSession();
    ServletContext servletContext = httpSession.getServletContext();
    HDIVUtil.setHttpServletRequest(request);

    // Put Spring context on ServletContext
    StaticWebApplicationContext webApplicationContext = new StaticWebApplicationContext();
    webApplicationContext.setServletContext(servletContext);
    webApplicationContext.setParent(this.applicationContext);
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            webApplicationContext);

    // Initialize config
    this.config = (HDIVConfig) this.applicationContext.getBean("config");

    InitListener initListener = new InitListener();
    // Initialize ServletContext
    ServletContextEvent servletContextEvent = new ServletContextEvent(servletContext);
    initListener.contextInitialized(servletContextEvent);
    // Initialize HttpSession
    HttpSessionEvent httpSessionEvent = new HttpSessionEvent(httpSession);
    initListener.sessionCreated(httpSessionEvent);
    // Initialize request
    ServletRequestEvent requestEvent = new ServletRequestEvent(servletContext, request);
    initListener.requestInitialized(requestEvent);

    if (log.isDebugEnabled()) {
        log.debug("Hdiv test context initialized");
    }

    onSetUp();
}

From source file:org.ireland.jnetty.server.session.HttpSessionImpl.java

/**
 * ?Session Destroyed//from  w w w  .  j av  a2s .  co  m
 */
private void publishSessionDestroyed() {

    ArrayList<HttpSessionListener> listeners = _manager.getListeners();

    if (listeners != null) {
        HttpSessionEvent event = new HttpSessionEvent(this);

        for (int i = listeners.size() - 1; i >= 0; i--) {
            HttpSessionListener listener;
            listener = (HttpSessionListener) listeners.get(i);

            listener.sessionDestroyed(event);
        }
    }
}

From source file:org.ireland.jnetty.server.session.SessionManager.java

/**
 * ?SessionCreated/*from w  w w .  ja  va 2 s  .  c om*/
 * 
 * @param session
 */
private void handleCreateListeners(HttpSessionImpl session) {
    if (_listeners != null) {
        HttpSessionEvent event = new HttpSessionEvent(session);

        for (int i = 0; i < _listeners.size(); i++) {
            HttpSessionListener listener = _listeners.get(i);

            listener.sessionCreated(event);
        }
    }
}

From source file:org.kchine.r.server.impl.RServantImpl.java

public void startHttpServer(final int port) throws RemoteException {
    if (_virtualizationServer != null) {
        throw new RemoteException("Server Already Running");
    } else if (ServerManager.isPortInUse("127.0.0.1", port)) {
        throw new RemoteException("Port already in use");
    } else {//from   ww w.  j a  v a2 s .c om

        try {
            log.info("!! Request to run virtualization server on port " + port);
            RKit rkit = new RKit() {
                RServices _r = (RServices) UnicastRemoteObject.toStub(RServantImpl.this);
                ReentrantLock _lock = new ExtendedReentrantLock() {
                    public void rawLock() {
                        super.lock();
                    }

                    public void rawUnlock() {
                        super.unlock();
                    }
                };

                public RServices getR() {
                    return _r;
                }

                public ReentrantLock getRLock() {
                    return _lock;
                }
            };

            _virtualizationServer = new Server(port);

            _virtualizationServer.setStopAtShutdown(true);

            Context root = new Context(_virtualizationServer, "/rvirtual",
                    Context.SESSIONS | Context.NO_SECURITY);

            final HttpSessionListener sessionListener = new FreeResourcesListener();
            root.getSessionHandler().setSessionManager(new HashSessionManager() {
                @Override
                protected void addSession(org.mortbay.jetty.servlet.AbstractSessionManager.Session session,
                        boolean arg1) {
                    super.addSession(session, arg1);
                    sessionListener.sessionCreated(new HttpSessionEvent(session.getSession()));
                }

                @Override
                protected void addSession(org.mortbay.jetty.servlet.AbstractSessionManager.Session session) {
                    super.addSession(session);
                }

                @Override
                public void removeSession(HttpSession session, boolean invalidate) {
                    super.removeSession(session, invalidate);
                    sessionListener.sessionDestroyed(new HttpSessionEvent(session));
                }

                @Override
                public void removeSession(org.mortbay.jetty.servlet.AbstractSessionManager.Session session,
                        boolean arg1) {
                    super.removeSession(session, arg1);
                    sessionListener.sessionDestroyed(new HttpSessionEvent(session));
                }

                @Override
                protected void removeSession(String clusterId) {
                    super.removeSession(clusterId);
                }
            });

            root.addServlet(new ServletHolder(new org.kchine.r.server.http.frontend.GraphicsServlet(rkit)),
                    "/graphics/*");
            root.addServlet(new ServletHolder(new org.kchine.r.server.http.frontend.RESTServlet(rkit)),
                    "/rest/*");
            root.addServlet(
                    new ServletHolder(new org.kchine.r.server.http.frontend.CommandServlet(rkit, false)),
                    "/cmd/*");
            root.addServlet(new ServletHolder(new org.kchine.r.server.http.local.LocalHelpServlet(rkit)),
                    "/helpme/*");
            root.addServlet(new ServletHolder(
                    new org.kchine.r.server.http.frontend.WWWDirectoryServlet(new DiretoryProvider() {
                        public String getDirectory() throws Exception {
                            return DirectJNI.getInstance().getRServices().getWorkingDirectory();
                        }
                    }, "/wd")), "/wd/*");
            root.addServlet(new ServletHolder(
                    new org.kchine.r.server.http.frontend.WWWDirectoryServlet(ServerManager.WWW_DIR, "/www")),
                    "/www/*");
            root.addServlet(new ServletHolder(new org.kchine.r.server.http.frontend.WWWDirectoryServlet(
                    ServerManager.WWW_DIR, "/appletlibs")), "/appletlibs/*");

            System.out.println("+ going to start virtualization http server port : " + port);

            _virtualizationServer.start();

            log.info("HTTP R URL :" + "http://" + PoolUtils.getHostIp() + ":" + port + "/rvirtual/cmd");

        } catch (Exception e) {
            log.info(PoolUtils.getStackTraceAsString(e));
            e.printStackTrace();
        }
    }

}