Code example for DefaultHttpClient

Methods: addRequestInterceptoraddResponseInterceptorsetHttpRequestRetryHandler

0
				.getSocketFactory(), 443));
		ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(
				httpParams, schemeRegistry);
 
		httpContext = new SyncBasicHttpContext(new BasicHttpContext());
		httpClient = new DefaultHttpClient(cm, httpParams);
		httpClient.addRequestInterceptor(new HttpRequestInterceptor()
		{ 
			@Override 
			public void process(HttpRequest request, HttpContext context)
			{ 
				if (!request.containsHeader(HEADER_ACCEPT_ENCODING))
				{ 
					request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
				} 
				for (String header : clientHeaderMap.keySet())
				{ 
					request.addHeader(header, clientHeaderMap.get(header));
				} 
			} 
		}); 
 
		httpClient.addResponseInterceptor(new HttpResponseInterceptor()
		{ 
			@Override 
			public void process(HttpResponse response, HttpContext context)
			{ 
				final HttpEntity entity = response.getEntity();
				if (entity == null)
				{ 
					return; 
				} 
				final Header encoding = entity.getContentEncoding();
				if (encoding != null)
				{ 
					for (HeaderElement element : encoding.getElements())
					{ 
						if (element.getName().equalsIgnoreCase(ENCODING_GZIP))
						{ 
							response.setEntity(new InflatingEntity(response
									.getEntity()));
							break; 
						} 
					} 
				} 
			} 
		}); 
 
		httpClient.setHttpRequestRetryHandler(new RetryHandler(
				DEFAULT_MAX_RETRIES));
 
		threadPool = new ThreadPoolExecutor(DEFAULT_CORE_POOL_SIZE,
				DEFAULT_MAXIMUM_POOL_SIZE, DEFAULT_KEEP_ALIVETIME,
				TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(3),
Stop searching for code, let great code find you!  Add Codota to your java IDE