List of usage examples for org.apache.http.impl.client DefaultHttpRequestRetryHandler DefaultHttpRequestRetryHandler
@SuppressWarnings("unchecked") public DefaultHttpRequestRetryHandler(final int retryCount, final boolean requestSentRetryEnabled)
From source file:org.flowable.http.impl.HttpActivityBehaviorImpl.java
public HttpActivityBehaviorImpl() { HttpClientConfig config = CommandContextUtil.getProcessEngineConfiguration().getHttpClientConfig(); HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); // https settings if (config.isDisableCertVerify()) { try {//from w w w .j a v a2 s.c o m SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); httpClientBuilder.setSSLSocketFactory( new SSLConnectionSocketFactory(builder.build(), new HostnameVerifier() { public boolean verify(String s, SSLSession sslSession) { return true; } })); } catch (Exception e) { LOGGER.error("Could not configure HTTP client SSL self signed strategy", e); } } // request retry settings int retryCount = 0; if (config.getRequestRetryLimit() > 0) { retryCount = config.getRequestRetryLimit(); } httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(retryCount, false)); // Build http client client = httpClientBuilder.build(); LOGGER.info("HTTP client is initialized"); // Shutdown hook to close the http client Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { if (client != null) { try { client.close(); LOGGER.info("HTTP client is closed"); } catch (Throwable e) { LOGGER.error("Could not close http client", e); } } } }); }
From source file:org.hyperic.hq.hqapi1.HQConnection.java
private <T> T runMethod(HttpRequestBase method, String uri, ResponseHandler<T> responseHandler) throws IOException { String protocol = _isSecure ? "https" : "http"; ServiceError error;/*from w ww . ja va2s . c om*/ URL url = new URL(protocol, _host, _port, uri); try { method.setURI(url.toURI()); } catch (URISyntaxException e) { throw new IllegalArgumentException("The syntax of request url [" + uri + "] is invalid", e); } _log.debug("Setting URI: " + url.toString()); DefaultHttpClient client = new DefaultHttpClient(); if (_isSecure) { // To allow for self signed certificates configureSSL(client); } // Validate user & password inputs if (_user == null || _user.length() == 0) { error = new ServiceError(); error.setErrorCode("LoginFailure"); error.setReasonText("User name cannot be null or empty"); return responseHandler.getErrorResponse(error); } if (_password == null || _password.length() == 0) { error = new ServiceError(); error.setErrorCode("LoginFailure"); error.setReasonText("Password cannot be null or empty"); return responseHandler.getErrorResponse(error); } // Set Basic auth creds UsernamePasswordCredentials defaultcreds = new UsernamePasswordCredentials(_user, _password); client.getCredentialsProvider().setCredentials(AuthScope.ANY, defaultcreds); // Preemptive authentication AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); HttpHost host = new HttpHost(_host, _port, protocol); authCache.put(host, basicAuth); BasicHttpContext localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.AUTH_CACHE, authCache); method.getParams().setParameter(ClientPNames.HANDLE_AUTHENTICATION, true); // Disable re-tries client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, true)); HttpResponse response = client.execute(method, localContext); return responseHandler.handleResponse(response); }