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:com.ridgelineapps.wallpaper.photosite.FiveHundredPxUtils.java

private FiveHundredPxUtils() {
    final HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "UTF-8");

    final SchemeRegistry registry = new SchemeRegistry();
    try {//w  w  w . j  a v  a2s.  c  o  m
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", new CustomSSLSocketFactory(), 443));
    } catch (Exception e) {
        e.printStackTrace();
    }
    final ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);
    mClient = new DefaultHttpClient(manager, params);
}

From source file:edu.htl3r.schoolplanner.backend.network.Network.java

public Network() {
    initSSLSocketFactories();/*from   w w w .  jav a 2  s  .  c  o  m*/

    HttpParams params = new BasicHttpParams();

    // TODO: Timeouts sind statisch
    HttpConnectionParams.setConnectionTimeout(params, 20000);
    HttpConnectionParams.setSoTimeout(params, 10000);

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

    SchemeRegistry registry = new SchemeRegistry();

    ClientConnectionManager connman = new ThreadSafeClientConnManager(params, registry);

    client = new DefaultHttpClient(connman, params);
}

From source file:com.jute.fed4j.engine.component.http.HttpDispatcherImpl_Jakarta.java

/**
 * get a connection manager//from w ww. ja  v  a 2  s .c  om
 * @param params
 * @return
 */
private ClientConnectionManager getConnectionManager(HttpParams params, boolean enablePersistentConnection) {
    ClientConnectionManager connectionManager;
    if (enablePersistentConnection) {
        //be careful, somehow the ThreadSafeClientConnManager dosn't perform well with high traffic
        if (sharedConnectionManager == null) {
            synchronized (locker) {
                if (sharedConnectionManager == null) {
                    ConnManagerParams.setMaxTotalConnections(params, 100);
                    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
                    ConnManagerParams.setTimeout(params, 10);
                    sharedConnectionManager = new ThreadSafeClientConnManager(params, schemeRegistry);
                }
            }
        }
        connectionManager = sharedConnectionManager;
    } else {
        connectionManager = new SingleClientConnManager(params, schemeRegistry);
    }
    return connectionManager;
}

From source file:com.xorcode.andtweet.net.ConnectionOAuth.java

public ConnectionOAuth(SharedPreferences sp) {
    super(sp);//from   ww w .  j av  a  2s .c om

    HttpParams parameters = new BasicHttpParams();
    HttpProtocolParams.setVersion(parameters, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(parameters, HTTP.DEFAULT_CONTENT_CHARSET);
    HttpProtocolParams.setUseExpectContinue(parameters, false);
    HttpConnectionParams.setTcpNoDelay(parameters, true);
    HttpConnectionParams.setSocketBufferSize(parameters, 8192);

    SchemeRegistry schReg = new SchemeRegistry();
    schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    ClientConnectionManager tsccm = new ThreadSafeClientConnManager(parameters, schReg);
    mClient = new DefaultHttpClient(tsccm, parameters);

    mConsumer = new CommonsHttpOAuthConsumer(OAuthKeys.TWITTER_CONSUMER_KEY, OAuthKeys.TWITTER_CONSUMER_SECRET);
    loadSavedKeys(sp);
}

From source file:com.google.code.jerseyclients.httpclientfour.ApacheHttpClientFour.java

/**
 * Create a default Apache HTTP client handler.
 * //from   w w  w. j  ava2 s.c  o m
 * @return a default Apache HTTP client handler.
 */
private static ApacheHttpClientFourHandler createDefaultClientHander(JerseyHttpClientConfig config,
        ThreadSafeClientConnManager threadSafeClientConnManager) {

    if (threadSafeClientConnManager == null) {
        throw new IllegalArgumentException("threadSafeClientConnManager cannot be null");
    }

    HttpParams httpParams = new BasicHttpParams();

    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
    HttpClient client = new DefaultHttpClient(threadSafeClientConnManager, httpParams);

    if (config.getProxyInformation() != null) {
        HttpHost proxy = new HttpHost(config.getProxyInformation().getProxyHost(),
                config.getProxyInformation().getProxyPort(), "http");
        client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }

    HttpConnectionParams.setConnectionTimeout(httpParams,
            config == null ? 60000 : config.getConnectionTimeOut());

    // FIXME 

    //HttpParams params = new BasicHttpParams();
    //params.setParameter( ConnManagerPNames.TIMEOUT, config == null ? 50000 : config
    //.getConnectionPoolTimeOut() );

    //client.setHttpConnectionFactoryTimeout( config == null ? 0 : config.getConnectionPoolTimeOut() );
    return new ApacheHttpClientFourHandler(client, config);
}

From source file:me.xiaopan.android.gohttp.HttpClientManager.java

public HttpClientManager(SchemeRegistry schemeRegistry) {
    BasicHttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setTcpNoDelay(httpParams, true); //?TCP
    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); //Http??
    HttpProtocolParams.setUserAgent(httpParams, DEFAULT_USER_AGENT); //?
    httpContext = new SyncBasicHttpContext(new BasicHttpContext()); //?Http
    httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, schemeRegistry), httpParams);
    httpClient.addRequestInterceptor(new GzipProcessRequestInterceptor());
    httpClient.addRequestInterceptor(new AddRequestHeaderRequestInterceptor(getHeaderMap()));
    httpClient.addResponseInterceptor(new GzipProcessResponseInterceptor());
    httpClient//from  w  w  w  .j a  v a  2s  .  c o  m
            .setHttpRequestRetryHandler(new RetryHandler(DEFAULT_MAX_RETRIES, DEFAULT_RETRY_SLEEP_TIME_MILLIS));
    clientHeaderMap = new HashMap<String, String>();
    setTimeout(DEFAULT_TIMEOUT);
    setMaxConnections(DEFAULT_MAX_CONNECTIONS);
    setSocketBufferSize(DEFAULT_SOCKET_BUFFER_SIZE);
}

