Search in sources :

Example 1 with SessionManager

use of org.apache.openejb.server.httpd.session.SessionManager in project tomee by apache.

the class OpenEJBDeployableContainer method quickDeploy.

private DeploymentInfo quickDeploy(final Archive<?> archive, final TestClass testClass, final Closeables cls) throws DeploymentException {
    final String name = archive.getName();
    DeploymentInfo info = DEPLOYMENT_INFO.get(name);
    if (info == null) {
        try {
            final AppModule module = OpenEJBArchiveProcessor.createModule(archive, testClass, cls);
            final AppInfo appInfo = configurationFactory.configureApplication(module);
            final WebAppBuilder webAppBuilder = SystemInstance.get().getComponent(WebAppBuilder.class);
            final boolean isEmbeddedWebAppBuilder = webAppBuilder != null && LightweightWebAppBuilder.class.isInstance(webAppBuilder);
            if (isEmbeddedWebAppBuilder) {
                // for now we keep the same classloader, open to discussion if we should recreate it, not sure it does worth it
                final LightweightWebAppBuilder lightweightWebAppBuilder = LightweightWebAppBuilder.class.cast(webAppBuilder);
                for (final WebModule w : module.getWebModules()) {
                    final String moduleId = w.getModuleId();
                    lightweightWebAppBuilder.setClassLoader(moduleId, w.getClassLoader());
                    cls.add(new Closeable() {

                        @Override
                        public void close() throws IOException {
                            lightweightWebAppBuilder.removeClassLoader(moduleId);
                        }
                    });
                }
            }
            final AppContext appCtx = assembler.createApplication(appInfo, module.getClassLoader());
            if (isEmbeddedWebAppBuilder && PROPERTIES.containsKey(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE) && !appCtx.getWebContexts().isEmpty()) {
                cls.add(new Closeable() {

                    @Override
                    public void close() throws IOException {
                        try {
                            final SessionManager sessionManager = SystemInstance.get().getComponent(SessionManager.class);
                            if (sessionManager != null) {
                                for (final WebContext web : appCtx.getWebContexts()) {
                                    sessionManager.destroy(web);
                                }
                            }
                        } catch (final Throwable e) {
                        // no-op
                        }
                    }
                });
            }
            final ServletContext appServletContext = new MockServletContext();
            final HttpSession appSession = new MockHttpSession();
            if (configuration.isStartDefaultScopes() && appCtx.getWebBeansContext() != null) {
                startContexts(appCtx.getWebBeansContext().getContextsService(), appServletContext, appSession);
            }
            info = new DeploymentInfo(appServletContext, appSession, appInfo, appCtx);
            if (configuration.isSingleDeploymentByArchiveName(name)) {
                DEPLOYMENT_INFO.putIfAbsent(name, info);
            }
        } catch (final Exception e) {
            throw new DeploymentException("can't deploy " + name, e);
        }
    }
    return info;
}
Also used : AppModule(org.apache.openejb.config.AppModule) WebContext(org.apache.openejb.core.WebContext) SessionManager(org.apache.openejb.server.httpd.session.SessionManager) HttpSession(javax.servlet.http.HttpSession) MockHttpSession(org.apache.webbeans.web.lifecycle.test.MockHttpSession) Closeable(java.io.Closeable) AppContext(org.apache.openejb.AppContext) WebModule(org.apache.openejb.config.WebModule) IOException(java.io.IOException) LightweightWebAppBuilder(org.apache.openejb.web.LightweightWebAppBuilder) WebAppBuilder(org.apache.openejb.assembler.classic.WebAppBuilder) MockServletContext(org.apache.webbeans.web.lifecycle.test.MockServletContext) NamingException(javax.naming.NamingException) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) IOException(java.io.IOException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) LightweightWebAppBuilder(org.apache.openejb.web.LightweightWebAppBuilder) MockServletContext(org.apache.webbeans.web.lifecycle.test.MockServletContext) ServletContext(javax.servlet.ServletContext) MockHttpSession(org.apache.webbeans.web.lifecycle.test.MockHttpSession) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException)

Example 2 with SessionManager

use of org.apache.openejb.server.httpd.session.SessionManager in project tomee by apache.

the class OpenEJBHttpServer method stop.

@Override
public void stop() throws ServiceException {
    OpenEJBAsyncContext.destroy();
    final SessionManager component = SystemInstance.get().getComponent(SessionManager.class);
    if (component != null) {
        component.destroy();
    }
}
Also used : SessionManager(org.apache.openejb.server.httpd.session.SessionManager)

Example 3 with SessionManager

use of org.apache.openejb.server.httpd.session.SessionManager in project tomee by apache.

