List of usage examples for org.apache.http.client HttpClient getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.artifactory.util.HttpClientUtils.java
private static RequestConfig getDefaultConfig(HttpClient client) { if (client == null) { return null; }/*from w ww .j a va 2 s . c o m*/ try { HttpClient httpClient = extractCloseableHttpClient(client); Field requestConfigField = httpClient.getClass().getDeclaredField("defaultConfig"); requestConfigField.setAccessible(true); return (RequestConfig) ReflectionUtils.getField(requestConfigField, httpClient); } catch (NoSuchFieldException e) { throw new IllegalStateException("Failed to get default request config", e); } }
From source file:com.android.fastergallery.common.HttpClientFactory.java
/** * Closes an HttpClient./*from w w w . j a v a 2 s . co m*/ */ public static void close(HttpClient client) { // AndroidHttpClient is available on all platform releases, // but is hidden until API Level 8 try { Class<?> clazz = client.getClass(); Method method = clazz.getMethod("close", (Class<?>[]) null); method.invoke(client, (Object[]) null); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }
From source file:lucee.commons.net.http.httpclient4.HTTPEngine4Impl.java
public static HttpResponse execute(HttpClient client, HttpUriRequest req, HttpContext context) throws ClientProtocolException, IOException { try {//w w w. ja v a 2 s . c o m Method exe = client.getClass().getMethod("execute", new Class[] { HttpUriRequest.class, HttpContext.class }); return (HttpResponse) exe.invoke(client, new Object[] { req, context }); } catch (InvocationTargetException ite) { Throwable t = ite.getTargetException(); if (t instanceof IOException) throw (IOException) t; if (t instanceof ClientProtocolException) throw (ClientProtocolException) t; throw new RuntimeException(t); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.microsoft.applicationinsights.internal.channel.common.ApacheSender42Test.java
@Test public void testHttpClientType() { HttpClient tested = new ApacheSender42().getHttpClient(); assertNotNull(tested);/*w ww.j av a 2s . c om*/ assertEquals(tested.getClass(), DefaultHttpClient.class); }
From source file:org.graphity.core.util.jena.HttpOp.java
private static AbstractHttpClient asAbstractClient(HttpClient client) { if (AbstractHttpClient.class.isAssignableFrom(client.getClass())) { return (AbstractHttpClient) client; }/*from www.j a va 2s .c o m*/ return null; }
From source file:org.springframework.cloud.config.server.environment.HttpClientConfigurableHttpConnectionFactoryTest.java
private HttpClientBuilder getActualHttpClientBuilder(HttpConnection actualConnection) { HttpClient actualHttpClient = getActualHttpClient(actualConnection); Field closeablesField = ReflectionUtils.findField(actualHttpClient.getClass(), "closeables"); ReflectionUtils.makeAccessible(closeablesField); List<?> closables = (List<?>) ReflectionUtils.getField(closeablesField, actualHttpClient); return closables.stream().map(o -> { Field builderField = Arrays.stream(o.getClass().getDeclaredFields()) .filter(field -> HttpClientBuilder.class.isAssignableFrom(field.getType())).findFirst() .orElse(null);/*from w w w . ja v a 2 s.c o m*/ if (builderField != null) { ReflectionUtils.makeAccessible(builderField); return ReflectionUtils.getField(builderField, o); } return null; }).filter(Objects::nonNull).map(HttpClientBuilder.class::cast).findFirst().get(); }
From source file:anhttpclient.impl.DefaultWebBrowser.java
private void addGZIPResponseInterceptor(HttpClient httpClient) { if (AbstractHttpClient.class.isAssignableFrom(httpClient.getClass())) { ((AbstractHttpClient) httpClient).addResponseInterceptor(new HttpResponseInterceptor() { public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { HttpEntity entity = response.getEntity(); if (entity == null) { return; }/*from w ww . ja v a2 s.c o m*/ Header contentEncodingHeader = entity.getContentEncoding(); if (contentEncodingHeader != null) { HeaderElement[] codecs = contentEncodingHeader.getElements(); for (HeaderElement codec : codecs) { if (codec.getName().equalsIgnoreCase(HttpConstants.GZIP)) { response.setEntity(new GzipDecompressingEntity(response.getEntity())); return; } } } } }); } }
From source file:com.pongme.utils.ImageDownloader.java
Bitmap downloadBitmap(String url, int width, int height) { // final int IO_BUFFER_SIZE = 4 * 1024; // AndroidHttpClient is not allowed to be used from the main thread HttpClient client = null; HttpGet getRequest = null;/*from w w w .j a v a 2s. c o m*/ try { getRequest = new HttpGet(url); client = getHttpClient(); HttpResponse response = client.execute(getRequest); final int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { Log.w("ImageDownloader", "Error " + statusCode + " while retrieving bitmap from " + url); return null; } final HttpEntity entity = response.getEntity(); if (entity != null) { String md5 = Utils.md5(url); File outputFile = sFileCache.getCachedFile(md5); FileOutputStream stream = new FileOutputStream(outputFile); entity.writeTo(stream); stream.close(); Bitmap res = getBitmapFromFile(outputFile, width, height); if (res != null) { synchronized (sFileCache) { sFileCache.put(url, md5); saveCache(); } } return res; } } catch (IOException e) { if (getRequest != null) getRequest.abort(); Log.w(LOG_TAG, "I/O error while retrieving bitmap from " + url, e); } catch (IllegalStateException e) { if (getRequest != null) getRequest.abort(); Log.w(LOG_TAG, "Incorrect URL: " + url); } catch (Exception e) { if (getRequest != null) getRequest.abort(); Log.w(LOG_TAG, "Error while retrieving bitmap from " + url, e); } finally { if (client == null) { return null; } if (ANDROID_CLIENT_CLASS != null && ANDROID_CLIENT_CLASS.isAssignableFrom(client.getClass())) { try { ANDROID_CLIENT_CLOSE.invoke(client); } catch (Exception e) { } } } return null; }