Search in sources :

Example 1 with PathHandler

use of io.undertow.server.handlers.PathHandler in project wildfly by wildfly.

the class AbstractUndertowSubsystemTestCase method testRuntime.

public static void testRuntime(KernelServices mainServices, final String virtualHostName, int flag) throws Exception {
    if (!mainServices.isSuccessfulBoot()) {
        Throwable t = mainServices.getBootError();
        Assert.fail("Boot unsuccessful: " + (t != null ? t.toString() : "no boot error provided"));
    }
    ServiceController<FilterService> connectionLimiter = (ServiceController<FilterService>) mainServices.getContainer().getService(UndertowService.FILTER.append("limit-connections"));
    connectionLimiter.setMode(ServiceController.Mode.ACTIVE);
    FilterService connectionLimiterService = connectionLimiter.getService().getValue();
    HttpHandler result = connectionLimiterService.createHttpHandler(Predicates.truePredicate(), new PathHandler());
    Assert.assertNotNull("handler should have been created", result);
    ServiceController<FilterService> headersFilter = (ServiceController<FilterService>) mainServices.getContainer().getService(UndertowService.FILTER.append("headers"));
    headersFilter.setMode(ServiceController.Mode.ACTIVE);
    FilterService headersService = headersFilter.getService().getValue();
    HttpHandler headerHandler = headersService.createHttpHandler(Predicates.truePredicate(), new PathHandler());
    Assert.assertNotNull("handler should have been created", headerHandler);
    final ServiceName hostServiceName = UndertowService.virtualHostName(virtualHostName, "other-host");
    ServiceController<Host> hostSC = (ServiceController<Host>) mainServices.getContainer().getService(hostServiceName);
    Assert.assertNotNull(hostSC);
    hostSC.setMode(ServiceController.Mode.ACTIVE);
    Host host = hostSC.getValue();
    Assert.assertEquals(1, host.getFilters().size());
    if (flag == 1) {
        Assert.assertEquals(3, host.getAllAliases().size());
        Assert.assertEquals("default-alias", new ArrayList<>(host.getAllAliases()).get(1));
    }
    final ServiceName locationServiceName = UndertowService.locationServiceName(virtualHostName, "default-host", "/");
    ServiceController<LocationService> locationSC = (ServiceController<LocationService>) mainServices.getContainer().getService(locationServiceName);
    Assert.assertNotNull(locationSC);
    locationSC.setMode(ServiceController.Mode.ACTIVE);
    LocationService locationService = locationSC.getValue();
    Assert.assertNotNull(locationService);
    connectionLimiter.setMode(ServiceController.Mode.REMOVE);
    final ServiceName jspServiceName = UndertowService.SERVLET_CONTAINER.append("myContainer");
    ServiceController<ServletContainerService> jspServiceServiceController = (ServiceController<ServletContainerService>) mainServices.getContainer().getService(jspServiceName);
    Assert.assertNotNull(jspServiceServiceController);
    JSPConfig jspConfig = jspServiceServiceController.getService().getValue().getJspConfig();
    Assert.assertNotNull(jspConfig);
    Assert.assertNotNull(jspConfig.createJSPServletInfo());
    final ServiceName filterRefName = UndertowService.filterRefName(virtualHostName, "other-host", "/", "static-gzip");
    ServiceController<FilterRef> gzipFilterController = (ServiceController<FilterRef>) mainServices.getContainer().getService(filterRefName);
    gzipFilterController.setMode(ServiceController.Mode.ACTIVE);
    FilterRef gzipFilterRef = gzipFilterController.getService().getValue();
    HttpHandler gzipHandler = gzipFilterRef.createHttpHandler(new PathHandler());
    Assert.assertNotNull("handler should have been created", gzipHandler);
}
Also used : HttpHandler(io.undertow.server.HttpHandler) FilterService(org.wildfly.extension.undertow.filters.FilterService) ArrayList(java.util.ArrayList) PathHandler(io.undertow.server.handlers.PathHandler) FilterRef(org.wildfly.extension.undertow.filters.FilterRef) ServiceName(org.jboss.msc.service.ServiceName) ServiceController(org.jboss.msc.service.ServiceController)