the class HttpRequestImpl method getSession.

public HttpSession getSession(boolean create) {
    if (session == null && create) {
        // default is infinite *here* only
        long timeout = -1;
        if (contextPath != null) {
            // TODO: webapp should be contextual, would need to normalize jaxws, jaxrs, servlet, jsf...before but would be better
            final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
            if (assembler != null) {
                for (final AppInfo info : assembler.getDeployedApplications()) {
                    for (final WebAppInfo webApp : info.webApps) {
                        if (webApp.contextRoot.replace("/", "").equals(contextPath.replace("/", ""))) {
                            timeout = webApp.sessionTimeout;
                        }
                    }
                }
            }
        }
        final HttpSessionImpl impl = new HttpSessionImpl(contextPath, timeout) {

            @Override
            public void invalidate() {
                super.invalidate();
                HttpRequestImpl.this.session = null;
            }
        };
        session = impl;
        if (begin != null) {
            begin.sessionCreated(new HttpSessionEvent(session));
            session = new SessionInvalidateListener(session, begin);
        }
        // can call req.getSession() so do it after affectation + do it after cdi init
        impl.callListeners();
        final SessionManager sessionManager = SystemInstance.get().getComponent(SessionManager.class);
        final SessionManager.SessionWrapper previous = sessionManager.newSession(begin, end, session, application);
        if (previous != null) {
            session = previous.session;
        }
    }
    return session;
}
Also used : WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) SessionManager(org.apache.openejb.server.httpd.session.SessionManager) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) Assembler(org.apache.openejb.assembler.classic.Assembler) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 4 with SessionManager

use of org.apache.openejb.server.httpd.session.SessionManager in project tomee by apache.

the class HttpSessionImpl method invalidate.

@Override
public void invalidate() {
    if (!valid) {
        return;
    }
    synchronized (this) {
        if (!valid) {
            return;
        }
        if (!listeners.isEmpty()) {
            final HttpSessionEvent event = new HttpSessionEvent(this);
            for (final HttpSessionListener o : listeners) {
                try {
                    HttpSessionListener.class.cast(o).sessionDestroyed(event);
                } catch (final Throwable th) {
                // ignore, may be undeployed
                }
            }
        }
        final SessionManager sessionManager = SystemInstance.get().getComponent(SessionManager.class);
        if (sessionManager != null) {
            sessionManager.removeSession(sessionId);
        }
        valid = false;
    }
}
Also used : HttpSessionListener(javax.servlet.http.HttpSessionListener) SessionManager(org.apache.openejb.server.httpd.session.SessionManager) HttpSessionEvent(javax.servlet.http.HttpSessionEvent)

Example 5 with SessionManager

use of org.apache.openejb.server.httpd.session.SessionManager in project tomee by apache.

the class HttpSessionImpl method getSessionContext.

@Override
public HttpSessionContext getSessionContext() {
    touch();
    final SessionManager component = SystemInstance.get().getComponent(SessionManager.class);
    return new HttpSessionContext() {

        @Override
        public javax.servlet.http.HttpSession getSession(final String sessionId) {
            final HttpSessionEvent event = component.findSession(sessionId);
            return event == null ? null : event.getSession();
        }

        @Override
        public Enumeration<String> getIds() {
            return Collections.enumeration(component.findSessionIds());
        }
    };
}
Also used : SessionManager(org.apache.openejb.server.httpd.session.SessionManager) HttpSessionContext(javax.servlet.http.HttpSessionContext) HttpSessionEvent(javax.servlet.http.HttpSessionEvent)

Aggregations

SessionManager (org.apache.openejb.server.httpd.session.SessionManager)5 HttpSessionEvent (javax.servlet.http.HttpSessionEvent)3 AppInfo (org.apache.openejb.assembler.classic.AppInfo)2 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)2 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 NamingException (javax.naming.NamingException)1 ServletContext (javax.servlet.ServletContext)1 HttpSession (javax.servlet.http.HttpSession)1 HttpSessionContext (javax.servlet.http.HttpSessionContext)1 HttpSessionListener (javax.servlet.http.HttpSessionListener)1 AppContext (org.apache.openejb.AppContext)1 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)1 Assembler (org.apache.openejb.assembler.classic.Assembler)1 WebAppBuilder (org.apache.openejb.assembler.classic.WebAppBuilder)1 AppModule (org.apache.openejb.config.AppModule)1 WebModule (org.apache.openejb.config.WebModule)1 WebContext (org.apache.openejb.core.WebContext)1 LightweightWebAppBuilder (org.apache.openejb.web.LightweightWebAppBuilder)1 MockHttpSession (org.apache.webbeans.web.lifecycle.test.MockHttpSession)1