Search in sources :

Example 6 with ServletRequestListener

use of javax.servlet.ServletRequestListener in project wildfly by wildfly.

the class UndertowContext method addRequestListener.

@Override
public void addRequestListener(ServletRequestListener listener) {
    ManagedListener ml = new ManagedListener(new ListenerInfo(ServletRequestListener.class, new ImmediateInstanceFactory<>(listener)), true);
    try {
        ml.start();
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
    this.deployment.getApplicationListeners().addListener(ml);
}
Also used : ServletException(javax.servlet.ServletException) ListenerInfo(io.undertow.servlet.api.ListenerInfo) ServletRequestListener(javax.servlet.ServletRequestListener) ManagedListener(io.undertow.servlet.core.ManagedListener) ImmediateInstanceFactory(io.undertow.servlet.util.ImmediateInstanceFactory)

Example 7 with ServletRequestListener

use of javax.servlet.ServletRequestListener in project atmosphere by Atmosphere.

the class ContainerInitializer method onStartup.

@Override
public void onStartup(Set<Class<?>> classes, final ServletContext c) throws ServletException {
    c.log("Initializing AtmosphereFramework");
    for (Map.Entry<String, ? extends ServletRegistration> reg : c.getServletRegistrations().entrySet()) {
        String disableSwitchValue = reg.getValue().getInitParameter(ApplicationConfig.DISABLE_ATMOSPHERE_INITIALIZER);
        // check if AtmosphereInitializer is disabled via web.xml see: https://github.com/Atmosphere/atmosphere/issues/1695
        if (Boolean.parseBoolean(disableSwitchValue)) {
            c.log("Container managed initialization disabled for servlet: " + reg.getValue().getName());
            continue;
        }
        if (c.getAttribute(reg.getKey()) == null && IOUtils.isAtmosphere(reg.getValue().getClassName())) {
            final AtmosphereFramework framework = AtmosphereFrameworkInitializer.newAtmosphereFramework(c, false, true);
            // Hack to make jsr356 works. Pretty ugly.
            DefaultAsyncSupportResolver resolver = new DefaultAsyncSupportResolver(framework.getAtmosphereConfig());
            List<Class<? extends AsyncSupport>> l = resolver.detectWebSocketPresent(false, true);
            if (resolver.testClassExists(DefaultAsyncSupportResolver.JSR356_WEBSOCKET)) {
                try {
                    framework.setAsyncSupport(new JSR356AsyncSupport(framework.getAtmosphereConfig(), c));
                } catch (IllegalStateException ex) {
                    framework.initializationError(ex);
                }
            }
            try {
                c.addListener(new ServletRequestListener() {

                    @Override
                    public void requestDestroyed(ServletRequestEvent sre) {
                    }

                    @Override
                    public void requestInitialized(ServletRequestEvent sre) {
                        HttpServletRequest r = HttpServletRequest.class.cast(sre.getServletRequest());
                        AtmosphereConfig config = framework.getAtmosphereConfig();
                        if (config.isSupportSession() && Utils.webSocketEnabled(r)) {
                            r.getSession(config.getInitParameter(ApplicationConfig.PROPERTY_SESSION_CREATE, true));
                        }
                    }
                });
            } catch (Throwable t) {
                c.log("AtmosphereFramework : Unable to install WebSocket Session Creator", t);
            }
            try {
                String s = c.getInitParameter(PROPERTY_SESSION_SUPPORT);
                if (s != null) {
                    boolean sessionSupport = Boolean.valueOf(s);
                    if (sessionSupport && c.getMajorVersion() > 2) {
                        c.addListener(SessionSupport.class);
                        c.log("AtmosphereFramework : Installed " + SessionSupport.class);
                    }
                }
            } catch (Throwable t) {
                c.log("AtmosphereFramework : SessionSupport error. Make sure you also define {} as a listener in web.xml, see https://github.com/Atmosphere/atmosphere/wiki/Enabling-HttpSession-Support", t);
            }
            c.setAttribute(reg.getKey(), framework);
        }
    }
}
Also used : ServletRequestListener(javax.servlet.ServletRequestListener) JSR356AsyncSupport(org.atmosphere.container.JSR356AsyncSupport) JSR356AsyncSupport(org.atmosphere.container.JSR356AsyncSupport) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequestEvent(javax.servlet.ServletRequestEvent) Map(java.util.Map)

Example 8 with ServletRequestListener

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

the class HttpRequestImpl method init.

public void init() {
    if (begin != null && getAttribute("openejb_requestInitialized") == null) {
        // if called again we loose the request scope
        setAttribute("openejb_requestInitialized", "ok");
        begin.requestInitialized(new ServletRequestEvent(getServletContext(), this));
    }
    listeners = LightweightWebAppBuilderListenerExtractor.findByTypeForContext(contextPath, ServletRequestListener.class);
    if (!listeners.isEmpty()) {
        final ServletRequestEvent event = new ServletRequestEvent(getServletContext(), this);
        for (final ServletRequestListener listener : listeners) {
            listener.requestInitialized(event);
        }
    }
}
Also used : ServletRequestListener(javax.servlet.ServletRequestListener) ServletRequestEvent(javax.servlet.ServletRequestEvent)

Aggregations

ServletRequestListener (javax.servlet.ServletRequestListener)8 ServletRequestEvent (javax.servlet.ServletRequestEvent)6 ArrayList (java.util.ArrayList)2 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)2 Test (org.junit.Test)2 ListenerInfo (io.undertow.servlet.api.ListenerInfo)1 ApplicationListeners (io.undertow.servlet.core.ApplicationListeners)1 ManagedListener (io.undertow.servlet.core.ManagedListener)1 ImmediateInstanceFactory (io.undertow.servlet.util.ImmediateInstanceFactory)1 Map (java.util.Map)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ServletContext (javax.servlet.ServletContext)1 ServletContextAttributeListener (javax.servlet.ServletContextAttributeListener)1 ServletContextEvent (javax.servlet.ServletContextEvent)1 ServletContextListener (javax.servlet.ServletContextListener)1 ServletException (javax.servlet.ServletException)1 ServletRequest (javax.servlet.ServletRequest)1 ServletRequestAttributeListener (javax.servlet.ServletRequestAttributeListener)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSessionAttributeListener (javax.servlet.http.HttpSessionAttributeListener)1