Search in sources :

Example 6 with SecureRandomSessionIdGenerator

use of io.undertow.server.session.SecureRandomSessionIdGenerator in project undertow by undertow-io.

the class DefaultServletCachingTestCase method testFileExistanceCheckCached.

@Test
public void testFileExistanceCheckCached() throws IOException, InterruptedException {
    TestHttpClient client = new TestHttpClient();
    String fileName = new SecureRandomSessionIdGenerator().createSessionId() + ".html";
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/" + fileName);
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.NOT_FOUND, result.getStatusLine().getStatusCode());
        HttpClientUtils.readResponse(result);
        Path f = tmpDir.resolve(fileName);
        Files.write(f, "hello".getBytes());
        get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/" + fileName);
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.NOT_FOUND, result.getStatusLine().getStatusCode());
        HttpClientUtils.readResponse(result);
        Thread.sleep(METADATA_MAX_AGE);
        get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/" + fileName);
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        String response = HttpClientUtils.readResponse(result);
        Assert.assertEquals("hello", response);
        Files.delete(f);
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : Path(java.nio.file.Path) SecureRandomSessionIdGenerator(io.undertow.server.session.SecureRandomSessionIdGenerator) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Aggregations

SecureRandomSessionIdGenerator (io.undertow.server.session.SecureRandomSessionIdGenerator)6 CookieImpl (io.undertow.server.handlers.CookieImpl)2 TestHttpClient (io.undertow.testutils.TestHttpClient)2 Path (java.nio.file.Path)2 HttpResponse (org.apache.http.HttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 Test (org.junit.Test)2 AuthenticationCallHandler (io.undertow.security.handlers.AuthenticationCallHandler)1 AuthenticationConstraintHandler (io.undertow.security.handlers.AuthenticationConstraintHandler)1 HandlerWrapper (io.undertow.server.HandlerWrapper)1 HttpHandler (io.undertow.server.HttpHandler)1 Cookie (io.undertow.server.handlers.Cookie)1 PathHandler (io.undertow.server.handlers.PathHandler)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 ServletSessionConfig (io.undertow.servlet.api.ServletSessionConfig)1 ThreadSetupHandler (io.undertow.servlet.api.ThreadSetupHandler)1 StatusCodes (io.undertow.util.StatusCodes)1 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1