Example 2 with PathHandler

use of io.undertow.server.handlers.PathHandler in project wildfly by wildfly.

the class UndertowSubsystem12TestCase method testCustomFilters.

private void testCustomFilters(KernelServices mainServices) {
    ServiceController<FilterService> customFilter = (ServiceController<FilterService>) mainServices.getContainer().getService(UndertowService.FILTER.append("custom-filter"));
    customFilter.setMode(ServiceController.Mode.ACTIVE);
    FilterService connectionLimiterService = customFilter.getService().getValue();
    HttpHandler result = connectionLimiterService.createHttpHandler(Predicates.truePredicate(), new PathHandler());
    Assert.assertNotNull("handler should have been created", result);
}
Also used : HttpHandler(io.undertow.server.HttpHandler) FilterService(org.wildfly.extension.undertow.filters.FilterService) PathHandler(io.undertow.server.handlers.PathHandler) ServiceController(org.jboss.msc.service.ServiceController)

Example 3 with PathHandler

use of io.undertow.server.handlers.PathHandler in project wildfly by wildfly.

the class UndertowSubsystem31TestCase method testRuntime.

@Test
public void testRuntime() throws Exception {
    System.setProperty("server.data.dir", System.getProperty("java.io.tmpdir"));
    System.setProperty("jboss.home.dir", System.getProperty("java.io.tmpdir"));
    System.setProperty("jboss.home.dir", System.getProperty("java.io.tmpdir"));
    System.setProperty("jboss.server.server.dir", System.getProperty("java.io.tmpdir"));
    KernelServicesBuilder builder = createKernelServicesBuilder(RUNTIME).setSubsystemXml(getSubsystemXml());
    KernelServices mainServices = builder.build();
    if (!mainServices.isSuccessfulBoot()) {
        Assert.fail(mainServices.getBootError().toString());
    }
    ServiceController<FilterService> connectionLimiter = (ServiceController<FilterService>) mainServices.getContainer().getService(UndertowService.FILTER.append("limit-connections"));
    connectionLimiter.setMode(ServiceController.Mode.ACTIVE);
    FilterService connectionLimiterService = connectionLimiter.getService().getValue();
    HttpHandler result = connectionLimiterService.createHttpHandler(Predicates.truePredicate(), new PathHandler());
    Assert.assertNotNull("handler should have been created", result);
    ServiceController<FilterService> headersFilter = (ServiceController<FilterService>) mainServices.getContainer().getService(UndertowService.FILTER.append("headers"));
    headersFilter.setMode(ServiceController.Mode.ACTIVE);
    FilterService headersService = headersFilter.getService().getValue();
    HttpHandler headerHandler = headersService.createHttpHandler(Predicates.truePredicate(), new PathHandler());
    Assert.assertNotNull("handler should have been created", headerHandler);
    final ServiceName hostServiceName = UndertowService.virtualHostName("some-server", "other-host");
    ServiceController<Host> hostSC = (ServiceController<Host>) mainServices.getContainer().getService(hostServiceName);
    Assert.assertNotNull(hostSC);
    hostSC.setMode(ServiceController.Mode.ACTIVE);
    Host host = hostSC.getValue();
    Assert.assertEquals(1, host.getFilters().size());
    Assert.assertEquals(3, host.getAllAliases().size());
    Assert.assertEquals("default-alias", new ArrayList<>(host.getAllAliases()).get(1));
    final ServiceName locationServiceName = UndertowService.locationServiceName("some-server", "default-host", "/");
    ServiceController<LocationService> locationSC = (ServiceController<LocationService>) mainServices.getContainer().getService(locationServiceName);
    Assert.assertNotNull(locationSC);
    locationSC.setMode(ServiceController.Mode.ACTIVE);
    LocationService locationService = locationSC.getValue();
    Assert.assertNotNull(locationService);
    connectionLimiter.setMode(ServiceController.Mode.REMOVE);
    final ServiceName jspServiceName = UndertowService.SERVLET_CONTAINER.append("myContainer");
    ServiceController<ServletContainerService> jspServiceServiceController = (ServiceController<ServletContainerService>) mainServices.getContainer().getService(jspServiceName);
    Assert.assertNotNull(jspServiceServiceController);
    JSPConfig jspConfig = jspServiceServiceController.getService().getValue().getJspConfig();
    Assert.assertNotNull(jspConfig);
    Assert.assertNotNull(jspConfig.createJSPServletInfo());
    final ServiceName filterRefName = UndertowService.filterRefName("some-server", "other-host", "/", "static-gzip");
    ServiceController<FilterRef> gzipFilterController = (ServiceController<FilterRef>) mainServices.getContainer().getService(filterRefName);
    gzipFilterController.setMode(ServiceController.Mode.ACTIVE);
    FilterRef gzipFilterRef = gzipFilterController.getService().getValue();
    HttpHandler gzipHandler = gzipFilterRef.createHttpHandler(new PathHandler());
    Assert.assertNotNull("handler should have been created", gzipHandler);
    //testCustomFilters(mainServices);
    ServiceController<Host> defaultHostSC = (ServiceController<Host>) mainServices.getContainer().getService(UndertowService.DEFAULT_HOST);
    defaultHostSC.setMode(ServiceController.Mode.ACTIVE);
    Host defaultHost = defaultHostSC.getValue();
    Assert.assertNotNull("Default host should exist", defaultHost);
    ServiceController<Server> defaultServerSC = (ServiceController<Server>) mainServices.getContainer().getService(UndertowService.DEFAULT_SERVER);
    defaultServerSC.setMode(ServiceController.Mode.ACTIVE);
    Server defaultServer = defaultServerSC.getValue();
    Assert.assertNotNull("Default host should exist", defaultServer);
    final ServiceName accessLogServiceName = UndertowService.accessLogServiceName("some-server", "default-host");
    ServiceController<AccessLogService> accessLogSC = (ServiceController<AccessLogService>) mainServices.getContainer().getService(accessLogServiceName);
    Assert.assertNotNull(accessLogSC);
    accessLogSC.setMode(ServiceController.Mode.ACTIVE);
    AccessLogService accessLogService = accessLogSC.getValue();
    Assert.assertNotNull(accessLogService);
    Assert.assertFalse(accessLogService.isRotate());
}
Also used : HttpHandler(io.undertow.server.HttpHandler) KernelServices(org.jboss.as.subsystem.test.KernelServices) FilterService(org.wildfly.extension.undertow.filters.FilterService) ArrayList(java.util.ArrayList) PathHandler(io.undertow.server.handlers.PathHandler) FilterRef(org.wildfly.extension.undertow.filters.FilterRef) ServiceName(org.jboss.msc.service.ServiceName) ServiceController(org.jboss.msc.service.ServiceController) KernelServicesBuilder(org.jboss.as.subsystem.test.KernelServicesBuilder) AbstractSubsystemBaseTest(org.jboss.as.subsystem.test.AbstractSubsystemBaseTest) Test(org.junit.Test)

