本文整理汇总了Java中org.apache.http.impl.client.DefaultHttpRequestRetryHandler类的典型用法代码示例。如果您正苦于以下问题:Java DefaultHttpRequestRetryHandler类的具体用法?Java DefaultHttpRequestRetryHandler怎么用?Java DefaultHttpRequestRetryHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultHttpRequestRetryHandler类属于org.apache.http.impl.client包,在下文中一共展示了DefaultHttpRequestRetryHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DefaultConnector
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; //导入依赖的package包/类
/**
*
*/
public DefaultConnector() {
final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.closeIdleConnections(120, TimeUnit.SECONDS);
// would be nice to set this from outside -> keep alive
final SocketConfig sConfig = SocketConfig.custom().setSoKeepAlive(true).setSoTimeout(Context.SOCKET_TO).build();
cm.setDefaultSocketConfig(sConfig);
cm.setMaxTotal(150);
cm.setDefaultMaxPerRoute(150);
cm.setValidateAfterInactivity(0);
final HttpRequestRetryHandler rh = new DefaultHttpRequestRetryHandler(3, true);
httpClient = HttpClients.custom().setRetryHandler(rh).setConnectionManager(cm).build();
}
示例2: setUseRetry
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; //导入依赖的package包/类
/**
* Control retry handler
* @param useRetry when false the client will not try to retry failed requests.
*/
public static void setUseRetry(final DefaultHttpClient httpClient,
boolean useRetry) {
if (!useRetry) {
httpClient.setHttpRequestRetryHandler(NO_RETRY);
} else {
// if the request is not fully sent, we retry
// streaming updates are not a problem, because they are not retryable
httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(){
@Override
protected boolean handleAsIdempotent(final HttpRequest request) {
return false; // we can't tell if a Solr request is idempotent
}
});
}
}
示例3: OAuthHttpClient
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; //导入依赖的package包/类
public OAuthHttpClient(int maxConnection, int connectTimeout, int socketTimeout) {
PoolingHttpClientConnectionManager connectionManager =
new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", SSLConnectionSocketFactory.getSocketFactory())
.build());
// set max connection
connectionManager.setMaxTotal(maxConnection);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(connectTimeout)
.setSocketTimeout(socketTimeout)
.setCookieSpec(CookieSpecs.IGNORE_COOKIES)
.build();
httpClient = HttpClientBuilder.create()
.setConnectionManager(connectionManager)
.setDefaultRequestConfig(requestConfig)
.setRetryHandler(new DefaultHttpRequestRetryHandler(3, true))
.build();
}
示例4: getHttpClientInstance
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; //导入依赖的package包/类
public DefaultHttpClient getHttpClientInstance() {
if (this.httpClient != null) {
return this.httpClient;
}
HttpParams params = new BasicHttpParams();
params.setParameter("http.connection.timeout", CONNECTION_TIMEOUT);
params.setParameter("http.socket.timeout", SOCKET_TIMEOUT);
params.setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
params.setParameter("http.useragent", "Apache-HttpClient/Android");
params.setParameter("http.connection.stalecheck", Boolean.valueOf(false));
this.httpClient = new DefaultHttpClient(params);
this.httpClient.addRequestInterceptor(new GzipHttpRequestInterceptor());
this.httpClient.addResponseInterceptor(new GzipHttpResponseInterceptor());
this.httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
return this.httpClient;
}
示例5: performLogoutOnServiceProviders
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; //导入依赖的package包/类
public void performLogoutOnServiceProviders(String idpSessionId) {
List<String> serviceProviderLogoutUrls = idpConfig.getServiceProviderLogoutUrls();
asyncServiceLogoutExecutor.submit(() -> {
HttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager();
HttpClient client = HttpClientBuilder.create()
.setConnectionManager(connectionManager)
.setRetryHandler(new DefaultHttpRequestRetryHandler(3, true))
.build();
try {
for (String serviceProviderLogoutUrl : serviceProviderLogoutUrls) {
callLoggedOutServiceUrl(client, serviceProviderLogoutUrl, idpSessionId);
}
} catch (Throwable ex) {
log.error("Unable to perform logout on IDP services for session {}", idpSessionId, ex);
} finally {
connectionManager.shutdown();
}
});
}
示例6: ping
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; //导入依赖的package包/类
private boolean ping() throws IOException {
RequestConfig requestConfig =
RequestConfig.custom()
.setSocketTimeout(HTTP_PING_TIMEOUT)
.setConnectTimeout(HTTP_PING_TIMEOUT)
.setConnectionRequestTimeout(HTTP_PING_TIMEOUT)
.build();
CloseableHttpClient httpClient = HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig)
.setRetryHandler(new DefaultHttpRequestRetryHandler(HTTP_CLIENT_RETRIES, false))
.build();
try {
CloseableHttpResponse response = httpClient.execute(RequestBuilder.create(method.toUpperCase()).setUri(url).build());
try {
int responseCode = response.getStatusLine().getStatusCode();
if (responseCode == 501) {
throw new IllegalArgumentException("Invalid or not supported HTTP method '" + method.toUpperCase() + "' for checking " + url);
}
return (responseCode >= statusMin && responseCode <= statusMax);
} finally {
response.close();
}
} finally {
httpClient.close();
}
}
示例7: createHttpClient
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; //导入依赖的package包/类
/**
* Returns a new HTTP client by the specified repository configuration.
*
* @return a new HTTP client by the specified repository configuration
*/
private HttpClient createHttpClient() {
RequestConfig.Builder requestBuilder = RequestConfig.custom().setSocketTimeout(10 * 1000);
if (repoConfig.getProxy() != null) {
requestBuilder.setProxy(HttpHost.create(repoConfig.getProxy()));
}
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().setDefaultRequestConfig(requestBuilder.build());
httpClientBuilder = httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(3, false));
httpClientBuilder = httpClientBuilder.setRedirectStrategy(new DefaultRedirectStrategy());
if (repoConfig.getUsername() != null) {
final Credentials creds = new UsernamePasswordCredentials(repoConfig.getUsername(), repoConfig.getPassword());
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, creds);
httpClientBuilder = httpClientBuilder.setDefaultCredentialsProvider(credsProvider);
}
return httpClientBuilder.build();
}
示例8: doConnect
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; //导入依赖的package包/类
protected HttpResponse doConnect(HttpTask task) throws Exception
{
mHttpParams = new BasicHttpParams();
HttpProtocolParams.setVersion(mHttpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(mHttpParams, "utf-8");
HttpConnectionParams.setConnectionTimeout(mHttpParams, task.getConnectTimeout());
HttpConnectionParams.setSoTimeout(mHttpParams, task.getSocketTimeout());
// 加入代理
HttpUtils.fillProxy(mContext, mHttpParams);
mHttpClient = new DefaultHttpClient(mHttpParams);
// 重试一次
mHttpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(2, true));
HttpResponse httpResponse = mHttpClient.execute(task.getHttpUriRequest());
return httpResponse;
}
示例9: test
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; //导入依赖的package包/类
@Test
public void test() throws Exception {
DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
IOException iOException = new IOException();
HttpContext context = new BasicHttpContext();
assertTrue(retryHandler.retryRequest(iOException, 1, context));
assertTrue(retryHandler.retryRequest(iOException, 2, context));
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
verifier.verifyTrace(event("HTTP_CLIENT_4_INTERNAL", DefaultHttpRequestRetryHandler.class.getMethod("retryRequest", IOException.class, int.class, HttpContext.class),
annotation("http.internal.display", IOException.class.getName() + ", 1"), annotation("RETURN_DATA", true)));
verifier.verifyTrace(event("HTTP_CLIENT_4_INTERNAL", DefaultHttpRequestRetryHandler.class.getMethod("retryRequest", IOException.class, int.class, HttpContext.class),
annotation("http.internal.display", IOException.class.getName() + ", 2"), annotation("RETURN_DATA", true)));
verifier.verifyTraceCount(0);
}
示例10: getClient
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; //导入依赖的package包/类
/**
* Returns a client with all our selected properties / params.
*
* @param timeout
* - socket timeout to set
* @return client
*/
public static final HttpClient getClient(int timeout) {
HttpClientBuilder client = HttpClientBuilder.create();
// set the connection manager
client.setConnectionManager(connectionManager);
// dont retry
client.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
// establish a connection within x seconds
RequestConfig config = RequestConfig.custom().setSocketTimeout(timeout).build();
client.setDefaultRequestConfig(config);
// no redirects
client.disableRedirectHandling();
// set custom ua
client.setUserAgent(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.setProxy(proxy);
}
return client.build();
}
示例11: getSecureClient
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; //导入依赖的package包/类
/**
* Returns a client with all our selected properties / params and SSL enabled.
*
* @return client
*/
public static final HttpClient getSecureClient() {
HttpClientBuilder client = HttpClientBuilder.create();
// set the ssl verifier to accept all
client.setSSLHostnameVerifier(new NoopHostnameVerifier());
// set the connection manager
client.setConnectionManager(connectionManager);
// dont retry
client.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
// establish a connection within x seconds
RequestConfig config = RequestConfig.custom().setSocketTimeout(connectionTimeout).build();
client.setDefaultRequestConfig(config);
// no redirects
client.disableRedirectHandling();
// set custom ua
client.setUserAgent(userAgent);
return client.build();
}
示例12: getClient
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; //导入依赖的package包/类
public synchronized HttpClient getClient() {
if (m_client == null) {
m_client = new DefaultHttpClient();
HttpParams clientParams = m_client.getParams();
clientParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, m_timeout);
clientParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, m_timeout);
clientParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
m_client.setParams(clientParams);
m_client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(m_retries, false));
}
return m_client;
}
示例13: makeCloseableHttpClient
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; //导入依赖的package包/类
/**
* Internal function to create http clients for fetching
* @param timeoutms The timeout, which is applied to the connect, connection request, and socket timeouts. Ignored if <=0
* @param numRetries The number of retries. Ignored if <0
* @param credentials optional credentials provider to be used for authentication
* @return A CloseableHttpClient with the specified parameters set
*/
private static CloseableHttpClient makeCloseableHttpClient(int timeoutms, int numRetries, Optional<CredentialsProvider> credentials) {
HttpClientBuilder builder = HttpClientBuilder.create();
if(credentials.isPresent()) { builder.setDefaultCredentialsProvider(credentials.get()); }
if (numRetries >= 0) {
DefaultHttpRequestRetryHandler retryHandler =
new DefaultHttpRequestRetryHandler(numRetries, false);
builder = builder.setRetryHandler(retryHandler);
}
if (timeoutms > 0) {
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(timeoutms)
.setConnectionRequestTimeout(timeoutms)
.setSocketTimeout(timeoutms).build();
builder.setDefaultRequestConfig(config);
}
return builder.build();
}
示例14: HttpStoreClientFactory
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; //导入依赖的package包/类
public HttpStoreClientFactory(ClientConfig config) {
super(config);
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(),
config.getConnectionTimeout(TimeUnit.MILLISECONDS),
TimeUnit.MILLISECONDS);
mgr.setMaxTotal(config.getMaxTotalConnections());
mgr.setDefaultMaxPerRoute(config.getMaxConnectionsPerNode());
this.httpClient = new DefaultHttpClient(mgr);
HttpParams clientParams = this.httpClient.getParams();
HttpProtocolParams.setUserAgent(clientParams, VOLDEMORT_USER_AGENT);
HttpProtocolParams.setVersion(clientParams, HttpVersion.HTTP_1_1);
HttpConnectionParams.setConnectionTimeout(clientParams,
config.getConnectionTimeout(TimeUnit.MILLISECONDS));
HttpConnectionParams.setSoTimeout(clientParams,
config.getSocketTimeout(TimeUnit.MILLISECONDS));
HttpConnectionParams.setStaleCheckingEnabled(clientParams, false);
this.httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
HttpClientParams.setCookiePolicy(clientParams, CookiePolicy.IGNORE_COOKIES);
this.reroute = config.getRoutingTier().equals(RoutingTier.SERVER);
this.requestFormatFactory = new RequestFormatFactory();
}
示例15: getClient
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; //导入依赖的package包/类
/**
* Returns a client with all our selected properties / params.
*
* @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;
}