Search in sources :

Example 21 with BasicHttpParams

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;
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) BasicHttpParams(org.apache.http.params.BasicHttpParams) ConnPerRouteBean(org.apache.http.conn.params.ConnPerRouteBean)

Example 22 with BasicHttpParams

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);
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams)

Example 23 with BasicHttpParams

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;
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) BasicHttpParams(org.apache.http.params.BasicHttpParams) Map(java.util.Map) TreeMap(java.util.TreeMap) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 24 with BasicHttpParams

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;
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) Scheme(org.apache.http.conn.scheme.Scheme) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) BasicHttpParams(org.apache.http.params.BasicHttpParams) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 25 with BasicHttpParams

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();
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) BasicHttpParams(org.apache.http.params.BasicHttpParams) Before(org.junit.Before)

Aggregations

BasicHttpParams (org.apache.http.params.BasicHttpParams)105 HttpParams (org.apache.http.params.HttpParams)75 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)50 IOException (java.io.IOException)41 HttpResponse (org.apache.http.HttpResponse)33 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)32 Scheme (org.apache.http.conn.scheme.Scheme)31 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)30 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)25 ClientProtocolException (org.apache.http.client.ClientProtocolException)16 HttpGet (org.apache.http.client.methods.HttpGet)16 HttpClient (org.apache.http.client.HttpClient)15 Test (org.junit.Test)15 HttpPost (org.apache.http.client.methods.HttpPost)14 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)14 Socket (java.net.Socket)11 URI (java.net.URI)11 StringEntity (org.apache.http.entity.StringEntity)11 TestHttpClient (io.undertow.testutils.TestHttpClient)10 KeyManagementException (java.security.KeyManagementException)9