List of usage examples for org.apache.http.client.protocol ResponseContentEncoding ResponseContentEncoding
ResponseContentEncoding
From source file:com.arcbees.vcs.util.HttpClientWrapperImpl.java
private CloseableHttpClient initHttpClient() { RequestConfig requestConfig = getRequestConfig(); String serverVersion = ServerVersionHolder.getVersion().getDisplayVersion(); connectionManager = new PoolingHttpClientConnectionManager(); return HttpClientBuilder.create().useSystemProperties().addInterceptorFirst(new RequestAcceptEncoding()) .addInterceptorFirst(new ResponseContentEncoding()) .setRetryHandler(new DefaultHttpRequestRetryHandler(RETRY_COUNT, true)) .setConnectionManager(connectionManager).setDefaultRequestConfig(requestConfig) .setUserAgent("JetBrains TeamCity " + serverVersion).build(); }
From source file:com.eviware.soapui.impl.wsdl.support.CompressionSupport.java
public static byte[] decompress(String alg, byte[] content) throws Exception { // Use the excellent content encoding handling that exists in HTTP Client HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new HttpVersion(1, 0), 0, null)); ByteArrayEntity entity = new ByteArrayEntity(content); entity.setContentEncoding(alg);//from www .ja v a 2 s . c o m response.setEntity(entity); new ResponseContentEncoding().process(response, null); return IOUtils.toByteArray(response.getEntity().getContent()); }
From source file:org.iglootools.hchelpers.core.DefaultHttpClientFactory.java
private static void handleGzipContentCompression(DefaultHttpClient httpClient) { httpClient.addRequestInterceptor(new RequestAcceptEncoding()); httpClient.addResponseInterceptor(new ResponseContentEncoding()); }
From source file:net.oneandone.shared.artifactory.ArtifactoryModule.java
@Provides @Named(value = "httpclient") HttpClient provideHttpClient() {/* www .j av a 2 s .co m*/ final DefaultHttpClient client = new DefaultHttpClient(); client.addRequestInterceptor(new RequestAcceptEncoding()); client.addResponseInterceptor(new ResponseContentEncoding()); client.addRequestInterceptor(providePreemptiveRequestInterceptor()); return client; }
From source file:org.sonatype.nexus.apachehttpclient.Hc4ProviderBase.java
protected Builder prepareHttpClient(final RemoteStorageContext context, final HttpClientConnectionManager httpClientConnectionManager) { final Builder builder = new Builder(); builder.getHttpClientBuilder().setConnectionManager(httpClientConnectionManager); builder.getHttpClientBuilder().addInterceptorFirst(new ResponseContentEncoding()); applyConfig(builder, context);/*from ww w .j av a2s. com*/ applyAuthenticationConfig(builder, context.getRemoteAuthenticationSettings(), null); applyProxyConfig(builder, context.getRemoteProxySettings()); // obey the given retries count and apply it to client. final int retries = context.getRemoteConnectionSettings() != null ? context.getRemoteConnectionSettings().getRetrievalRetryCount() : 0; builder.getHttpClientBuilder().setRetryHandler(new StandardHttpRequestRetryHandler(retries, false)); builder.getHttpClientBuilder() .setKeepAliveStrategy(new NexusConnectionKeepAliveStrategy(getKeepAliveMaxDuration())); return builder; }
From source file:com.cxic.ip.WebUrl.java
public String getResponseStr() { String userAgentCopy = VersionInfo.getUserAgent("Apache-HttpClient", "org.apache.http.client", getClass()); HttpProcessor httpprocessorCopy = null; if (httpprocessorCopy == null) { final HttpProcessorBuilder b = HttpProcessorBuilder.create(); b.addAll(new RequestDefaultHeaders(null), new RequestContent(), new RequestTargetHost(), // new RequestClientConnControl(), new RequestUserAgent(userAgentCopy), new RequestExpectContinue()); b.add(new RequestAddCookies()); b.add(new RequestAcceptEncoding()); b.add(new RequestAuthCache()); b.add(new ResponseProcessCookies()); b.add(new ResponseContentEncoding()); httpprocessorCopy = b.build();/*from w ww . ja v a 2s .co m*/ } HttpHost proxy = new HttpHost(ip, port, "http"); // DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); CloseableHttpClient httpclient = HttpClients.custom() // .setRoutePlanner(routePlanner) .setProxy(proxy).setHttpProcessor(httpprocessorCopy).build(); String r = ""; HttpGet httpGet = new HttpGet(url); // httpGet.setHeader("GET http://www.stilllistener.com/checkpoint1/test2/ HTTP/1.1",""); // httpGet.setHeader("Host","www.stilllistener.com"); // httpGet.setHeader("User-Agent","Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0"); // httpGet.setHeader("User-Agent","Baiduspider+(+http://www.baidu.com/search/spider.htm)"); // httpGet.setHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); // httpGet.setHeader("Accept-Language","zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3"); // httpGet.setHeader("Accept-Encoding","gzip, deflate"); // httpGet.setHeader("Referer",url); // httpGet.setHeader("Connection","keep-alive"); // httpGet.setHeader("Cache-Control","max-age=0"); CloseableHttpResponse response1 = null; try { response1 = httpclient.execute(httpGet); HttpEntity entity1 = response1.getEntity(); String line = response1.getStatusLine().getReasonPhrase(); // System.out.println(line); if (line.equals("OK")) { r = EntityUtils.toString(entity1); // System.out.println(r); // do something useful with the response body // and ensure it is fully consumed // InputStream in = entity1.getContent(); // System.out.println(EntityUtils.toString(entity1,"GB2312")); //System.out.println(in.toString()); } // do something useful with the response body // and ensure it is fully consumed // InputStream in = entity1.getContent(); // System.out.println(EntityUtils.toString(entity1,"GB2312")); //System.out.println(in.toString()); //System.out.println(EntityUtils.toString(entity1)); EntityUtils.consume(entity1); response1.close(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return r; }
From source file:org.sonatype.nexus.proxy.storage.remote.httpclient.HttpClientUtil.java
/** * Creates and prepares an http client instance by using configuration present in {@link RemoteStorageContext}. * <p/>/*from w w w. jav a 2s . c o m*/ * This implies:<br/> * * setting up connection pool using number of connections specified by system property * {@link #CONNECTION_POOL_SIZE_KEY}<br/> * * setting timeout as configured for repository<br/> * * (if necessary) configure authentication<br/> * * (if necessary) configure proxy as configured for repository * * @param ctxPrefix context keys prefix * @param ctx remote repository context * @param logger logger */ static void configure(final String ctxPrefix, final RemoteStorageContext ctx, final Logger logger) { final DefaultHttpClient httpClient = new DefaultHttpClient(createConnectionManager(), createHttpParams(ctx)) { @Override protected BasicHttpProcessor createHttpProcessor() { final BasicHttpProcessor result = super.createHttpProcessor(); result.addResponseInterceptor(new ResponseContentEncoding()); return result; } }; ctx.putContextObject(ctxPrefix + CTX_KEY_CLIENT, httpClient); configureAuthentication(httpClient, ctxPrefix, ctx, ctx.getRemoteAuthenticationSettings(), logger, ""); configureProxy(httpClient, ctxPrefix, ctx, logger); // NEXUS-3338: we don't know after config change is remote S3 (url changed maybe) ctx.putContextObject(ctxPrefix + CTX_KEY_S3_FLAG, new BooleanFlagHolder()); }
From source file:jetbrains.teamcilty.github.api.impl.HttpClientWrapperImpl.java
public HttpClientWrapperImpl() throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { final String serverVersion = ServerVersionHolder.getVersion().getDisplayVersion(); final HttpParams ps = new BasicHttpParams(); DefaultHttpClient.setDefaultHttpParams(ps); final int timeout = TeamCityProperties.getInteger("teamcity.github.http.timeout", 300 * 1000); HttpConnectionParams.setConnectionTimeout(ps, timeout); HttpConnectionParams.setSoTimeout(ps, timeout); HttpProtocolParams.setUserAgent(ps, "JetBrains TeamCity " + serverVersion); final SchemeRegistry schemaRegistry = SchemeRegistryFactory.createDefault(); final SSLSocketFactory sslSocketFactory = new SSLSocketFactory(new TrustStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return !TeamCityProperties.getBoolean("teamcity.github.verify.ssl.certificate"); }//from w w w . jav a2 s .c o m }); schemaRegistry.register(new Scheme("https", 443, sslSocketFactory)); final DefaultHttpClient httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager(schemaRegistry), ps); setupProxy(httpclient); httpclient.setRoutePlanner(new ProxySelectorRoutePlanner( httpclient.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault())); httpclient.addRequestInterceptor(new RequestAcceptEncoding()); httpclient.addResponseInterceptor(new ResponseContentEncoding()); httpclient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3, true)); myClient = httpclient; }