public AutoRetryHttpClient( final HttpClient client, final ServiceUnavailableRetryStrategy retryStrategy) { super(); if (client == null) { throw new IllegalArgumentException("HttpClient may not be null"); } if (retryStrategy == null) { throw new IllegalArgumentException( "ServiceUnavailableRetryStrategy may not be null"); } this.backend = client; this.retryStrategy = retryStrategy; }
public ServiceUnavailableRetryExec( final ClientExecChain requestExecutor, final ServiceUnavailableRetryStrategy retryStrategy) { super(); Args.notNull(requestExecutor, "HTTP request executor"); Args.notNull(retryStrategy, "Retry strategy"); this.requestExecutor = requestExecutor; this.retryStrategy = retryStrategy; }
public AutoRetryHttpClient( final HttpClient client, final ServiceUnavailableRetryStrategy retryStrategy) { super(); Args.notNull(client, "HttpClient"); Args.notNull(retryStrategy, "ServiceUnavailableRetryStrategy"); this.backend = client; this.retryStrategy = retryStrategy; }
public static HttpClientBuilder getHttpClientBuilder(final String charset, String proxyIp, int proxyPort) { HttpClientBuilder builder = HttpClients.custom(); Charset chartset = charset == null ? Charset.forName(CHARSET_UTF8) : Charset.forName(charset); ConnectionConfig.Builder connBuilder = ConnectionConfig.custom().setCharset(chartset); RequestConfig.Builder reqBuilder = RequestConfig.custom(); reqBuilder.setExpectContinueEnabled(false); reqBuilder.setSocketTimeout(10 * 60 * 1000); reqBuilder.setConnectTimeout(10 * 60 * 1000); reqBuilder.setMaxRedirects(10); if (StringUtils.isNotBlank(proxyIp) && proxyPort > 0) { logger.info("using proxy {}:{} to request ", proxyIp, String.valueOf(proxyPort)); HttpHost proxy = new HttpHost(proxyIp, proxyPort); reqBuilder.setProxy(proxy); } ServiceUnavailableRetryStrategy serviceUnavailableRetryStrategy = new DefaultServiceUnavailableRetryStrategy( 3, 3000); builder.setServiceUnavailableRetryStrategy(serviceUnavailableRetryStrategy); // 模拟浏览器,解决一些服务器程序只允许浏览器访问的问题 builder.setUserAgent( "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0"); builder.setDefaultRequestConfig(reqBuilder.build()); builder.setDefaultConnectionConfig(connBuilder.build()); builder.setConnectionManager(getConnectionManager()); // HostnameVerifier allowAllHostnameVerifier = // NoopHostnameVerifier.INSTANCE; // builder.setSSLHostnameVerifier(allowAllHostnameVerifier); return builder; }
public ServiceUnavailableRetryStrategy getServiceUnavailableRetryStrategy() { return this.serviceUnavailableRetryStrategy; }
public void setServiceUnavailableRetryStrategy(final ServiceUnavailableRetryStrategy serviceUnavailableRetryStrategy) { this.serviceUnavailableRetryStrategy = serviceUnavailableRetryStrategy; }
/** * Assigns {@link ServiceUnavailableRetryStrategy} instance. */ public final HttpClientBuilder setServiceUnavailableRetryStrategy( final ServiceUnavailableRetryStrategy serviceUnavailStrategy) { this.serviceUnavailStrategy = serviceUnavailStrategy; return this; }
@Override protected ServiceUnavailableRetryStrategy getServiceUnavailableRetryStrategy() { return new OctaneUnauthorizedRetryStrategy(); }
@Override protected ServiceUnavailableRetryStrategy getServiceUnavailableRetryStrategy() { return new TooManyRequestsRetryStrategy("X-Rate-Limit-Reset"); }
protected ServiceUnavailableRetryStrategy getServiceUnavailableRetryStrategy() { return null; }
/** * Constructs a {@code AutoRetryHttpClient} with the given caching options that * stores cache entries in memory and uses a vanilla * {@link DefaultHttpClient} for backend requests. * * @param config * retry configuration module options */ public AutoRetryHttpClient(ServiceUnavailableRetryStrategy config) { this(new DefaultHttpClient(), config); }
/** * Constructs a {@code AutoRetryHttpClient} with the given caching options that * stores cache entries in memory and uses a vanilla * {@link DefaultHttpClient} for backend requests. * * @param config * retry configuration module options */ public AutoRetryHttpClient(final ServiceUnavailableRetryStrategy config) { this(new DefaultHttpClient(), config); }