Search in sources :

Example 66 with ServletContainer

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

the class SuspendResumeTestCase method setUp.

@BeforeClass
public static void setUp() {
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(TestMessagesReceivedInOrder.class.getClassLoader()).setContextPath("/").setResourceManager(new TestResourceLoader(TestMessagesReceivedInOrder.class)).setClassIntrospecter(TestClassIntrospector.INSTANCE).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorker()).addListener(c -> serverContainer = c).addEndpoint(SuspendResumeEndpoint.class)).setDeploymentName("servletContext.war");
    deploymentManager = container.addDeployment(builder);
    deploymentManager.deploy();
    try {
        DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/", deploymentManager.start()));
    } catch (ServletException e) {
        e.printStackTrace();
    }
}
Also used : Handlers(io.undertow.Handlers) BeforeClass(org.junit.BeforeClass) ServletException(javax.servlet.ServletException) TestClassIntrospector(io.undertow.servlet.test.util.TestClassIntrospector) HttpOneOnly(io.undertow.testutils.HttpOneOnly) TestMessagesReceivedInOrder(io.undertow.websockets.jsr.test.TestMessagesReceivedInOrder) RunWith(org.junit.runner.RunWith) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) ServerWebSocketContainer(io.undertow.websockets.jsr.ServerWebSocketContainer) BufferedTextMessage(io.undertow.websockets.core.BufferedTextMessage) AtomicReference(java.util.concurrent.atomic.AtomicReference) TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) BufferedBinaryMessage(io.undertow.websockets.core.BufferedBinaryMessage) URI(java.net.URI) StreamSourceFrameChannel(io.undertow.websockets.core.StreamSourceFrameChannel) AfterClass(org.junit.AfterClass) WebSocketFrameType(io.undertow.websockets.core.WebSocketFrameType) DefaultServer(io.undertow.testutils.DefaultServer) IOException(java.io.IOException) Test(org.junit.Test) ServletContainer(io.undertow.servlet.api.ServletContainer) AbstractReceiveListener(io.undertow.websockets.core.AbstractReceiveListener) DeploymentManager(io.undertow.servlet.api.DeploymentManager) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) WebSockets(io.undertow.websockets.core.WebSockets) WebSocketClient(io.undertow.websockets.client.WebSocketClient) WebSocketChannel(io.undertow.websockets.core.WebSocketChannel) Channels(org.xnio.channels.Channels) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) Assert(org.junit.Assert) UpgradeFailedException(org.xnio.http.UpgradeFailedException) IoUtils(org.xnio.IoUtils) ServletException(javax.servlet.ServletException) TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) ServletContainer(io.undertow.servlet.api.ServletContainer) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) BeforeClass(org.junit.BeforeClass)

Example 67 with ServletContainer

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

the class DynamicEndpointTest method setup.

@BeforeClass
public static void setup() throws Exception {
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(DynamicEndpointTest.class.getClassLoader()).setContextPath("/ws").setResourceManager(new TestResourceLoader(DynamicEndpointTest.class)).setClassIntrospecter(TestClassIntrospector.INSTANCE).addServlet(Servlets.servlet("upgrade", DoUpgradeServlet.class).addMapping("/*")).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorkerSupplier()).addListener(containerReady -> deployment = containerReady)).setDeploymentName("servletContext.war");
    deploymentManager = container.addDeployment(builder);
    deploymentManager.deploy();
    DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/ws", deploymentManager.start()));
}
Also used : TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) ServletContainer(io.undertow.servlet.api.ServletContainer) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) BeforeClass(org.junit.BeforeClass)

Example 68 with ServletContainer

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

the class JsrWebsocketExtensionTestCase method setup.

@BeforeClass
public static void setup() throws Exception {
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(BinaryEndpointTest.class.getClassLoader()).setContextPath("/").setClassIntrospecter(TestClassIntrospector.INSTANCE).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setDispatchToWorkerThread(true).setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorkerSupplier()).addExtension(new PerMessageDeflateHandshake()).addEndpoint(AutobahnAnnotatedEndpoint.class)).setDeploymentName("servletContext.war");
    deploymentManager = container.addDeployment(builder);
    deploymentManager.deploy();
    debug = new DebugExtensionsHeaderHandler(deploymentManager.start());
    DefaultServer.setRootHandler(debug);
}
Also used : DebugExtensionsHeaderHandler(io.undertow.websockets.extensions.DebugExtensionsHeaderHandler) ServletContainer(io.undertow.servlet.api.ServletContainer) PerMessageDeflateHandshake(io.undertow.websockets.extensions.PerMessageDeflateHandshake) BinaryEndpointTest(io.undertow.websockets.jsr.test.BinaryEndpointTest) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) BeforeClass(org.junit.BeforeClass)

Example 69 with ServletContainer

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

the class ServletMetricsHandlerTestCase method testMetrics.

