Search in sources :

Example 6 with SessionTrackingMode

use of javax.servlet.SessionTrackingMode in project undertow by undertow-io.

the class ServletContextImpl method initDone.

public void initDone() {
    initialized = true;
    Set<SessionTrackingMode> trackingMethods = sessionTrackingModes;
    SessionConfig sessionConfig = sessionCookieConfig;
    if (trackingMethods != null && !trackingMethods.isEmpty()) {
        if (sessionTrackingModes.contains(SessionTrackingMode.SSL)) {
            sessionConfig = new SslSessionConfig(deployment.getSessionManager());
        } else {
            if (sessionTrackingModes.contains(SessionTrackingMode.COOKIE) && sessionTrackingModes.contains(SessionTrackingMode.URL)) {
                sessionCookieConfig.setFallback(new PathParameterSessionConfig(sessionCookieConfig.getName().toLowerCase(Locale.ENGLISH)));
            } else if (sessionTrackingModes.contains(SessionTrackingMode.URL)) {
                sessionConfig = new PathParameterSessionConfig(sessionCookieConfig.getName().toLowerCase(Locale.ENGLISH));
            }
        }
    }
    SessionConfigWrapper wrapper = deploymentInfo.getSessionConfigWrapper();
    if (wrapper != null) {
        sessionConfig = wrapper.wrap(sessionConfig, deployment);
    }
    this.sessionConfig = new ServletContextSessionConfig(sessionConfig);
    this.onWritePossibleTask = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, WriteListener>() {

        @Override
        public Void call(HttpServerExchange exchange, WriteListener context) throws Exception {
            context.onWritePossible();
            return null;
        }
    });
    this.runnableTask = new ThreadSetupHandler.Action<Void, Runnable>() {

        @Override
        public Void call(HttpServerExchange exchange, Runnable context) throws Exception {
            context.run();
            return null;
        }
    };
    this.onDataAvailableTask = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, ReadListener>() {

        @Override
        public Void call(HttpServerExchange exchange, ReadListener context) throws Exception {
            context.onDataAvailable();
            return null;
        }
    });
    this.onAllDataReadTask = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, ReadListener>() {

        @Override
        public Void call(HttpServerExchange exchange, ReadListener context) throws Exception {
            context.onAllDataRead();
            return null;
        }
    });
    this.invokeActionTask = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, ThreadSetupHandler.Action<Void, Object>>() {

        @Override
        public Void call(HttpServerExchange exchange, ThreadSetupHandler.Action<Void, Object> context) throws Exception {
            context.call(exchange, null);
            return null;
        }
    });
}
Also used : PrivilegedAction(java.security.PrivilegedAction) SessionTrackingMode(javax.servlet.SessionTrackingMode) PathParameterSessionConfig(io.undertow.server.session.PathParameterSessionConfig) SslSessionConfig(io.undertow.server.session.SslSessionConfig) PathParameterSessionConfig(io.undertow.server.session.PathParameterSessionConfig) SessionConfig(io.undertow.server.session.SessionConfig) ReadListener(javax.servlet.ReadListener) ServletException(javax.servlet.ServletException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) HttpServerExchange(io.undertow.server.HttpServerExchange) ThreadSetupHandler(io.undertow.servlet.api.ThreadSetupHandler) SslSessionConfig(io.undertow.server.session.SslSessionConfig) SessionConfigWrapper(io.undertow.servlet.api.SessionConfigWrapper) WriteListener(javax.servlet.WriteListener)

Example 7 with SessionTrackingMode

use of javax.servlet.SessionTrackingMode in project tomee by apache.

the class TomcatWebAppBuilder method beforeStart.

/**
     * {@inheritDoc}
     */
@Override
public void beforeStart(final StandardContext standardContext) {
    if (standardContext.getResources() != null && LazyStopStandardRoot.class.isInstance(standardContext.getResources())) {
        // reset after reload
        Reflections.set(standardContext, "resources", LazyStopStandardRoot.class.cast(standardContext.getResources()).getDelegate());
    }
    final ServletContext sc = standardContext.getServletContext();
    if (sc != null && !SystemInstance.get().getOptions().get(OPENEJB_JSESSION_ID_SUPPORT, true)) {
        final Set<SessionTrackingMode> defaultTrackingModes = sc.getEffectiveSessionTrackingModes();
        if (defaultTrackingModes.contains(SessionTrackingMode.URL)) {
            final Set<SessionTrackingMode> newModes = new HashSet<>();
            newModes.remove(SessionTrackingMode.URL);
            sc.setSessionTrackingModes(newModes);
        }
    }
    initContextLoader(standardContext);
    // used to add custom filters first - our arquillian integration uses it for instance
    // needs to be done now (= before start event) because of addFilterMapBefore() usage
    final String filters = SystemInstance.get().getProperty("org.apache.openejb.servlet.filters");
    if (filters != null) {
        final String[] names = filters.split(",");
        for (final String name : names) {
            final String[] clazzMapping = name.split("=");
            final FilterDef filterDef = new FilterDef();
            filterDef.setFilterClass(clazzMapping[0]);
            filterDef.setFilterName(clazzMapping[0]);
            standardContext.addFilterDef(filterDef);
            final FilterMap filterMap = new FilterMap();
            filterMap.setFilterName(clazzMapping[0]);
            filterMap.addURLPattern(clazzMapping[1]);
            standardContext.addFilterMapBefore(filterMap);
        }
    }
    // mainly to get back compatibility with tomcat <= 8.0
    final String cookieProcessor = SystemInstance.get().getProperty("tomee.tomcat.cookieProcessor");
    if (cookieProcessor != null) {
        // not that important for now if we use the container loader, we mainly want to be able to access
        // the legacy one
        final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        try {
            final Class<?> cookieProcessorClass = contextClassLoader.loadClass(cookieProcessor.trim());
            standardContext.setCookieProcessor(CookieProcessor.class.cast(cookieProcessorClass.newInstance()));
        } catch (final Exception e) {
            throw new IllegalArgumentException("Cannot set CookieProcessor: " + cookieProcessor);
        }
    }
}
Also used : FilterDef(org.apache.tomcat.util.descriptor.web.FilterDef) SessionTrackingMode(javax.servlet.SessionTrackingMode) FilterMap(org.apache.tomcat.util.descriptor.web.FilterMap) LifecycleException(org.apache.catalina.LifecycleException) NameNotFoundException(javax.naming.NameNotFoundException) IOException(java.io.IOException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) CookieProcessor(org.apache.tomcat.util.http.CookieProcessor) ServletContext(javax.servlet.ServletContext) HashSet(java.util.HashSet)

Aggregations

SessionTrackingMode (javax.servlet.SessionTrackingMode)7 HashSet (java.util.HashSet)3 ThreadSetupHandler (io.undertow.servlet.api.ThreadSetupHandler)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Constraint (org.eclipse.jetty.util.security.Constraint)2 HandlerWrapper (io.undertow.server.HandlerWrapper)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 PathParameterSessionConfig (io.undertow.server.session.PathParameterSessionConfig)1 SecureRandomSessionIdGenerator (io.undertow.server.session.SecureRandomSessionIdGenerator)1 SessionConfig (io.undertow.server.session.SessionConfig)1 SslSessionConfig (io.undertow.server.session.SslSessionConfig)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 ServletSessionConfig (io.undertow.servlet.api.ServletSessionConfig)1 SessionConfigWrapper (io.undertow.servlet.api.SessionConfigWrapper)1 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1 PrivilegedAction (java.security.PrivilegedAction)1