use of org.apache.http.client.config.RequestConfig in project Signal-Android by WhisperSystems.
the class LegacyMmsConnection method constructHttpClient.
protected CloseableHttpClient constructHttpClient() throws IOException {
RequestConfig config = RequestConfig.custom().setConnectTimeout(20 * 1000).setConnectionRequestTimeout(20 * 1000).setSocketTimeout(20 * 1000).setMaxRedirects(20).build();
URL mmsc = new URL(apn.getMmsc());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
if (apn.hasAuthentication()) {
credsProvider.setCredentials(new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()), new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword()));
}
return HttpClients.custom().setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4()).setRedirectStrategy(new LaxRedirectStrategy()).setUserAgent(TextSecurePreferences.getMmsUserAgent(context, USER_AGENT)).setConnectionManager(new BasicHttpClientConnectionManager()).setDefaultRequestConfig(config).setDefaultCredentialsProvider(credsProvider).build();
}
use of org.apache.http.client.config.RequestConfig in project jersey by jersey.
the class ApacheConnector method getUriHttpRequest.
private HttpUriRequest getUriHttpRequest(final ClientRequest clientRequest) {
final RequestConfig.Builder requestConfigBuilder = RequestConfig.copy(requestConfig);
final int connectTimeout = clientRequest.resolveProperty(ClientProperties.CONNECT_TIMEOUT, -1);
final int socketTimeout = clientRequest.resolveProperty(ClientProperties.READ_TIMEOUT, -1);
if (connectTimeout >= 0) {
requestConfigBuilder.setConnectTimeout(connectTimeout);
}
if (socketTimeout >= 0) {
requestConfigBuilder.setSocketTimeout(socketTimeout);
}
final Boolean redirectsEnabled = clientRequest.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, requestConfig.isRedirectsEnabled());
requestConfigBuilder.setRedirectsEnabled(redirectsEnabled);
final Boolean bufferingEnabled = clientRequest.resolveProperty(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.class) == RequestEntityProcessing.BUFFERED;
final HttpEntity entity = getHttpEntity(clientRequest, bufferingEnabled);
return RequestBuilder.create(clientRequest.getMethod()).setUri(clientRequest.getUri()).setConfig(requestConfigBuilder.build()).setEntity(entity).build();
}
use of org.apache.http.client.config.RequestConfig in project jersey by jersey.
the class DisableContentEncodingTest method testEnabledByRequestConfig.
@Test
public void testEnabledByRequestConfig() {
ClientConfig cc = new ClientConfig(GZipEncoder.class);
final RequestConfig requestConfig = RequestConfig.custom().setContentCompressionEnabled(true).build();
cc.property(ApacheClientProperties.REQUEST_CONFIG, requestConfig);
cc.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(cc);
WebTarget r = client.target(getBaseUri());
String enc = r.request().get().readEntity(String.class);
assertEquals("gzip,deflate", enc);
}
use of org.apache.http.client.config.RequestConfig in project disconf by knightliao.
the class HttpClientUtil method buildHttpClient.
/**
* 初始化httpclient对象
*/
private static void buildHttpClient() {
RequestConfig globalConfig = RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(5000).build();
CloseableHttpClient httpclient = HttpClients.custom().setKeepAliveStrategy(new HttpClientKeepAliveStrategy()).setDefaultRequestConfig(globalConfig).build();
HttpClientUtil.httpclient = httpclient;
}
use of org.apache.http.client.config.RequestConfig in project DataX by alibaba.
the class RetryUtilTest method testRetryAsync3.
//@Test
@Ignore
public void testRetryAsync3() throws Exception {
final int TIME_OUT = 30000;
ThreadPoolExecutor executor = RetryUtil.createThreadPoolExecutor();
String res = RetryUtil.asyncExecuteWithRetry(new Callable<String>() {
@Override
public String call() throws Exception {
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(TIME_OUT).setConnectTimeout(TIME_OUT).setConnectionRequestTimeout(TIME_OUT).setStaleConnectionCheckEnabled(true).build();
HttpClient httpClient = HttpClientBuilder.create().setMaxConnTotal(10).setMaxConnPerRoute(10).setDefaultRequestConfig(requestConfig).build();
HttpGet httpGet = new HttpGet();
httpGet.setURI(new URI("http://0.0.0.0:8080/test"));
httpClient.execute(httpGet);
return OK;
}
}, 3, 1000L, false, 6000L, executor);
Assert.assertEquals(res, OK);
// Assert.assertEquals(RetryUtil.EXECUTOR.getActiveCount(), 0);
}
Aggregations