Example usage for org.apache.http.params HttpProtocolParams setVersion

List of usage examples for org.apache.http.params HttpProtocolParams setVersion

Introduction

In this page you can find the example usage for org.apache.http.params HttpProtocolParams setVersion.

Prototype

public static void setVersion(HttpParams httpParams, ProtocolVersion protocolVersion) 

Source Link

Usage

From source file:org.dasein.cloud.virtustream.VirtustreamMethod.java

private @Nonnull HttpClient getClient(URI uri) throws InternalException, CloudException {
    ProviderContext ctx = provider.getContext();

    if (ctx == null) {
        throw new InternalException();
    }//from   w  w w .j a va 2  s  .c om
    boolean ssl = uri.getScheme().startsWith("https");
    HttpParams params = new BasicHttpParams();

    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    //noinspection deprecation
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    HttpProtocolParams.setUserAgent(params, "");

    Properties p = ctx.getCustomProperties();

    if (p != null) {
        String proxyHost = p.getProperty("proxyHost");
        String proxyPort = p.getProperty("proxyPort");

        if (proxyHost != null) {
            int port = 0;

            if (proxyPort != null && proxyPort.length() > 0) {
                port = Integer.parseInt(proxyPort);
            }
            params.setParameter(ConnRoutePNames.DEFAULT_PROXY,
                    new HttpHost(proxyHost, port, ssl ? "https" : "http"));
        }
    }
    return new DefaultHttpClient(params);
}

From source file:org.klnusbaum.udj.network.ServerConnection.java

public static DefaultHttpClient getHttpClient() throws IOException {
    if (httpClient == null) {
        SchemeRegistry schemeReg = new SchemeRegistry();
        schemeReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), SERVER_PORT));
        BasicHttpParams params = new BasicHttpParams();
        ConnManagerParams.setMaxTotalConnections(params, 100);
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
        HttpProtocolParams.setUseExpectContinue(params, true);

        ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(params, schemeReg);
        httpClient = new DefaultHttpClient(cm, params);
    }//from w ww  .j a  va2s.co m
    return httpClient;
}

From source file:org.whitesource.agent.client.WssServiceClientImpl.java

/**
 * Constructor//from   w  w w  .j  av a 2  s .c  o m
 *
 * @param serviceUrl WhiteSource service URL to use.
 * @param setProxy WhiteSource set proxy, whether the proxy settings is defined or not.
 * @param connectionTimeoutMinutes WhiteSource connection timeout, whether the connection timeout is defined or not (default to 60 minutes).
 */
public WssServiceClientImpl(String serviceUrl, boolean setProxy, int connectionTimeoutMinutes,
        boolean ignoreCertificateCheck) {
    gson = new Gson();

    if (serviceUrl == null || serviceUrl.length() == 0) {
        this.serviceUrl = ClientConstants.DEFAULT_SERVICE_URL;
    } else {
        this.serviceUrl = serviceUrl;
    }

    if (connectionTimeoutMinutes <= 0) {
        this.connectionTimeout = ClientConstants.DEFAULT_CONNECTION_TIMEOUT_MINUTES * TO_MILLISECONDS;
    } else {
        this.connectionTimeout = connectionTimeoutMinutes * TO_MILLISECONDS;
    }

    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, this.connectionTimeout);
    HttpConnectionParams.setSoTimeout(params, this.connectionTimeout);
    HttpClientParams.setRedirecting(params, true);

    httpClient = new DefaultHttpClient();

    if (ignoreCertificateCheck) {
        try {
            logger.warn("Security Warning - Trusting all certificates");

            KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
            char[] password = SOME_PASSWORD.toCharArray();
            keystore.load(null, password);

            WssSSLSocketFactory sf = new WssSSLSocketFactory(keystore);
            sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

            HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
            HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

            SchemeRegistry registry = new SchemeRegistry();
            registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
            registry.register(new Scheme("https", sf, 443));

            ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

            httpClient = new DefaultHttpClient(ccm, params);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
    }

    if (setProxy) {
        findDefaultProxy();
    }
}