Search in sources :

Example 1 with StoredResponseHandler

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

the class AccessLogTestCase method testRemoteAddress.

@Test
public void testRemoteAddress() throws IOException, InterruptedException {
    latch = new CountDownLatch(1);
    DefaultServer.setRootHandler(new StoredResponseHandler(new AccessLogHandler(HELLO_HANDLER, RECEIVER, "Remote address %a Code %s test-header %{i,test-header} %{STORED_RESPONSE}", AccessLogFileTestCase.class.getClassLoader())));
    TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
        get.addHeader("test-header", "test-value");
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals("HelloResponse", HttpClientUtils.readResponse(result));
        latch.await(10, TimeUnit.SECONDS);
        Assert.assertEquals("Remote address " + DefaultServer.getDefaultServerAddress().getAddress().getHostAddress() + " Code 200 test-header test-value HelloResponse", message);
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : StoredResponseHandler(io.undertow.server.handlers.StoredResponseHandler) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) CountDownLatch(java.util.concurrent.CountDownLatch) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Aggregations

StoredResponseHandler (io.undertow.server.handlers.StoredResponseHandler)1 TestHttpClient (io.undertow.testutils.TestHttpClient)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 HttpResponse (org.apache.http.HttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 Test (org.junit.Test)1