Search in sources :

Example 1 with DeflateEncodingProvider

use of io.undertow.server.handlers.encoding.DeflateEncodingProvider in project undertow by undertow-io.

the class ContentEncodedResourceTestCase method setup.

@BeforeClass
public static void setup() throws IOException {
    tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), DIR_NAME);
    final PathResourceManager resourceManager = new PathResourceManager(tmpDir, 10485760);
    DefaultServer.setRootHandler(new ResourceHandler(resourceManager).setContentEncodedResourceManager(new ContentEncodedResourceManager(tmpDir, new CachingResourceManager(100, 10000, null, resourceManager, -1), new ContentEncodingRepository().addEncodingHandler("deflate", new DeflateEncodingProvider(), 50, null), 0, 100000, null)));
}
Also used : ContentEncodedResourceManager(io.undertow.server.handlers.encoding.ContentEncodedResourceManager) DeflateEncodingProvider(io.undertow.server.handlers.encoding.DeflateEncodingProvider) ContentEncodingRepository(io.undertow.server.handlers.encoding.ContentEncodingRepository) ResourceHandler(io.undertow.server.handlers.resource.ResourceHandler) CachingResourceManager(io.undertow.server.handlers.resource.CachingResourceManager) PathResourceManager(io.undertow.server.handlers.resource.PathResourceManager) BeforeClass(org.junit.BeforeClass)

Example 2 with DeflateEncodingProvider

use of io.undertow.server.handlers.encoding.DeflateEncodingProvider in project undertow by undertow-io.

the class ServerSentEventTestCase method testProgressiveSSEWithCompression.

@Test
public void testProgressiveSSEWithCompression() throws IOException {
    final AtomicReference<ServerSentEventConnection> connectionReference = new AtomicReference<>();
    DecompressingHttpClient client = new DecompressingHttpClient(new TestHttpClient());
    try {
        DefaultServer.setRootHandler(new EncodingHandler(new ContentEncodingRepository().addEncodingHandler("deflate", new DeflateEncodingProvider(), 50)).setNext(new ServerSentEventHandler(new ServerSentEventConnectionCallback() {

            @Override
            public void connected(ServerSentEventConnection connection, String lastEventId) {
                connectionReference.set(connection);
                connection.send("msg 1", new ServerSentEventConnection.EventCallback() {

                    @Override
                    public void done(ServerSentEventConnection connection, String data, String event, String id) {
                    }

                    @Override
                    public void failed(ServerSentEventConnection connection, String data, String event, String id, IOException e) {
                        e.printStackTrace();
                        IoUtils.safeClose(connection);
                    }
                });
            }
        })));
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/");
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        InputStream stream = result.getEntity().getContent();
        assertData(stream, "data:msg 1\n\n");
        connectionReference.get().send("msg 2");
        assertData(stream, "data:msg 2\n\n");
        connectionReference.get().close();
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : DeflateEncodingProvider(io.undertow.server.handlers.encoding.DeflateEncodingProvider) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) ContentEncodingRepository(io.undertow.server.handlers.encoding.ContentEncodingRepository) HttpResponse(org.apache.http.HttpResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) EncodingHandler(io.undertow.server.handlers.encoding.EncodingHandler) IOException(java.io.IOException) DecompressingHttpClient(org.apache.http.impl.client.DecompressingHttpClient) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Aggregations

ContentEncodingRepository (io.undertow.server.handlers.encoding.ContentEncodingRepository)2 DeflateEncodingProvider (io.undertow.server.handlers.encoding.DeflateEncodingProvider)2 ContentEncodedResourceManager (io.undertow.server.handlers.encoding.ContentEncodedResourceManager)1 EncodingHandler (io.undertow.server.handlers.encoding.EncodingHandler)1 CachingResourceManager (io.undertow.server.handlers.resource.CachingResourceManager)1 PathResourceManager (io.undertow.server.handlers.resource.PathResourceManager)1 ResourceHandler (io.undertow.server.handlers.resource.ResourceHandler)1 TestHttpClient (io.undertow.testutils.TestHttpClient)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 HttpResponse (org.apache.http.HttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 DecompressingHttpClient (org.apache.http.impl.client.DecompressingHttpClient)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1