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:it.restrung.rest.misc.HttpClientFactory.java

/**
 * Private helper to initialize an http client
 *
 * @return the initialize http client/*from  w ww .j  a  v  a2  s.  c  o m*/
 */
private static synchronized DefaultHttpClient initializeClient() {
    //prepare for the https connection
    //call this in the constructor of the class that does the connection if
    //it's used multiple times
    SchemeRegistry schemeRegistry = new SchemeRegistry();

    // http scheme
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    // https scheme
    schemeRegistry.register(new Scheme("https", new FakeSocketFactory(), 443));

    HttpParams params;
    params = new BasicHttpParams();
    params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 1);
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(1));
    params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
    HttpClientParams.setRedirecting(params, true);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "utf8");

    // ignore that the ssl cert is self signed
    ThreadSafeClientConnManager clientConnectionManager = new ThreadSafeClientConnManager(params,
            schemeRegistry);

    instance = new DefaultHttpClient(clientConnectionManager, params);
    instance.setRedirectHandler(new DefaultRedirectHandler()); //If the link has a redirect
    return instance;
}

From source file:fi.iki.dezgeg.matkakorttiwidget.matkakortti.NonverifyingSSLSocketFactory.java

public static AbstractHttpClient createNonverifyingHttpClient() throws Exception {

    KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
    trustStore.load(null, null);//w  ww  .  j ava  2  s .  c o  m

    SSLSocketFactory sf = new NonverifyingSSLSocketFactory(trustStore);
    sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

    HttpParams params = new BasicHttpParams();
    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);

    return new DefaultHttpClient(ccm, params);
}

From source file:com.thistech.spotlink.util.HttpClientFactory.java

public HttpClient newInstance() {
    HttpClient client = new DefaultHttpClient();
    HttpParams httpParams = client.getParams();
    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);

    if (this.properties.containsKey("httpclient.timeout")) {
        int timeout = Integer.parseInt(this.properties.getProperty("httpclient.timeout"));
        HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
        HttpConnectionParams.setSoTimeout(httpParams, timeout);
    }//  w ww  .  j  a va 2 s .c  o m

    ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRoute() {
        public int getMaxForRoute(HttpRoute route) {
            return Integer.parseInt(properties.getProperty("httpclient.conn-per-route", "5"));
        }
    });

    int totalConnections = Integer.parseInt(this.properties.getProperty("httpclient.total-connections", "100"));
    ConnManagerParams.setMaxTotalConnections(httpParams, totalConnections);

    String userAgent = this.properties.getProperty("httpclient.user-agent", "Mozilla/5.0");
    HttpProtocolParams.setUserAgent(httpParams, userAgent);

    String charset = this.properties.getProperty("httpclient.content-charset", "UTF-8");
    HttpProtocolParams.setContentCharset(httpParams, charset);

    ClientConnectionManager mgr = client.getConnectionManager();
    SchemeRegistry schemeRegistry = mgr.getSchemeRegistry();
    client = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, schemeRegistry), httpParams);
    return client;
}

From source file:com.inferiorhumanorgans.WayToGo.Agency.BART.BaseXMLTask.java

@Override
protected Void doInBackground(final BARTAgency... someAgencies) {
    Assert.assertEquals(1, someAgencies.length);
    theAgency = someAgencies[0];// ww  w .  ja v a 2  s  . com

    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
    HttpProtocolParams.setUseExpectContinue(params, true);
    /*HttpConnectionParams.setConnectionTimeout(params, 1000);
    HttpConnectionParams.setSoTimeout(params, 1000);
    ConnManagerParams.setTimeout(params, 1000);*/

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

    return null;
}

From source file:cn.keke.travelmix.HttpClientHelper.java

