List of usage examples for org.apache.http.impl.client ContentEncodingHttpClient ContentEncodingHttpClient
public ContentEncodingHttpClient()
From source file:com.teamlazerbeez.crm.sf.rest.FieldDescriptionTest.java
@BeforeClass public static void setUpClass() throws com.teamlazerbeez.crm.sf.soap.ApiException, MalformedURLException { ConnectionPool<Integer> repository = new ConnectionPoolImpl<Integer>("testPartnerKey"); repository.configureOrg(1, USER, PASSWD, 1); BindingConfig bindingConfig = repository.getConnectionBundle(1).getBindingConfig(); ObjectMapper objectMapper = new ObjectMapper(); conn = new RestConnectionImpl(objectMapper.reader(), new FixedHttpApiClientProvider( new HttpApiClient(new URL(bindingConfig.getPartnerServerUrl()).getHost(), bindingConfig.getSessionId(), objectMapper, new ContentEncodingHttpClient()))); }
From source file:com.teamlazerbeez.crm.sf.rest.RestConnectionImplTest.java
@BeforeClass public static void setUpClass() throws com.teamlazerbeez.crm.sf.soap.ApiException, MalformedURLException { ConnectionPool<Integer> repository = new ConnectionPoolImpl<Integer>("testPartnerKey"); repository.configureOrg(1, HttpApiClientTest.USER, HttpApiClientTest.PASSWORD, 1); BindingConfig bindingConfig = repository.getConnectionBundle(1).getBindingConfig(); ObjectMapper objectMapper = new ObjectMapper(); conn = new RestConnectionImpl(objectMapper.reader(), new FixedHttpApiClientProvider( new HttpApiClient(new URL(bindingConfig.getPartnerServerUrl()).getHost(), bindingConfig.getSessionId(), objectMapper, new ContentEncodingHttpClient()))); }
From source file:com.teamlazerbeez.crm.sf.rest.HttpApiClientTest.java
@BeforeClass public static void setUpClass() throws com.teamlazerbeez.crm.sf.soap.ApiException, MalformedURLException { ConnectionPool<Integer> repository = new ConnectionPoolImpl<Integer>("testPartnerKey"); repository.configureOrg(1, USER, PASSWORD, 1); BindingConfig bindingConfig = repository.getConnectionBundle(1).getBindingConfig(); String host = new URL(bindingConfig.getPartnerServerUrl()).getHost(); client = new HttpApiClient(host, bindingConfig.getSessionId(), MAPPER, new ContentEncodingHttpClient()); }
From source file:io.undertow.server.handlers.encoding.DeflateContentEncodingTestCase.java
/** * This message should not be compressed as it is too small * * @throws IOException/*from w ww.java 2 s.co m*/ */ @Test public void testSmallMessagePredicateDoesNotCompress() throws IOException { ContentEncodingHttpClient client = new ContentEncodingHttpClient(); try { message = "Hi"; HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path"); get.setHeader(Headers.ACCEPT_ENCODING_STRING, "deflate"); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); Header[] header = result.getHeaders(Headers.CONTENT_ENCODING_STRING); Assert.assertEquals(0, header.length); final String body = HttpClientUtils.readResponse(result); Assert.assertEquals("Hi", body); } finally { client.getConnectionManager().shutdown(); } }
From source file:io.undertow.server.handlers.encoding.GzipContentEncodingTestCase.java
/** * This message should not be compressed as it is too small * * @throws java.io.IOException// ww w .j a va2 s. com */ @Test public void testSmallMessagePredicateDoesNotCompress() throws IOException { ContentEncodingHttpClient client = new ContentEncodingHttpClient(); try { message = "Hi"; HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path"); get.setHeader(Headers.ACCEPT_ENCODING_STRING, "gzip"); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); Header[] header = result.getHeaders(Headers.CONTENT_ENCODING_STRING); Assert.assertEquals(0, header.length); final String body = HttpClientUtils.readResponse(result); Assert.assertEquals("Hi", body); } finally { client.getConnectionManager().shutdown(); } }
From source file:io.undertow.server.handlers.file.ContentEncodedResourceTestCase.java
@Test public void testFileIsCompressed() throws IOException, InterruptedException { ContentEncodingHttpClient client = new ContentEncodingHttpClient(); String fileName = "hello.html"; Path f = tmpDir.resolve(fileName); Files.write(f, "hello world".getBytes()); try {// w ww .j a v a2 s . c om for (int i = 0; i < 3; ++i) { HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/" + fileName); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); String response = HttpClientUtils.readResponse(result); Assert.assertEquals("hello world", response); Assert.assertEquals("deflate", result.getHeaders(Headers.CONTENT_ENCODING_STRING)[0].getValue()); } Files.write(f, "modified file".getBytes()); //if it is serving a cached compressed version what is being served will not change HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/" + fileName); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); String response = HttpClientUtils.readResponse(result); Assert.assertEquals("hello world", response); Assert.assertEquals("deflate", result.getHeaders(Headers.CONTENT_ENCODING_STRING)[0].getValue()); } finally { client.getConnectionManager().shutdown(); } }
From source file:io.undertow.server.handlers.file.PreCompressedResourceTestCase.java
@Test public void testContentEncodedResource() throws IOException, URISyntaxException { TestHttpClient client = new TestHttpClient(); Path rootPath = Paths.get(getClass().getResource("page.html").toURI()).getParent(); try {//from w w w. ja va 2 s .c om DefaultServer .setRootHandler( new CanonicalPathHandler().setNext(new PathHandler().addPrefixPath("/path", new ResourceHandler(new PreCompressedResourceSupplier( new PathResourceManager(rootPath, 10485760)).addEncoding("gzip", ".gz")) .setDirectoryListingEnabled(true)))); HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path/page.html"); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); final String nonCompressedResource = HttpClientUtils.readResponse(result); Header[] headers = result.getHeaders(Headers.CONTENT_TYPE_STRING); Assert.assertEquals("text/html", headers[0].getValue()); Assert.assertTrue(nonCompressedResource, nonCompressedResource.contains("A web page")); Assert.assertNull(result.getFirstHeader(Headers.CONTENT_ENCODING_STRING)); ContentEncodingHttpClient compClient = new ContentEncodingHttpClient(); result = compClient.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); final String compressedResource = HttpClientUtils.readResponse(result); headers = result.getHeaders(Headers.CONTENT_TYPE_STRING); Assert.assertEquals("text/html", headers[0].getValue()); Assert.assertEquals(nonCompressedResource, compressedResource); Assert.assertEquals("gzip", result.getFirstHeader(Headers.CONTENT_ENCODING_STRING).getValue()); } finally { client.getConnectionManager().shutdown(); } }
From source file:io.undertow.server.handlers.encoding.GzipContentEncodingTestCase.java
@Test public void testAcceptIdentity() throws IOException { ContentEncodingHttpClient client = new ContentEncodingHttpClient(); try {//ww w . j a v a2 s . com message = "Hi"; HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path"); get.setHeader(Headers.ACCEPT_ENCODING_STRING, "identity;q=1, *;q=0"); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); Header[] header = result.getHeaders(Headers.CONTENT_ENCODING_STRING); Assert.assertEquals(1, header.length); Assert.assertEquals("identity", header[0].getValue()); final String body = HttpClientUtils.readResponse(result); Assert.assertEquals("Hi", body); } finally { client.getConnectionManager().shutdown(); } }
From source file:org.eclipse.mylyn.commons.repositories.http.tests.HttpUtilTest.java
@Test public void testGetEmptyGzipResponse() throws Exception { client = new ContentEncodingHttpClient() { @Override// w ww .j av a 2 s. com protected ClientConnectionManager createClientConnectionManager() { return connectionManager; } }; Message message = new Message("HTTP/1.1 200 OK"); message.headers.add("Content-Length: 0"); message.headers.add("Content-Encoding: gzip"); message.headers.add("Connection: close"); testProxy.addResponse(message); HttpRequestBase request = new HttpGet(testProxy.getUrl()); HttpUtil.configureClient(client, null); HttpResponse response = HttpUtil.execute(client, null, request, null); assertEquals(1, connectionManager.getConnectionsInPool()); HttpUtil.release(request, response, null); assertEquals(0, connectionManager.getConnectionsInPool()); }
From source file:io.undertow.server.handlers.encoding.DeflateContentEncodingTestCase.java
public void runTest(final String theMessage) throws IOException { ContentEncodingHttpClient client = new ContentEncodingHttpClient(); try {//from ww w .j av a 2s .c o m message = theMessage; HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path"); get.setHeader(Headers.ACCEPT_ENCODING_STRING, "deflate"); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); Header[] header = result.getHeaders(Headers.CONTENT_ENCODING_STRING); Assert.assertEquals("deflate", header[0].getValue()); final String body = HttpClientUtils.readResponse(result); Assert.assertEquals(theMessage, body); } finally { client.getConnectionManager().shutdown(); } }