@Test
public void testMetrics() throws Exception {
    final TestMetricsCollector metricsCollector = new TestMetricsCollector();
    CompletionLatchHandler completionLatchHandler;
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ServletPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(DefaultServletTestCase.class));
    builder.addServlet(new ServletInfo("MetricTestServlet", MetricTestServlet.class).addMapping("/path/default"));
    builder.addFilter(new FilterInfo("Filter", HelloFilter.class));
    builder.addFilterUrlMapping("Filter", "/filterpath/*", DispatcherType.REQUEST);
    builder.setMetricsCollector(metricsCollector);
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(completionLatchHandler = new CompletionLatchHandler(root));
    HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/path/default");
    TestHttpClient client = new TestHttpClient();
    try {
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertTrue(HttpClientUtils.readResponse(result).contains("metric"));
        completionLatchHandler.await();
        completionLatchHandler.reset();
        MetricsHandler.MetricResult metrics = metricsCollector.getMetrics("MetricTestServlet");
        Assert.assertEquals(1, metrics.getTotalRequests());
        Assert.assertTrue(metrics.getMaxRequestTime() > 0);
        Assert.assertEquals(metrics.getMinRequestTime(), metrics.getMaxRequestTime());
        Assert.assertEquals(metrics.getMaxRequestTime(), metrics.getTotalRequestTime());
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertTrue(HttpClientUtils.readResponse(result).contains("metric"));
        completionLatchHandler.await();
        completionLatchHandler.reset();
        metrics = metricsCollector.getMetrics("MetricTestServlet");
        Assert.assertEquals(2, metrics.getTotalRequests());
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : HelloFilter(io.undertow.servlet.test.defaultservlet.HelloFilter) DefaultServletTestCase(io.undertow.servlet.test.defaultservlet.DefaultServletTestCase) TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) DeploymentManager(io.undertow.servlet.api.DeploymentManager) CompletionLatchHandler(io.undertow.util.CompletionLatchHandler) HttpGet(org.apache.http.client.methods.HttpGet) PathHandler(io.undertow.server.handlers.PathHandler) HttpResponse(org.apache.http.HttpResponse) TestHttpClient(io.undertow.testutils.TestHttpClient) ServletInfo(io.undertow.servlet.api.ServletInfo) ServletContainer(io.undertow.servlet.api.ServletContainer) MetricsHandler(io.undertow.server.handlers.MetricsHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo) Test(org.junit.Test)

Example 70 with ServletContainer

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

the class ServletContextRolesTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    final ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "unspecified-role");
    LoginConfig loginConfig = new LoginConfig(REALM_NAME);
    Map<String, String> props = new HashMap<>();
    props.put("charset", "ISO_8859_1");
    props.put("user-agent-charsets", "Chrome,UTF-8,OPR,UTF-8");
    loginConfig.addFirstAuthMethod(new AuthMethodConfig("BASIC", props));
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(ServletContextRolesTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServlet(new ServletInfo("servlet", CheckRolesServlet.class).addMapping("/aa")).addListener(new ListenerInfo(DeclareRolesServletContextListener.class)).setIdentityManager(identityManager).setLoginConfig(loginConfig);
    builder.addPrincipalVsRoleMappings("user1", DeclareRolesServletContextListener.ROLES);
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/*")).addRolesAllowed(DeclareRolesServletContextListener.ROLES).setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.DENY));
    manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
Also used : WebResourceCollection(io.undertow.servlet.api.WebResourceCollection) HashMap(java.util.HashMap) PathHandler(io.undertow.server.handlers.PathHandler) ServletIdentityManager(io.undertow.servlet.test.security.constraint.ServletIdentityManager) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) ServletInfo(io.undertow.servlet.api.ServletInfo) ListenerInfo(io.undertow.servlet.api.ListenerInfo) AuthMethodConfig(io.undertow.servlet.api.AuthMethodConfig) ServletContainer(io.undertow.servlet.api.ServletContainer) LoginConfig(io.undertow.servlet.api.LoginConfig) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) BeforeClass(org.junit.BeforeClass)

Aggregations

ServletContainer (io.undertow.servlet.api.ServletContainer)92 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)88 DeploymentManager (io.undertow.servlet.api.DeploymentManager)78 PathHandler (io.undertow.server.handlers.PathHandler)76 BeforeClass (org.junit.BeforeClass)69 ServletInfo (io.undertow.servlet.api.ServletInfo)65 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)20 SimpleServletTestCase (io.undertow.servlet.test.SimpleServletTestCase)19 ServletException (javax.servlet.ServletException)19 FilterInfo (io.undertow.servlet.api.FilterInfo)18 LoginConfig (io.undertow.servlet.api.LoginConfig)18 ServletIdentityManager (io.undertow.servlet.test.security.constraint.ServletIdentityManager)16 Test (org.junit.Test)15 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)14 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)12 WebResourceCollection (io.undertow.servlet.api.WebResourceCollection)12 ListenerInfo (io.undertow.servlet.api.ListenerInfo)10 TestHttpClient (io.undertow.testutils.TestHttpClient)9 ServletSecurityInfo (io.undertow.servlet.api.ServletSecurityInfo)8 AuthMethodConfig (io.undertow.servlet.api.AuthMethodConfig)7