public static HttpClient getNewHttpClient() {
    try {/*  w  ww  . j ava  2 s  . co m*/
        SSLSocketFactory sf = new EasySSLSocketFactory();

        // TODO test, if SyncBasicHttpParams is needed
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
        HttpProtocolParams.setUseExpectContinue(params, false);
        HttpProtocolParams.setHttpElementCharset(params, HTTP.UTF_8);
        HttpConnectionParams.setConnectionTimeout(params, 10000);
        HttpConnectionParams.setSocketBufferSize(params, 8192);
        HttpConnectionParams.setLinger(params, 1);
        HttpConnectionParams.setStaleCheckingEnabled(params, false);
        HttpConnectionParams.setSoReuseaddr(params, true);
        HttpConnectionParams.setTcpNoDelay(params, true);
        HttpClientParams.setCookiePolicy(params, CookiePolicy.IGNORE_COOKIES);
        HttpClientParams.setAuthenticating(params, false);
        HttpClientParams.setRedirecting(params, false);

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

        ThreadSafeClientConnManager ccm = new ThreadSafeClientConnManager(registry, 20, TimeUnit.MINUTES);
        ccm.setMaxTotal(100);
        ccm.setDefaultMaxPerRoute(20);

        return new DefaultHttpClient(ccm, params);
    } catch (Exception e) {
        LOG.warn("Failed to create custom http client. Default http client is created", e);
        return new DefaultHttpClient();
    }
}

From source file:org.andstatus.app.net.http.MisconfiguredSslHttpClientFactory.java

private static HttpParams getHttpParams() {
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    HttpConnectionParams.setStaleCheckingEnabled(params, true);

    HttpProtocolParams.setUseExpectContinue(params, false);
    HttpConnectionParams.setSoTimeout(params, MyPreferences.getConnectionTimeoutMs());
    HttpConnectionParams.setSocketBufferSize(params, 2 * 8192);
    return params;
}

From source file:org.silvertunnel.netlib.adapter.httpclient.HttpClientUtil.java

static void init(NetLayer lowerNetLayer) {
    try {/*from  w  ww. j a  v  a 2  s  . c o m*/
        HttpClientUtil.lowerNetLayer = lowerNetLayer;
        Scheme http = new Scheme("http", new NetlibSocketFactory(lowerNetLayer), 80);

        supportedSchemes = new SchemeRegistry();
        supportedSchemes.register(http);

        // prepare parameters
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, "UTF-8");
        HttpProtocolParams.setUseExpectContinue(params, true);

        connMgr = new ThreadSafeClientConnManager(params, supportedSchemes);

    } catch (Exception e) {
        log.log(Level.SEVERE, "error during class init", e);
    }
}

From source file:org.changhong.sync.web.MySSLSocketFactory.java

public static DefaultHttpClient getNewHttpClient() {
    try {//  w ww. ja  v  a2s.c om
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

        SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        HttpParams params = new BasicHttpParams();
        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);

        return new DefaultHttpClient(ccm, params);
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}

From source file:com.wialon.remote.ApacheSdkHttpClient.java

private static BasicHttpParams getBasicHttpParams(int timeout) {
    BasicHttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    HttpProtocolParams.setHttpElementCharset(params, HTTP.UTF_8);
    HttpConnectionParams.setConnectionTimeout(params, timeout);
    HttpConnectionParams.setSoTimeout(params, timeout);
    return params;
}

From source file:mpv5.utils.http.HttpClient.java

/**
 * Connects to the given host/*from  w  ww. jav a 2 s. c o m*/
 * @param toHost
 * @param port
 * @throws UnknownHostException
 * @throws IOException
 * @throws HttpException
 */
public HttpClient(String toHost, int port) throws UnknownHostException, IOException, HttpException {
    params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "UTF-8");
    HttpProtocolParams.setUserAgent(params, "HttpComponents/1.1");
    HttpProtocolParams.setUseExpectContinue(params, true);

    httpproc = new BasicHttpProcessor();
    // Required protocol interceptors
    httpproc.addInterceptor(new RequestContent());
    httpproc.addInterceptor(new RequestTargetHost());
    // Recommended protocol interceptors
    httpproc.addInterceptor(new RequestConnControl());
    httpproc.addInterceptor(new RequestUserAgent());
    httpproc.addInterceptor(new RequestExpectContinue());
    httpexecutor = new HttpRequestExecutor();
    context = new BasicHttpContext(null);
    host = new HttpHost(toHost, port);
    conn = new DefaultHttpClientConnection();
    connStrategy = new DefaultConnectionReuseStrategy();
    context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
    context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host);
}