use of io.undertow.servlet.api.ListenerInfo in project undertow by undertow-io.
the class ServletContextImpl method addListener.
@Override
public void addListener(final Class<? extends EventListener> listenerClass) {
ensureNotInitialized();
ensureNotProgramaticListener();
if (ApplicationListeners.listenerState() != NO_LISTENER && ServletContextListener.class.isAssignableFrom(listenerClass)) {
throw UndertowServletMessages.MESSAGES.cannotAddServletContextListener();
}
InstanceFactory<? extends EventListener> factory = null;
try {
factory = deploymentInfo.getClassIntrospecter().createInstanceFactory(listenerClass);
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
final ListenerInfo listener = new ListenerInfo(listenerClass, factory);
deploymentInfo.addListener(listener);
deployment.getApplicationListeners().addListener(new ManagedListener(listener, true));
}
use of io.undertow.servlet.api.ListenerInfo in project undertow by undertow-io.
the class NestedListenerInvocationTestCase method setup.
@BeforeClass
public static void setup() throws ServletException {
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
ServletInfo a = new ServletInfo("asyncServlet", AsyncServlet.class).setAsyncSupported(true).addMapping("/async");
DeploymentInfo builder = new DeploymentInfo().setClassLoader(NestedListenerInvocationTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServlets(a).addListener(new ListenerInfo(SimpleRequestListener.class));
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
root.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(root);
}
use of io.undertow.servlet.api.ListenerInfo in project undertow by undertow-io.
the class BypassServletTestCase method setup.
@BeforeClass
public static void setup() throws ServletException {
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServlet(new ServletInfo("servlet", MessageServlet.class).addMapping("/").addInitParam(MessageServlet.MESSAGE, "This is a servlet")).addListener(new ListenerInfo(TestListener.class)).addInitialHandlerChainWrapper(new HandlerWrapper() {
@Override
public HttpHandler wrap(final HttpHandler handler) {
return new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
if (exchange.getRelativePath().equals("/async")) {
exchange.getResponseSender().send("This is not a servlet", IoCallback.END_EXCHANGE);
} else {
handler.handleRequest(exchange);
}
}
};
}
});
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
root.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(root);
}
use of io.undertow.servlet.api.ListenerInfo in project undertow by undertow-io.
the class ServletSessionListenerOrderingTestCase method setup.
@BeforeClass
public static void setup() throws ServletException {
final PathHandler path = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/listener").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("listener.war").addListener(new ListenerInfo(FirstListener.class)).addListener(new ListenerInfo(SecondListener.class)).addServlet(new ServletInfo("message", EmptyServlet.class).addMapping("/*"));
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
path.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(path);
}
use of io.undertow.servlet.api.ListenerInfo 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);
}
Aggregations