From source file:foam.littlej.android.app.net.MainHttpClient.java

public MainHttpClient(Context context) {
    this.context = context;
    httpParameters = new BasicHttpParams();
    httpParameters.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 1);
    httpParameters.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(1));

    httpParameters.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
    HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(httpParameters, "utf8");

    // Set the timeout in milliseconds until a connection is established.
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);

    // in milliseconds which is the timeout for waiting for data.
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

    SchemeRegistry schemeRegistry = new SchemeRegistry();

    // http scheme
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    // https scheme
    try {/*from   w  w w  . j  av a2s  .  c o m*/
        schemeRegistry.register(new Scheme("https", new TrustedSocketFactory(Preferences.domain, false), 443));
    } catch (KeyManagementException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParameters, schemeRegistry),
            httpParameters);
    httpClient.setParams(httpParameters);

}

From source file:de.codesourcery.eve.skills.market.impl.EveCentralClient.java

/**
 * Must <b>only</b> be called while {@link #CLIENT_LOCK}
 * is being held./*  w w w.j ava2s.  co m*/
 * 
 * @return
 */
protected ThreadSafeClientConnManager getConnectionManager() {

    if (connectionManager == null) {
        // Create and initialize HTTP parameters
        final HttpParams params = new BasicHttpParams();
        ConnManagerParams.setMaxTotalConnections(params, 30);

        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

        // Create and initialize scheme registry 
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));

        // Create an HttpClient with the ThreadSafeClientConnManager.
        // This connection manager must be used if more than one thread will
        // be using the HttpClient.
        connectionManager = new ThreadSafeClientConnManager(params, schemeRegistry);
    }
    return connectionManager;
}

From source file:org.couch4j.http.HttpConnectionManager.java

public HttpConnectionManager() {
    // Create and initialize HTTP parameters
    HttpParams params = new BasicHttpParams();
    ConnManagerParams.setMaxTotalConnections(params, MAX_TOTAL_CONNECTIONS);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

    Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);

    // Create and initialize scheme registry
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(http);//from  ww w .jav a  2s  .  c o m

    // Create an HttpClient with the ThreadSafeClientConnManager.
    // This connection manager must be used if more than one thread will
    // be using the HttpClient.
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    this.client = new DefaultHttpClient(cm, params);
}