Search in sources :

Example 6 with DecompressingHttpClient

use of org.apache.http.impl.client.DecompressingHttpClient 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

DecompressingHttpClient (org.apache.http.impl.client.DecompressingHttpClient)6 HttpResponse (org.apache.http.HttpResponse)5 HttpGet (org.apache.http.client.methods.HttpGet)5 InputStream (java.io.InputStream)3 Test (org.junit.Test)3 TestHttpClient (io.undertow.testutils.TestHttpClient)2 IOException (java.io.IOException)2 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)2 SimpleClientCertificateKeyManager (com.fathomdb.crypto.SimpleClientCertificateKeyManager)1 PublicKeyTrustManager (com.fathomdb.crypto.ssl.PublicKeyTrustManager)1 Result (com.google.refine.importing.UrlRewriter.Result)1 ContentEncodingRepository (io.undertow.server.handlers.encoding.ContentEncodingRepository)1 DeflateEncodingProvider (io.undertow.server.handlers.encoding.DeflateEncodingProvider)1 EncodingHandler (io.undertow.server.handlers.encoding.EncodingHandler)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URL (java.net.URL)1