Search in sources :

Example 11 with ListenerInfo

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));
}
Also used : ListenerInfo(io.undertow.servlet.api.ListenerInfo) ServletContextListener(javax.servlet.ServletContextListener) ManagedListener(io.undertow.servlet.core.ManagedListener) ServletException(javax.servlet.ServletException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 12 with ListenerInfo

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);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ListenerInfo(io.undertow.servlet.api.ListenerInfo) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) BeforeClass(org.junit.BeforeClass)

Example 13 with ListenerInfo

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);
}
Also used : HttpHandler(io.undertow.server.HttpHandler) DeploymentManager(io.undertow.servlet.api.DeploymentManager) PathHandler(io.undertow.server.handlers.PathHandler) HandlerWrapper(io.undertow.server.HandlerWrapper) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) ServletInfo(io.undertow.servlet.api.ServletInfo) HttpServerExchange(io.undertow.server.HttpServerExchange) ListenerInfo(io.undertow.servlet.api.ListenerInfo) ServletContainer(io.undertow.servlet.api.ServletContainer) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) MessageServlet(io.undertow.servlet.test.util.MessageServlet) BeforeClass(org.junit.BeforeClass)

Example 14 with ListenerInfo

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);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ListenerInfo(io.undertow.servlet.api.ListenerInfo) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase) BeforeClass(org.junit.BeforeClass)

Example 15 with ListenerInfo

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

Aggregations

ListenerInfo (io.undertow.servlet.api.ListenerInfo)16 ServletInfo (io.undertow.servlet.api.ServletInfo)11 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)10 PathHandler (io.undertow.server.handlers.PathHandler)9 ServletContainer (io.undertow.servlet.api.ServletContainer)9 DeploymentManager (io.undertow.servlet.api.DeploymentManager)8 BeforeClass (org.junit.BeforeClass)8 ServletException (javax.servlet.ServletException)6 ManagedListener (io.undertow.servlet.core.ManagedListener)4 HandlerWrapper (io.undertow.server.HandlerWrapper)3 ServletContainerInitializerInfo (io.undertow.servlet.api.ServletContainerInitializerInfo)3 SimpleServletTestCase (io.undertow.servlet.test.SimpleServletTestCase)3 MessageServlet (io.undertow.servlet.test.util.MessageServlet)3 ImmediateInstanceFactory (io.undertow.servlet.util.ImmediateInstanceFactory)3 ServletContextListener (javax.servlet.ServletContextListener)3 HttpHandler (io.undertow.server.HttpHandler)2 ServletExtension (io.undertow.servlet.ServletExtension)2 ErrorPage (io.undertow.servlet.api.ErrorPage)2 FilterInfo (io.undertow.servlet.api.FilterInfo)2 LoginConfig (io.undertow.servlet.api.LoginConfig)2