Example 4 with PathHandler

use of io.undertow.server.handlers.PathHandler in project undertow by undertow-io.

the class ComplexSSLTestCase method complexSSLTestCase.

@Test
public void complexSSLTestCase() throws IOException, GeneralSecurityException, URISyntaxException, InterruptedException {
    final PathHandler pathHandler = new PathHandler();
    Path rootPath = Paths.get(FileHandlerTestCase.class.getResource("page.html").toURI()).getParent();
    final NameVirtualHostHandler virtualHostHandler = new NameVirtualHostHandler();
    HttpHandler root = virtualHostHandler;
    root = new SimpleErrorPageHandler(root);
    root = new CanonicalPathHandler(root);
    virtualHostHandler.addHost("default-host", pathHandler);
    virtualHostHandler.setDefaultHandler(pathHandler);
    pathHandler.addPrefixPath("/", new ResourceHandler(new PathResourceManager(rootPath, 10485760)).setDirectoryListingEnabled(true));
    DefaultServer.setRootHandler(root);
    DefaultServer.startSSLServer();
    TestHttpClient client = new TestHttpClient();
    client.setSSLContext(DefaultServer.getClientSSLContext());
    try {
        //get file list, this works
        HttpGet getFileList = new HttpGet(DefaultServer.getDefaultServerSSLAddress());
        HttpResponse resultList = client.execute(getFileList);
        Assert.assertEquals(StatusCodes.OK, resultList.getStatusLine().getStatusCode());
        String responseList = HttpClientUtils.readResponse(resultList);
        Assert.assertTrue(responseList, responseList.contains("page.html"));
        Header[] headersList = resultList.getHeaders("Content-Type");
        Assert.assertEquals("text/html; charset=UTF-8", headersList[0].getValue());
        //get file itself, breaks
        HttpGet getFile = new HttpGet(DefaultServer.getDefaultServerSSLAddress() + "/page.html");
        HttpResponse result = client.execute(getFile);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        String response = HttpClientUtils.readResponse(result);
        Header[] headers = result.getHeaders("Content-Type");
        Assert.assertEquals("text/html", headers[0].getValue());
        Assert.assertTrue(response, response.contains("A web page"));
    } finally {
        client.getConnectionManager().shutdown();
        DefaultServer.stopSSLServer();
    }
}
Also used : Path(java.nio.file.Path) HttpHandler(io.undertow.server.HttpHandler) CanonicalPathHandler(io.undertow.server.handlers.CanonicalPathHandler) HttpGet(org.apache.http.client.methods.HttpGet) CanonicalPathHandler(io.undertow.server.handlers.CanonicalPathHandler) PathHandler(io.undertow.server.handlers.PathHandler) FileHandlerTestCase(io.undertow.server.handlers.file.FileHandlerTestCase) HttpResponse(org.apache.http.HttpResponse) ResourceHandler(io.undertow.server.handlers.resource.ResourceHandler) NameVirtualHostHandler(io.undertow.server.handlers.NameVirtualHostHandler) PathResourceManager(io.undertow.server.handlers.resource.PathResourceManager) TestHttpClient(io.undertow.testutils.TestHttpClient) Header(org.apache.http.Header) SimpleErrorPageHandler(io.undertow.server.handlers.error.SimpleErrorPageHandler) Test(org.junit.Test)

