Example usage for javax.servlet.http HttpSessionListener sessionCreated

List of usage examples for javax.servlet.http HttpSessionListener sessionCreated

Introduction

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

Prototype

default public void sessionCreated(HttpSessionEvent se) 

Source Link

Document

Receives notification that a session has been created.

Usage

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

/**
 * Inform the listeners about the new session.
 *
 *//* ww w .  ja v a2s .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.ireland.jnetty.server.session.SessionManager.java

/**
 * ?SessionCreated//from ww  w  .  j a  va2s.  c  o m
 * 
 * @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 {/*  ww  w  . ja  v  a 2 s  .  c  o m*/

        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();
        }
    }

}

From source file:org.ops4j.pax.web.service.internal.EventListenerTest.java

@Test
public void listenerIsCalled() throws IOException, NamespaceException, ServletException, InterruptedException {
    HttpSessionListener listener = createMock(HttpSessionListener.class);
    listener.sessionCreated((HttpSessionEvent) notNull());
    listener.sessionDestroyed((HttpSessionEvent) notNull());

    replay(listener);/*from  ww  w .  ja v a2 s .c o  m*/

    HttpContext context = m_httpService.createDefaultHttpContext();
    m_httpService.registerServlet("/test", new TestServlet(), null, context);
    m_httpService.registerEventListener(listener, context);

    HttpMethod method = new GetMethod("http://localhost:8080/test");
    m_client.executeMethod(method);
    System.out.println("Waiting the session to expire for two minutes...");
    method.releaseConnection();
    Thread.sleep(2 * 60 * 1000);

    verify(listener);

    ((StoppableHttpService) m_httpService).stop();
}