Search in sources :

Example 41 with ServletContainer

use of io.undertow.servlet.api.ServletContainer in project undertow by undertow-io.

the class MockRequestTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo s = new ServletInfo("servlet", HelloServlet.class).addMapping("/aa");
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(MockRequestTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServlet(s);
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    deployment = manager.getDeployment();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) 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 42 with ServletContainer

use of io.undertow.servlet.api.ServletContainer in project undertow by undertow-io.

the class ServletContextListenerTestCase 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").addServletContainerInitalizer(new ServletContainerInitializerInfo(TestSci.class, Collections.<Class<?>>emptySet())).addServlet(new ServletInfo("servlet", MessageServlet.class).addMapping("/aa")).addListener(new ListenerInfo(ServletContextTestListener.class));
    manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ServletContainerInitializerInfo(io.undertow.servlet.api.ServletContainerInitializerInfo) ListenerInfo(io.undertow.servlet.api.ListenerInfo) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) BeforeClass(org.junit.BeforeClass) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase) MessageServlet(io.undertow.servlet.test.util.MessageServlet) BeforeClass(org.junit.BeforeClass)

Example 43 with ServletContainer

use of io.undertow.servlet.api.ServletContainer in project undertow by undertow-io.

the class ServletSessionInvalidateWithListenerTestCase 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(SimpleSessionListener.class)).addServlet(new ServletInfo("servlet", SessionServlet.class).addMapping("/test"));
    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) BeforeClass(org.junit.BeforeClass)

Example 44 with ServletContainer

use of io.undertow.servlet.api.ServletContainer in project undertow by undertow-io.

the class AsyncContextImpl method dispatch.

@Override
public void dispatch() {
    if (dispatched) {
        throw UndertowServletMessages.MESSAGES.asyncRequestAlreadyDispatched();
    }
    final HttpServletRequestImpl requestImpl = this.servletRequestContext.getOriginalRequest();
    Deployment deployment = requestImpl.getServletContext().getDeployment();
    if (requestSupplied && servletRequest instanceof HttpServletRequest) {
        ServletContainer container = deployment.getServletContainer();
        final String requestURI = ((HttpServletRequest) servletRequest).getRequestURI();
        DeploymentManager context = container.getDeploymentByPath(requestURI);
        if (context == null) {
            throw UndertowServletMessages.MESSAGES.couldNotFindContextToDispatchTo(requestImpl.getOriginalContextPath());
        }
        String toDispatch = requestURI.substring(context.getDeployment().getServletContext().getContextPath().length());
        String qs = ((HttpServletRequest) servletRequest).getQueryString();
        if (qs != null && !qs.isEmpty()) {
            toDispatch = toDispatch + "?" + qs;
        }
        dispatch(context.getDeployment().getServletContext(), toDispatch);
    } else {
        //original request
        ServletContainer container = deployment.getServletContainer();
        DeploymentManager context = container.getDeploymentByPath(requestImpl.getOriginalContextPath());
        if (context == null) {
            //this should never happen
            throw UndertowServletMessages.MESSAGES.couldNotFindContextToDispatchTo(requestImpl.getOriginalContextPath());
        }
        String toDispatch = CanonicalPathUtils.canonicalize(requestImpl.getOriginalRequestURI()).substring(requestImpl.getOriginalContextPath().length());
        String qs = requestImpl.getOriginalQueryString();
        if (qs != null && !qs.isEmpty()) {
            toDispatch = toDispatch + "?" + qs;
        }
        dispatch(context.getDeployment().getServletContext(), toDispatch);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) Deployment(io.undertow.servlet.api.Deployment)

Example 45 with ServletContainer

use of io.undertow.servlet.api.ServletContainer in project undertow by undertow-io.

the class JSRWebSocketServer method main.

public static void main(final String[] args) {
    PathHandler path = Handlers.path();
    Undertow server = Undertow.builder().addHttpListener(8080, "localhost").setHandler(path).build();
    server.start();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(JSRWebSocketServer.class.getClassLoader()).setContextPath("/").addWelcomePage("index.html").setResourceManager(new ClassPathResourceManager(JSRWebSocketServer.class.getClassLoader(), JSRWebSocketServer.class.getPackage())).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(new DefaultByteBufferPool(true, 100)).addEndpoint(JsrChatWebSocketEndpoint.class)).setDeploymentName("chat.war");
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    try {
        path.addPrefixPath("/", manager.start());
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) ClassPathResourceManager(io.undertow.server.handlers.resource.ClassPathResourceManager) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) Undertow(io.undertow.Undertow)

Aggregations

ServletContainer (io.undertow.servlet.api.ServletContainer)71 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)68 DeploymentManager (io.undertow.servlet.api.DeploymentManager)68 PathHandler (io.undertow.server.handlers.PathHandler)58 BeforeClass (org.junit.BeforeClass)55 ServletInfo (io.undertow.servlet.api.ServletInfo)51 SimpleServletTestCase (io.undertow.servlet.test.SimpleServletTestCase)17 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)17 FilterInfo (io.undertow.servlet.api.FilterInfo)16 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)13 LoginConfig (io.undertow.servlet.api.LoginConfig)12 ServletIdentityManager (io.undertow.servlet.test.security.constraint.ServletIdentityManager)10 ListenerInfo (io.undertow.servlet.api.ListenerInfo)9 ServletException (javax.servlet.ServletException)9 Test (org.junit.Test)9 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)8 WebResourceCollection (io.undertow.servlet.api.WebResourceCollection)8 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)8 TestHttpClient (io.undertow.testutils.TestHttpClient)7 MessageServlet (io.undertow.servlet.test.util.MessageServlet)6