Search in sources :

Example 1 with SimpleErrorPageHandler

use of io.undertow.server.handlers.error.SimpleErrorPageHandler 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 2 with SimpleErrorPageHandler

use of io.undertow.server.handlers.error.SimpleErrorPageHandler in project wildfly by wildfly.

the class Server method start.

@Override
public void start(StartContext startContext) throws StartException {
    root = virtualHostHandler;
    root = new SimpleErrorPageHandler(root);
    root = new CanonicalPathHandler(root);
    root = new DefaultHostHandler(root);
    UndertowLogger.ROOT_LOGGER.startedServer(name);
    undertowService.getValue().registerServer(this);
}
Also used : CanonicalPathHandler(io.undertow.server.handlers.CanonicalPathHandler) SimpleErrorPageHandler(io.undertow.server.handlers.error.SimpleErrorPageHandler)

Aggregations

CanonicalPathHandler (io.undertow.server.handlers.CanonicalPathHandler)2 SimpleErrorPageHandler (io.undertow.server.handlers.error.SimpleErrorPageHandler)2 HttpHandler (io.undertow.server.HttpHandler)1 NameVirtualHostHandler (io.undertow.server.handlers.NameVirtualHostHandler)1 PathHandler (io.undertow.server.handlers.PathHandler)1 FileHandlerTestCase (io.undertow.server.handlers.file.FileHandlerTestCase)1 PathResourceManager (io.undertow.server.handlers.resource.PathResourceManager)1 ResourceHandler (io.undertow.server.handlers.resource.ResourceHandler)1 TestHttpClient (io.undertow.testutils.TestHttpClient)1 Path (java.nio.file.Path)1 Header (org.apache.http.Header)1 HttpResponse (org.apache.http.HttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 Test (org.junit.Test)1