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