List of usage examples for org.apache.http.impl.client DefaultHttpClient setHttpRequestRetryHandler
public synchronized void setHttpRequestRetryHandler(final HttpRequestRetryHandler handler)
From source file:com.waku.common.http.MyHttpClient.java
public static Document getAsDom4jDoc(String url) { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler()); try {/*ww w . j a v a2 s .com*/ HttpGet httpGet = new HttpGet(url); return getResponseAndConvertToDom(httpclient, httpGet); } finally { try { httpclient.getConnectionManager().shutdown(); } catch (Exception ignore) { } } }
From source file:com.waku.common.http.MyHttpClient.java
public static Document getAsDom4jDoc(String url, MultipartEntity reqEntity) { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler()); try {/*w w w . ja va 2s. c o m*/ HttpPost httpPost = new HttpPost(url); httpPost.setEntity(reqEntity); return getResponseAndConvertToDom(httpclient, httpPost); } finally { try { httpclient.getConnectionManager().shutdown(); } catch (Exception ignore) { } } }
From source file:org.red5.server.util.HttpConnectionUtil.java
/** * Returns a client with all our selected properties / params. * /*from w ww .ja v a2 s . c o m*/ * @return client */ public static final DefaultHttpClient getClient() { // create a singular HttpClient object DefaultHttpClient client = new DefaultHttpClient(connectionManager); // dont retry client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); // get the params for the client HttpParams params = client.getParams(); // establish a connection within x seconds params.setParameter(CoreConnectionPNames.SO_TIMEOUT, connectionTimeout); // no redirects params.setParameter(ClientPNames.HANDLE_REDIRECTS, false); // set custom ua params.setParameter(CoreProtocolPNames.USER_AGENT, userAgent); // set the proxy if the user has one set if ((System.getProperty("http.proxyHost") != null) && (System.getProperty("http.proxyPort") != null)) { HttpHost proxy = new HttpHost(System.getProperty("http.proxyHost").toString(), Integer.valueOf(System.getProperty("http.proxyPort"))); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } return client; }
From source file:org.zenoss.app.consumer.metric.impl.MetricServicePoster.java
private static final DefaultHttpClient newHttpClient() { DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(Integer.MAX_VALUE, true)); return httpClient; }
From source file:uk.co.unclealex.googleauth.ApacheHttpTransport.java
/** * Creates a new instance of the Apache HTTP client that is used by the * {@link #ApacheHttpTransport()} constructor. * * <p>//www . j a v a2 s . co m * Use this constructor if you want to customize the default Apache HTTP client. Settings: * </p> * <ul> * <li>The client connection manager is set to {@link ThreadSafeClientConnManager}.</li> * <li>The socket buffer size is set to 8192 using * {@link HttpConnectionParams#setSocketBufferSize}.</li> * <li><The retry mechanism is turned off by setting * {@code new DefaultHttpRequestRetryHandler(0, false)}</li> * </ul> * * @return new instance of the Apache HTTP client * @since 1.6 */ public static DefaultHttpClient newDefaultHttpClient() { // Turn off stale checking. Our connections break all the time anyway, // and it's not worth it to pay the penalty of checking every time. HttpParams params = new BasicHttpParams(); HttpConnectionParams.setStaleCheckingEnabled(params, false); HttpConnectionParams.setSocketBufferSize(params, 8192); ConnManagerParams.setMaxTotalConnections(params, 200); ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(20)); // See http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(params, registry); DefaultHttpClient defaultHttpClient = new DefaultHttpClient(connectionManager, params); defaultHttpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); return defaultHttpClient; }
From source file:com.starbucks.apps.HttpUtils.java
private static DefaultHttpClient getHttpClient(HttpInvocationContext context) { DefaultHttpClient client = new DefaultHttpClient(); HttpParams params = client.getParams(); HttpConnectionParams.setConnectionTimeout(params, 30000); HttpConnectionParams.setSoTimeout(params, 30000); client.setHttpRequestRetryHandler(new HttpRequestRetryHandler() { public boolean retryRequest(IOException e, int i, HttpContext httpContext) { return false; }/*from w ww . ja v a 2 s . c o m*/ }); client.addRequestInterceptor(context); client.addResponseInterceptor(context); return client; }
From source file:ee.ria.xroad.asyncsender.ProxyClient.java
private static HttpClient createHttpClient() { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpParams params = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, CLIENT_TIMEOUT); // Disable request retry httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); return httpClient; }
From source file:com.fanfou.app.opensource.util.NetworkHelper.java
public final static DefaultHttpClient createHttpClient(final Context context) { final HttpParams params = NetworkHelper.createHttpParams(); final DefaultHttpClient client = new DefaultHttpClient(params); client.addRequestInterceptor(new GzipRequestInterceptor()); client.addResponseInterceptor(new GzipResponseInterceptor()); client.setHttpRequestRetryHandler(new RequestRetryHandler(NetworkHelper.MAX_RETRY_TIMES)); NetworkHelper.checkAndSetProxy(context, params); return client; }
From source file:net.paissad.waqtsalat.service.utils.HttpUtils.java
private static HttpClient getNewHttpClient() throws WSException { try {//ww w . j a v a 2 s.c o m TrustStrategy trustStrategy = new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }; SSLSocketFactory sf = new CustomSSLFactory(trustStrategy); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry sr = new SchemeRegistry(); sr.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); sr.register(new Scheme("https", 443, sf)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(sr); DefaultHttpClient client = new DefaultHttpClient(ccm); client.setHttpRequestRetryHandler(new CustomHttpRequestRetryHandler()); client.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, true); client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH); List<String> authpref = new ArrayList<String>(); // Choose BASIC over DIGEST for proxy authentication authpref.add(AuthPolicy.BASIC); authpref.add(AuthPolicy.DIGEST); client.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref); client.addRequestInterceptor(new CustomHttpRequestInterceptor()); client.addResponseInterceptor(new CustomHttpResponseInterceptor()); return client; } catch (Exception e) { throw new WSException("Error while creating a HTTP client.", e); } }
From source file:com.bt.download.android.core.HttpFetcher.java
private static HttpClient setupHttpClient(boolean gzip) { SSLSocketFactory.getSocketFactory().setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); BasicHttpParams params = new BasicHttpParams(); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(20)); params.setIntParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 200); ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); DefaultHttpClient httpClient = new DefaultHttpClient(cm, new BasicHttpParams()); httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(HTTP_RETRY_COUNT, true)); if (gzip) {// ww w.j a va 2s.c om httpClient.addRequestInterceptor(new HttpRequestInterceptor() { public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { if (!request.containsHeader("Accept-Encoding")) { request.addHeader("Accept-Encoding", "gzip"); } } }); httpClient.addResponseInterceptor(new HttpResponseInterceptor() { public void process(HttpResponse response, HttpContext context) throws HttpException, IOException { HttpEntity entity = response.getEntity(); Header ceheader = entity.getContentEncoding(); if (ceheader != null) { HeaderElement[] codecs = ceheader.getElements(); for (int i = 0; i < codecs.length; i++) { if (codecs[i].getName().equalsIgnoreCase("gzip")) { response.setEntity(new GzipDecompressingEntity(response.getEntity())); return; } } } } }); } return httpClient; }