Example 5 with PathHandler

use of io.undertow.server.handlers.PathHandler in project undertow by undertow-io.

the class SessionIdHandlingTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler pathHandler = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServlets(new ServletInfo("servlet", RequestedSessionIdServlet.class).addMapping("/session"));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    try {
        pathHandler.addPrefixPath(builder.getContextPath(), manager.start());
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
    DefaultServer.setRootHandler(pathHandler);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ServletException(javax.servlet.ServletException) 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)

Aggregations

PathHandler (io.undertow.server.handlers.PathHandler)92 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)58 ServletContainer (io.undertow.servlet.api.ServletContainer)58 DeploymentManager (io.undertow.servlet.api.DeploymentManager)57 ServletInfo (io.undertow.servlet.api.ServletInfo)49 BeforeClass (org.junit.BeforeClass)48 Test (org.junit.Test)30 TestHttpClient (io.undertow.testutils.TestHttpClient)28 HttpResponse (org.apache.http.HttpResponse)25 HttpGet (org.apache.http.client.methods.HttpGet)24 PathResourceManager (io.undertow.server.handlers.resource.PathResourceManager)22 CanonicalPathHandler (io.undertow.server.handlers.CanonicalPathHandler)21 ResourceHandler (io.undertow.server.handlers.resource.ResourceHandler)21 Path (java.nio.file.Path)21 SimpleServletTestCase (io.undertow.servlet.test.SimpleServletTestCase)17 HttpHandler (io.undertow.server.HttpHandler)15 FilterInfo (io.undertow.servlet.api.FilterInfo)14 LoginConfig (io.undertow.servlet.api.LoginConfig)12 Header (org.apache.http.Header)12 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)11