Search in sources :

Example 1 with EncodingHandler

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

the class LoadBalancingProxyTestCase method setup.

@BeforeClass
public static void setup() throws URISyntaxException {
    int port = DefaultServer.getHostPort("default");
    server1 = Undertow.builder().addHttpListener(port + 1, DefaultServer.getHostAddress("default")).setSocketOption(Options.REUSE_ADDRESSES, true).setServerOption(UndertowOptions.NO_REQUEST_TIMEOUT, IDLE_TIMEOUT).setHandler(getRootHandler("s1", "server1")).build();
    server2 = Undertow.builder().addHttpListener(port + 2, DefaultServer.getHostAddress("default")).setSocketOption(Options.REUSE_ADDRESSES, true).setServerOption(UndertowOptions.NO_REQUEST_TIMEOUT, IDLE_TIMEOUT).setHandler(getRootHandler("s2", "server2")).build();
    server1.start();
    server2.start();
    ProxyHandler handler = new ProxyHandler(new LoadBalancingProxyClient().setConnectionsPerThread(4).addHost(new URI("http", null, DefaultServer.getHostAddress("default"), port + 1, null, null, null), "s1").addHost(new URI("http", null, DefaultServer.getHostAddress("default"), port + 2, null, null, null), "s2"), 10000, ResponseCodeHandler.HANDLE_404, false, false, 2);
    DefaultServer.setRootHandler(new EncodingHandler(handler, new ContentEncodingRepository().addEncodingHandler("gzip", new GzipEncodingProvider(), 50, Predicates.truePredicate())));
}
Also used : ContentEncodingRepository(io.undertow.server.handlers.encoding.ContentEncodingRepository) EncodingHandler(io.undertow.server.handlers.encoding.EncodingHandler) URI(java.net.URI) GzipEncodingProvider(io.undertow.server.handlers.encoding.GzipEncodingProvider) BeforeClass(org.junit.BeforeClass)

Example 2 with EncodingHandler

use of io.undertow.server.handlers.encoding.EncodingHandler in project spring-boot by spring-projects.

the class UndertowServletWebServer method configurationCompressionIfNecessary.

private HttpHandler configurationCompressionIfNecessary(HttpHandler httpHandler) {
    if (this.compression == null || !this.compression.getEnabled()) {
        return httpHandler;
    }
    ContentEncodingRepository repository = new ContentEncodingRepository();
    repository.addEncodingHandler("gzip", new GzipEncodingProvider(), 50, Predicates.and(getCompressionPredicates(this.compression)));
    return new EncodingHandler(repository).setNext(httpHandler);
}
Also used : ContentEncodingRepository(io.undertow.server.handlers.encoding.ContentEncodingRepository) EncodingHandler(io.undertow.server.handlers.encoding.EncodingHandler) GzipEncodingProvider(io.undertow.server.handlers.encoding.GzipEncodingProvider)

Example 3 with EncodingHandler

use of io.undertow.server.handlers.encoding.EncodingHandler 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)

Example 4 with EncodingHandler

use of io.undertow.server.handlers.encoding.EncodingHandler in project wildfly by wildfly.

the class GzipFilter method createHttpHandler.

@Override
public HttpHandler createHttpHandler(final Predicate predicate, ModelNode model, HttpHandler next) {
    EncodingHandler encodingHandler = new EncodingHandler(new ContentEncodingRepository().addEncodingHandler("gzip", new GzipEncodingProvider(), 50, predicate != null ? predicate : Predicates.truePredicate()));
    encodingHandler.setNext(next);
    return encodingHandler;
}
Also used : ContentEncodingRepository(io.undertow.server.handlers.encoding.ContentEncodingRepository) EncodingHandler(io.undertow.server.handlers.encoding.EncodingHandler) GzipEncodingProvider(io.undertow.server.handlers.encoding.GzipEncodingProvider)

Aggregations

ContentEncodingRepository (io.undertow.server.handlers.encoding.ContentEncodingRepository)4 EncodingHandler (io.undertow.server.handlers.encoding.EncodingHandler)4 GzipEncodingProvider (io.undertow.server.handlers.encoding.GzipEncodingProvider)3 DeflateEncodingProvider (io.undertow.server.handlers.encoding.DeflateEncodingProvider)1 TestHttpClient (io.undertow.testutils.TestHttpClient)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)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