use of org.apache.http.params.BasicHttpParams in project vespa by vespa-engine.
the class HTTPParameters method toHttpParams.
/**
* Returns the eligible subset of this as a HttpParams snapshot
* AND configures the Apache HTTP library with the parameters of this
*/
public HttpParams toHttpParams(int connectionTimeout, int readTimeout) {
HttpParams params = new BasicHttpParams();
// force use of configured value if available
if (configuredConnectionTimeout > 0) {
HttpConnectionParams.setConnectionTimeout(params, configuredConnectionTimeout);
} else {
HttpConnectionParams.setConnectionTimeout(params, connectionTimeout);
}
if (configuredReadTimeout > 0) {
HttpConnectionParams.setSoTimeout(params, configuredReadTimeout);
} else {
HttpConnectionParams.setSoTimeout(params, readTimeout);
}
if (socketBufferSizeBytes > 0) {
HttpConnectionParams.setSocketBufferSize(params, socketBufferSizeBytes);
}
if (connectionPoolTimeout > 0) {
ConnManagerParams.setTimeout(params, connectionPoolTimeout);
}
ConnManagerParams.setMaxTotalConnections(params, maxTotalConnections);
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(maxConnectionsPerRoute));
if (retries >= 0) {
params.setIntParameter(RETRIES, retries);
}
params.setParameter("http.protocol.handle-redirects", followRedirects);
return params;
}
use of org.apache.http.params.BasicHttpParams in project service-proxy by membrane.
the class OAuth2RaceCondition method setNoRedirects.
private void setNoRedirects(HttpRequestBase get) {
BasicHttpParams params = new BasicHttpParams();
params.setParameter(ClientPNames.HANDLE_REDIRECTS, false);
get.setParams(params);
}
use of org.apache.http.params.BasicHttpParams in project Hotchpotch by carryxyh.
the class HttpUtil method getBytes.
public static byte[] getBytes(String url, Map<String, Object> params, int timeout) {
HttpClient httpClient = null;
HttpGet get = null;
try {
httpClient = new DefaultHttpClient();
initHttpClient(httpClient, timeout);
get = new HttpGet(url);
get.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
get.addHeader("Accept-Encoding", "gzip, deflate");
if (params != null && !params.isEmpty()) {
HttpParams httpParams = new BasicHttpParams();
for (Map.Entry<String, Object> entry : params.entrySet()) {
httpParams.setParameter(entry.getKey(), entry.getValue().toString());
}
get.setParams(httpParams);
}
// logger.error(get.getQueryString());
HttpResponse httpResponse = httpClient.execute(get);
return processResponse(httpResponse);
} catch (Exception e) {
logger.error("网络出错,可能的原因是:您的网络不通!\n或者服务器停掉了!" + e);
} finally {
if (httpClient != null) {
httpClient.getConnectionManager().shutdown();
}
}
return null;
}
use of org.apache.http.params.BasicHttpParams in project LiveSDK-for-Android by liveservices.
the class LiveConnectClient method getHttpClient.
private static HttpClient getHttpClient() {
// The LiveConnectClients can share one HttpClient with a ThreadSafeConnManager.
if (HTTP_CLIENT == null) {
synchronized (HTTP_CLIENT_LOCK) {
if (HTTP_CLIENT == null) {
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, CONNECT_TIMEOUT_IN_MS);
HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT_IN_MS);
ConnManagerParams.setMaxTotalConnections(params, 100);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
// Create an HttpClient with the ThreadSafeClientConnManager.
// This connection manager must be used if more than one thread will
// be using the HttpClient, which is a common scenario.
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
HTTP_CLIENT = new DefaultHttpClient(cm, params);
}
}
}
return HTTP_CLIENT;
}
use of org.apache.http.params.BasicHttpParams in project k-9 by k9mail.
the class WebDavStoreTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
HttpParams httpParams = new BasicHttpParams();
when(mockHttpClientFactory.create()).thenReturn(mockHttpClient);
when(mockHttpClient.getParams()).thenReturn(httpParams);
when(mockHttpClient.getConnectionManager()).thenReturn(mockClientConnectionManager);
when(mockClientConnectionManager.getSchemeRegistry()).thenReturn(mockSchemeRegistry);
serverSettings = createServerSettings(ConnectionSecurity.SSL_TLS_REQUIRED);
webDavStore = createWebDavStore();
}
Aggregations