List of usage examples for org.apache.http.impl.client DecompressingHttpClient execute
public HttpResponse execute(final HttpUriRequest request) throws IOException, ClientProtocolException
From source file:org.n52.wps.server.request.strategy.LazyHttpInputStream.java
/** * Make a GET request using mimeType and href * //from w w w . j a v a 2 s . co m * TODO: add support for autoretry, proxy */ private static InputStream httpGet(final String dataURLString, final String mimeType) throws IOException { HttpClient backend = new DefaultHttpClient(); DecompressingHttpClient httpclient = new DecompressingHttpClient(backend); HttpGet httpget = new HttpGet(dataURLString); if (mimeType != null) { httpget.addHeader(new BasicHeader("Content-type", mimeType)); } HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); return entity.getContent(); }
From source file:org.n52.wps.server.request.strategy.LazyHttpInputStream.java
/** * Make a POST request using mimeType and href * // w ww.j a v a 2 s .c o m * TODO: add support for autoretry, proxy */ private static InputStream httpPost(final String dataURLString, final String body, final String mimeType) throws IOException { HttpClient backend = new DefaultHttpClient(); DecompressingHttpClient httpclient = new DecompressingHttpClient(backend); HttpPost httppost = new HttpPost(dataURLString); if (mimeType != null) { httppost.addHeader(new BasicHeader("Content-type", mimeType)); } // set body entity HttpEntity postEntity = new StringEntity(body); httppost.setEntity(postEntity); HttpResponse response = httpclient.execute(httppost); HttpEntity resultEntity = response.getEntity(); return resultEntity.getContent(); }
From source file:org.n52.wps.server.request.strategy.DefaultReferenceStrategy.java
/** * Make a GET request using mimeType and href * /*from www . ja v a 2s.c om*/ * TODO: add support for autoretry, proxy */ private ReferenceInputStream httpGet(final String dataURLString, final String mimeType) throws IOException { HttpClient backend = new DefaultHttpClient(); DecompressingHttpClient httpclient = new DecompressingHttpClient(backend); HttpGet httpget = new HttpGet(dataURLString); if (mimeType != null) { httpget.addHeader(new BasicHeader("Content-type", mimeType)); } return processResponse(httpclient.execute(httpget)); }
From source file:io.undertow.server.handlers.proxy.AbstractLoadBalancingProxyTestCase.java
@Test public void testLoadShared() throws IOException { final StringBuilder resultString = new StringBuilder(); for (int i = 0; i < 6; ++i) { DecompressingHttpClient client = new DecompressingHttpClient(new TestHttpClient()); try {/*from w w w.j av a 2 s .co m*/ HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/name"); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); resultString.append(HttpClientUtils.readResponse(result)); resultString.append(' '); } finally { client.getConnectionManager().shutdown(); } } Assert.assertTrue(resultString.toString().contains("server1")); Assert.assertTrue(resultString.toString().contains("server2")); }
From source file:org.n52.wps.server.request.strategy.DefaultReferenceStrategy.java
/** * Make a POST request using mimeType and href * /* w w w . ja va2s. c om*/ * TODO: add support for autoretry, proxy */ private ReferenceInputStream httpPost(final String dataURLString, final String body, final String mimeType) throws IOException { HttpClient backend = new DefaultHttpClient(); DecompressingHttpClient httpclient = new DecompressingHttpClient(backend); HttpPost httppost = new HttpPost(dataURLString); if (mimeType != null) { httppost.addHeader(new BasicHeader("Content-type", mimeType)); } // set body entity HttpEntity postEntity = new StringEntity(body); httppost.setEntity(postEntity); return processResponse(httpclient.execute(httppost)); }
From source file:io.undertow.server.handlers.sse.ServerSentEventTestCase.java
@Test public void testProgressiveSSEWithCompression() throws IOException { final AtomicReference<ServerSentEventConnection> connectionReference = new AtomicReference<>(); DecompressingHttpClient client = new DecompressingHttpClient(new TestHttpClient()); try {/*w w w . j a va 2 s . c o m*/ 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(); } }