Java Code Examples for io.undertow.servlet.api.DeploymentManager#deploy()
The following examples show how to use
io.undertow.servlet.api.DeploymentManager#deploy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultServletCachingTestCase.java From quarkus-http with Apache License 2.0 | 6 votes |
@BeforeClass public static void setup() throws ServletException, IOException { tmpDir = Files.createTempDirectory(DIR_NAME); 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 CachingResourceManager(100, 10000, dataCache, new PathResourceManager(tmpDir, 10485760, false, false, false), METADATA_MAX_AGE)); builder.addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class) .addMapping("/path/default")) .addFilter(Servlets.filter("message", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "FILTER_TEXT ")) .addFilterUrlMapping("message", "*.txt", DispatcherType.REQUEST); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
Example 2
Source File: GetResourceTestCase.java From quarkus-http with Apache License 2.0 | 6 votes |
@BeforeClass public static void setup() throws ServletException { final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); DeploymentInfo builder = new DeploymentInfo() .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setClassLoader(GetResourceTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setDeploymentName("servletContext.war") .setResourceManager(new TestResourceLoader(GetResourceTestCase.class)); builder.addServlet(new ServletInfo("ReadFileServlet", ReadFileServlet.class) .addMapping("/file")); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
Example 3
Source File: NestedListenerInvocationTestCase.java From quarkus-http with Apache License 2.0 | 6 votes |
@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); }
Example 4
Source File: GetCookiesTestCase.java From quarkus-http with Apache License 2.0 | 6 votes |
@BeforeClass public static void setup() throws ServletException { final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); ServletInfo s = new ServletInfo("servlet", ValidCookieEchoServlet.class) .addMapping("/aaa"); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(GetCookiesTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .addServlet(s); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
Example 5
Source File: ResponseWriterTestCase.java From quarkus-http with Apache License 2.0 | 6 votes |
@BeforeClass public static void setup() throws ServletException { final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); DeploymentInfo builder = new DeploymentInfo() .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setClassLoader(ResponseWriterTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setDeploymentName("servletContext.war") .addServlet(Servlets.servlet("resp", ResponseWriterServlet.class) .addMapping("/resp")) .addServlet(Servlets.servlet("respLArget", LargeResponseWriterServlet.class) .addMapping("/large")); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
Example 6
Source File: ServletSessionListenerOrderingTestCase.java From quarkus-http with Apache License 2.0 | 6 votes |
@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); }
Example 7
Source File: ConfidentialityConstraintUrlMappingTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() throws Exception { DefaultServer.startSSLServer(); final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); ServletInfo s = new ServletInfo("servlet", SendSchemeServlet.class) .addMapping("/clear") .addMapping("/integral") .addMapping("/confidential"); DeploymentInfo info = new DeploymentInfo() .setClassLoader(SimpleServletTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .setConfidentialPortManager(TestConfidentialPortManager.INSTANCE) .addServlet(s); info.addSecurityConstraint(new SecurityConstraint() .addWebResourceCollection(new WebResourceCollection() .addUrlPattern("/integral")) .setTransportGuaranteeType(TransportGuaranteeType.INTEGRAL) .setEmptyRoleSemantic(EmptyRoleSemantic.PERMIT)); info.addSecurityConstraint(new SecurityConstraint() .addWebResourceCollection(new WebResourceCollection() .addUrlPattern("/confidential")) .setTransportGuaranteeType(TransportGuaranteeType.CONFIDENTIAL) .setEmptyRoleSemantic(EmptyRoleSemantic.PERMIT)); DeploymentManager manager = container.addDeployment(info); manager.deploy(); root.addPrefixPath(info.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
Example 8
Source File: SuspendResumeTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() throws ServletException { 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() .addListener(new WebSocketDeploymentInfo.ContainerReadyListener() { @Override public void ready(ServerWebSocketContainer c) { serverContainer = c; } }) .addEndpoint(SuspendResumeEndpoint.class) ) .setDeploymentName("servletContext.war"); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/", manager.start())); }
Example 9
Source File: AbstractResponseWrapperTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
@Before public void setup() throws ServletException { DeploymentInfo builder = new DeploymentInfo(); builder.setExceptionHandler(LoggingExceptionHandler.builder().add(IllegalArgumentException.class, "io.undertow", Logger.Level.DEBUG).build()); final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); builder.addServlet(new ServletInfo("wrapperServlet", WrapperServlet.class) .addMapping("/*")); builder.addFilter(new FilterInfo("standard", StandardRequestWrappingFilter.class)); builder.addFilterUrlMapping("standard", "/standard", DispatcherType.REQUEST); builder.addFilter(new FilterInfo("nonstandard", NonStandardRequestWrappingFilter.class)); builder.addFilterUrlMapping("nonstandard", "/nonstandard", DispatcherType.REQUEST); builder.setClassIntrospecter(TestClassIntrospector.INSTANCE) .setClassLoader(AbstractResponseWrapperTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setDeploymentName("servletContext.war") .setAllowNonStandardWrappers(isNonStandardAllowed()); final DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
Example 10
Source File: ServletClientCertAuthTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() throws ServletException, IOException { DefaultServer.startSSLServer(); clientSSLContext = DefaultServer.getClientSSLContext(); final PathHandler path = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); ServletInfo usernameServlet = new ServletInfo("Username Servlet", SendUsernameServlet.class) .addMapping("/secured/username"); ServletInfo authTypeServlet = new ServletInfo("Auth Type Servlet", SendAuthTypeServlet.class) .addMapping("/secured/authType"); LoginConfig loginConfig = new LoginConfig(REALM_NAME); loginConfig.addFirstAuthMethod(new AuthMethodConfig("CLIENT_CERT")); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(SimpleServletTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .setIdentityManager(identityManager) .setLoginConfig(loginConfig) .addServlets(usernameServlet, authTypeServlet); builder.addSecurityConstraint(new SecurityConstraint() .addWebResourceCollection(new WebResourceCollection() .addUrlPattern("/secured/*")) .addRoleAllowed("role1") .setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.DENY)); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); path.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(path); }
Example 11
Source File: ServletCustomAuthTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() throws ServletException { final PathHandler path = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); ServletInfo s = new ServletInfo("servlet", SendUsernameServlet.class) .setServletSecurityInfo(new ServletSecurityInfo() .addRoleAllowed("role1")) .addMapping("/secured/*"); ServletInfo s1 = new ServletInfo("loginPage", FormLoginServlet.class) .setServletSecurityInfo(new ServletSecurityInfo() .addRoleAllowed("group1")) .addMapping("/FormLoginServlet"); ServletIdentityManager identityManager = new ServletIdentityManager(); identityManager.addUser("user1", "password1", "role1"); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(SimpleServletTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .setIdentityManager(identityManager) .setLoginConfig(new LoginConfig("FORM", "Test Realm", "/FormLoginServlet", "/error.html")) .addServlets(s, s1) .addAuthenticationMechanism("FORM", CustomAuthenticationMechanism.FACTORY); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); path.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(path); }
Example 12
Source File: CamelEndpointDeployerService.java From wildfly-camel with Apache License 2.0 | 5 votes |
/** * The stuff common for {@link #deploy(URI, EndpointHttpHandler)} and {@link #deploy(URI, HttpHandler)}. * * @param uri * @param endpointServletConsumer customize the {@link EndpointServlet} * @param deploymentInfoConsumer customize the {@link DeploymentInfo} * @param deploymentConsumer customize the {@link DeploymentImpl} */ void doDeploy(URI uri, Consumer<EndpointServlet> endpointServletConsumer, Consumer<DeploymentInfo> deploymentInfoConsumer, Consumer<DeploymentImpl> deploymentConsumer) { final ServletInfo servletInfo = Servlets.servlet(EndpointServlet.NAME, EndpointServlet.class).addMapping("/*") .setAsyncSupported(true); final DeploymentInfo mainDeploymentInfo = deploymentInfoSupplier.getValue(); DeploymentInfo endPointDeplyomentInfo = adaptDeploymentInfo(mainDeploymentInfo, uri, servletInfo); deploymentInfoConsumer.accept(endPointDeplyomentInfo); CamelLogger.LOGGER.debug("Deploying endpoint {}", endPointDeplyomentInfo.getDeploymentName()); final ClassLoader old = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(endPointDeplyomentInfo.getClassLoader()); try { final DeploymentManager manager = servletContainerServiceSupplier.getValue().getServletContainer() .addDeployment(endPointDeplyomentInfo); manager.deploy(); final Deployment deployment = manager.getDeployment(); try { deploymentConsumer.accept((DeploymentImpl) deployment); manager.start(); hostSupplier.getValue().registerDeployment(deployment, deployment.getHandler()); ManagedServlet managedServlet = deployment.getServlets().getManagedServlet(EndpointServlet.NAME); EndpointServlet servletInstance = (EndpointServlet) managedServlet.getServlet().getInstance(); endpointServletConsumer.accept(servletInstance); } catch (ServletException ex) { throw new IllegalStateException(ex); } synchronized (deployments) { deployments.put(uri, manager); } } finally { Thread.currentThread().setContextClassLoader(old); } }
Example 13
Source File: FilterPathMappingTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
@Test public void testExtensionMatchServletWithGlobalFilter() throws IOException, ServletException { DeploymentInfo builder = new DeploymentInfo(); final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); builder.addServlet(new ServletInfo("*.jsp", PathMappingServlet.class) .addMapping("*.jsp")); builder.addFilter(new FilterInfo("/*", PathFilter.class)); builder.addFilterUrlMapping("/*", "/*", DispatcherType.REQUEST); builder.setClassIntrospecter(TestClassIntrospector.INSTANCE) .setClassLoader(FilterPathMappingTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setDeploymentName("servletContext.war"); final DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); TestHttpClient client = new TestHttpClient(); try { runTest(client, "aa.jsp", "*.jsp - /aa.jsp - null", "/*"); } finally { client.getConnectionManager().shutdown(); } }
Example 14
Source File: SecurityErrorPageTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() throws IOException, ServletException { final ServletContainer container = ServletContainer.Factory.newInstance(); final PathHandler root = new PathHandler(); DefaultServer.setRootHandler(root); DeploymentInfo builder = new DeploymentInfo(); builder.addServlet(new ServletInfo("secure", SecureServlet.class) .addMapping("/secure")) .addSecurityConstraint(Servlets.securityConstraint().addRoleAllowed("user").addWebResourceCollection(Servlets.webResourceCollection().addUrlPattern("/*"))); builder.addServlet(new ServletInfo("path", PathServlet.class) .addMapping("/*")); builder.addErrorPage(new ErrorPage("/401", StatusCodes.UNAUTHORIZED)); ServletIdentityManager identityManager = new ServletIdentityManager(); identityManager.addUser("user1", "password1"); // Just one role less user. builder.setClassIntrospecter(TestClassIntrospector.INSTANCE) .setClassLoader(ErrorPageTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setServletStackTraces(ServletStackTraces.NONE) .setIdentityManager(identityManager) .setLoginConfig(Servlets.loginConfig("BASIC", "Test Realm")) .setDeploymentName("servletContext.war"); final DeploymentManager manager1 = container.addDeployment(builder); manager1.deploy(); root.addPrefixPath(builder.getContextPath(), manager1.start()); }
Example 15
Source File: ProgramaticAutobahnServer.java From quarkus-http with Apache License 2.0 | 5 votes |
public void run() { try { final ServletContainer container = ServletContainer.Factory.newInstance(); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(ProgramaticAutobahnServer.class.getClassLoader()) .setContextPath("/") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .addFilter(new FilterInfo("filter", JsrWebSocketFilter.class)) .addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST) .addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo() .setDispatchToWorkerThread(true) .addEndpoint(new ServerEndpointConfigImpl(ProgramaticAutobahnEndpoint.class, "/")) ); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); Undertow.builder().addHttpListener(port, "localhost") .setHandler(manager.start()) .build(); } catch (Exception e) { throw new RuntimeException(e); } }
Example 16
Source File: RequestListenerAsyncRequestTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() throws ServletException { final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); ServletInfo m = new ServletInfo("messageServlet", MessageServlet.class) .addInitParam(MessageServlet.MESSAGE, HELLO_WORLD) .setAsyncSupported(true) .addMapping("/message"); ServletInfo a = new ServletInfo("asyncServlet", AsyncServlet.class) .addInitParam(MessageServlet.MESSAGE, HELLO_WORLD) .setAsyncSupported(true) .addMapping("/async"); ServletInfo comp = new ServletInfo("completeAsyncServlet", CompleteAsyncServlet.class) .addInitParam(MessageServlet.MESSAGE, HELLO_WORLD) .setAsyncSupported(true) .addMapping("/asynccomplete"); ServletInfo a2 = new ServletInfo("asyncServlet2", AnotherAsyncServlet.class) .setAsyncSupported(true) .addMapping("/async2"); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(SimpleServletTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .addServlets(m, a, a2, comp) .addListener(new ListenerInfo(TestListener.class)); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
Example 17
Source File: UndertowHTTPServerEngine.java From cxf with Apache License 2.0 | 5 votes |
private ServletContext buildServletContext(String contextName) throws ServletException { ServletContainer servletContainer = new ServletContainerImpl(); DeploymentInfo deploymentInfo = new DeploymentInfo(); deploymentInfo.setClassLoader(Thread.currentThread().getContextClassLoader()); deploymentInfo.setDeploymentName("cxf-undertow"); deploymentInfo.setContextPath(contextName); ServletInfo asyncServlet = new ServletInfo(ServletPathMatches.DEFAULT_SERVLET_NAME, CxfUndertowServlet.class); deploymentInfo.addServlet(asyncServlet); servletContainer.addDeployment(deploymentInfo); DeploymentManager deploymentManager = servletContainer.getDeployment(deploymentInfo.getDeploymentName()); deploymentManager.deploy(); deploymentManager.start(); return deploymentManager.getDeployment().getServletContext(); }
Example 18
Source File: MarkSecureHandlerTestCase.java From quarkus-http with Apache License 2.0 | 4 votes |
@Test public void testMarkSecureHandlerWithSecureCookieHandler() throws IOException, GeneralSecurityException, ServletException { final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); ServletInfo s = new ServletInfo("servlet", MessageServlet.class) .addInitParam(MessageServlet.MESSAGE, HELLO_WORLD) .addMapping("/issecure"); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(MarkSecureHandlerTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .addServlet(s); builder.addFilter(new FilterInfo("issecure-filter", IsSecureFilter.class)); builder.addFilterUrlMapping("issecure-filter", "/*", DispatcherType.REQUEST); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(new MarkSecureHandler(new SecureCookieHandler(root))); TestHttpClient client = new TestHttpClient(); try { HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/issecure"); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); // When MarkSecureHandler is enabled, req.isSecure() should be true Assert.assertEquals("true", result.getHeaders("issecure")[0].getValue()); // When SecureCookieHandler is enabled with MarkSecureHandler, secure cookie is enabled as this channel is treated as secure Header header = result.getFirstHeader("set-cookie"); Assert.assertEquals("foo=bar; secure", header.getValue()); final String response = HttpClientUtils.readResponse(result); Assert.assertEquals(HELLO_WORLD, response); } finally { client.getConnectionManager().shutdown(); } }
Example 19
Source File: SaveOriginalPostRequestTestCase.java From quarkus-http with Apache License 2.0 | 4 votes |
@BeforeClass public static void setup() throws ServletException { final PathHandler path = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); ServletInfo securedRequestDumper = new ServletInfo("SecuredRequestDumperServlet", RequestDumper.class) .setServletSecurityInfo(new ServletSecurityInfo() .addRoleAllowed("role1")) .addMapping("/secured/dumpRequest"); ServletInfo securedIndexRequestDumper = new ServletInfo("SecuredIndexRequestDumperServlet", RequestDumper.class) .setServletSecurityInfo(new ServletSecurityInfo() .addRoleAllowed("role1")) .addMapping("/index.html"); ServletInfo unsecuredRequestDumper = new ServletInfo("UnsecuredRequestDumperServlet", RequestDumper.class) .addMapping("/dumpRequest"); ServletInfo loginFormServlet = new ServletInfo("loginPage", FormLoginServlet.class) .setServletSecurityInfo(new ServletSecurityInfo() .addRoleAllowed("group1")) .addMapping("/FormLoginServlet"); ServletIdentityManager identityManager = new ServletIdentityManager(); identityManager.addUser("user1", "password1", "role1"); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(SimpleServletTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .setIdentityManager(identityManager) .addWelcomePage("index.html") .setResourceManager(new TestResourceLoader(SaveOriginalPostRequestTestCase.class)) .setLoginConfig(new LoginConfig("FORM", "Test Realm", "/FormLoginServlet", "/error.html")) .addServlets(securedRequestDumper, unsecuredRequestDumper, loginFormServlet, securedIndexRequestDumper); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); path.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(path); }
Example 20
Source File: ServletMetricsHandlerTestCase.java From quarkus-http with Apache License 2.0 | 4 votes |
@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(); } }