Example usage for org.apache.http.conn.routing HttpRoute HttpRoute

List of usage examples for org.apache.http.conn.routing HttpRoute HttpRoute

Introduction

In this page you can find the example usage for org.apache.http.conn.routing HttpRoute HttpRoute.

Prototype

public HttpRoute(final HttpHost target) 

Source Link

Document

Creates a new direct insecure route.

Usage

From source file:net.ecfirm.ec.ec1.net.EcNetHelper.java

public static DefaultHttpClient getThreadSafeClient() {
    DefaultHttpClient client = new DefaultHttpClient();
    ClientConnectionManager mgr = client.getConnectionManager();
    /////////*  w  w w . j  ava  2 s  . co m*/
    client.getParams().setParameter("http.protocol.expect-continue", false);
    client.getParams().setParameter("http.connection.timeout", EcConst.NET_HTTP_CONN_TIMEOUT);
    //client.getParams().setParameter("http.socket.timeout", );
    ////////
    HttpParams params = client.getParams();
    ////////
    ConnManagerParams.setMaxTotalConnections(params, EcConst.NET_HTTP_CONN);
    ConnPerRouteBean connPerRoute = new ConnPerRouteBean(EcConst.NET_HTTP_CONN_PER_ROUTE);
    HttpHost localhost = new HttpHost("localhost", 80);
    connPerRoute.setMaxForRoute(new HttpRoute(localhost), EcConst.NET_HTTP_CONN_PER_ROUTE);
    ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
    mgr.getSchemeRegistry().register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    mgr.getSchemeRegistry().register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ////////
    client = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()), params);
    return client;
}

From source file:dal.arris.RequestArrisAlter.java

public RequestArrisAlter(Integer deviceId, Autenticacao autenticacao, String frequency)
        throws UnsupportedEncodingException, IOException {
    Autenticacao a = AuthFactory.getEnd();
    String auth = a.getUser() + ":" + a.getPassword();
    String url = a.getLink() + "capability/execute?capability="
            + URLEncoder.encode("\"getLanWiFiInfo\"", "UTF-8") + "&deviceId=" + deviceId + "&input="
            + URLEncoder.encode(frequency, "UTF-8");

    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(1);//from   ww w  .  ja  v a2  s .  c o  m
    cm.setDefaultMaxPerRoute(1);
    HttpHost localhost = new HttpHost("10.200.6.150", 80);
    cm.setMaxPerRoute(new HttpRoute(localhost), 50);

    // Cookies
    RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT).build();

    CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(cm)
            .setDefaultRequestConfig(globalConfig).build();

    byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("UTF-8")));
    String authHeader = "Basic " + new String(encodedAuth);

    //        CloseableHttpClient httpclient = HttpClients.createDefault();
    try {
        HttpGet httpget = new HttpGet(url);
        httpget.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
        httpget.setHeader(HttpHeaders.CONTENT_TYPE, "text/html");
        httpget.setHeader("Cookie", "JSESSIONID=aaazqNDcHoduPbavRvVUv; AX-CARE-AGENTS-20480=HECDMIAKJABP");

        RequestConfig localConfig = RequestConfig.copy(globalConfig).setCookieSpec(CookieSpecs.STANDARD_STRICT)
                .build();

        HttpGet httpGet = new HttpGet("/");
        httpGet.setConfig(localConfig);

        //            httpget.setHeader(n);
        System.out.println("Executing request " + httpget.getRequestLine());
        CloseableHttpResponse response = httpclient.execute(httpget);

        try {
            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());

            // Get hold of the response entity
            HttpEntity entity = response.getEntity();

            // If the response does not enclose an entity, there is no need
            // to bother about connection release
            if (entity != null) {
                InputStream instream = entity.getContent();
                try {
                    instream.read();
                    BufferedReader rd = new BufferedReader(
                            new InputStreamReader(response.getEntity().getContent()));
                    String line = "";
                    while ((line = rd.readLine()) != null) {
                        System.out.println(line);
                    }
                    // do something useful with the response
                } catch (IOException ex) {
                    // In case of an IOException the connection will be released
                    // back to the connection manager automatically
                    throw ex;
                } finally {
                    // Closing the input stream will trigger connection release
                    instream.close();
                }
            }
        } finally {
            response.close();
            for (Header allHeader : response.getAllHeaders()) {
                System.out.println("Nome: " + allHeader.getName() + " Valor: " + allHeader.getValue());
            }
        }
    } finally {
        httpclient.close();
    }
    httpclient.close();
}

From source file:com.googlesource.gerrit.plugins.github.oauth.GitHubHttpProvider.java

public GitHubHttpProvider() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

    connectionManager = new PoolingClientConnectionManager(schemeRegistry);
    connectionManager.setMaxTotal(MAX_TOTAL_CONN);
    connectionManager.setDefaultMaxPerRoute(MAX_CONN_PER_ROUTE);
    HttpHost localhost = new HttpHost("locahost", 80);
    connectionManager.setMaxPerRoute(new HttpRoute(localhost), MAX_LOCALHOST_CONN);
}

From source file:org.jboss.narayana.rts.JAXRSServer.java

private void setCMConfig(PoolingHttpClientConnectionManager cm) {
    cm.setMaxTotal(100);/* ww w  .j a v a 2 s  . com*/
    cm.setDefaultMaxPerRoute(10);
    cm.setMaxPerRoute(new HttpRoute(new HttpHost("localhost", 80)), 20);
}

From source file:ro.zg.netcell.connectors.HttpConnectionManager.java

private void initHttpClient() {
    ConfigurationData cfgData = dataSourceDefinition.getConfigData();

    HttpParams params = new BasicHttpParams();
    ConnManagerParams.setMaxTotalConnections(params, Integer
            .parseInt(cfgData.getParameterValue(DataSourceConfigParameters.MAX_TOTAL_CONNECTIONS).toString()));
    ConnPerRouteBean connPerRoute = new ConnPerRouteBean(10);
    HttpHost localhost = new HttpHost("locahost", 80);
    connPerRoute.setMaxForRoute(new HttpRoute(localhost), 50);
    ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
    ConnManagerParams.setTimeout(params, Long
            .parseLong(cfgData.getParameterValue(DataSourceConfigParameters.CONNECTION_TIMEOUT).toString()));

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

    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);

    /* set config params */
    ConfigurationData configData = dataSourceDefinition.getConfigData();
    Map<String, UserInputParameter> userInputParams = configData.getUserInputParams();
    for (UserInputParameter uip : userInputParams.values()) {
        params.setParameter(uip.getInnerName(), uip.getValue());
    }/*from w  w w .j av  a2s .c o  m*/

    HttpConnectionParams.setSoTimeout(params, 25000);
    httpClient = new DefaultHttpClient(cm, params);

}

From source file:com.bigdata.rdf.sail.webapp.client.DefaultClientConnectionManagerFactory.java

public ClientConnectionManager newInstance() {

    final ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(newSchemeRegistry());

    // Increase max total connection to 200
    cm.setMaxTotal(200);//  w w  w  . j  ava2s .  co  m

    // Increase default max connection per route to 20
    cm.setDefaultMaxPerRoute(20);

    // Increase max connections for localhost to 50
    final HttpHost localhost = new HttpHost("locahost");

    cm.setMaxForRoute(new HttpRoute(localhost), 50);

    return cm;

}

From source file:utils.HttpClientGenerator.java

public static CloseableHttpClient getHttpClient(boolean checkCert) {

    if (checkCert == false) {
        HttpClientBuilder b = HttpClientBuilder.create();

        // setup a Trust Strategy that allows all certificates.
        SSLContext sslContext = null;
        try {/*from   w w  w  .  j  av a 2s.co  m*/
            sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
                public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                    return true;
                }
            }).build();
        } catch (NoSuchAlgorithmException e) {
            String err = "error occurred while creating SSL disables hhtp client";
        } catch (KeyManagementException e) {
            e.printStackTrace();
        } catch (KeyStoreException e) {
            e.printStackTrace();
        }
        b.setSslcontext(sslContext);

        // not to check Hostnames
        HostnameVerifier hostnameVerifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

        //       create an SSL Socket Factory, to use weakened "trust strategy";
        //       and create a Registry, to register it.
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext,
                (X509HostnameVerifier) hostnameVerifier);
        Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
                .<ConnectionSocketFactory>create()
                .register("http", PlainConnectionSocketFactory.getSocketFactory())
                .register("https", sslSocketFactory).build();

        // creating connection-manager using our Registry.
        //      -- allows multi-threaded use
        PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(
                socketFactoryRegistry);
        connMgr.setDefaultMaxPerRoute(20);
        // Increase max connections for localhost:80 to 50
        HttpHost localhost = new HttpHost("localhost", 9443);
        connMgr.setMaxPerRoute(new HttpRoute(localhost), 10);
        b.setConnectionManager(connMgr);

        // finally, build the HttpClient;
        CloseableHttpClient client = b.build();
        return client;
    } else {
        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
        // Increase default max connection per route to 20
        cm.setDefaultMaxPerRoute(20);
        // Increase max connections for localhost:80 to 50
        HttpHost localhost = new HttpHost("localhost", 9443);
        cm.setMaxPerRoute(new HttpRoute(localhost), 10);
        CloseableHttpClient client = HttpClients.custom().setConnectionManager(cm).build();
        return client;
    }
}

From source file:com.yahoo.sql4d.sql4ddriver.DruidNodeAccessor.java

/**
 * For each route we explicitly set max Connections.
 * @param host/*w  w w  .  j  a v a  2 s.  c  om*/
 * @param port
 * @param maxConnsPerRout 
 */
public DruidNodeAccessor(String host, int port, int maxConnsPerRout) {
    proxyInit();
    if (host != null) {
        HttpHost targetHost = new HttpHost(host, port);
        pool.setMaxPerRoute(new HttpRoute(targetHost), maxConnsPerRout);
    }
}

From source file:org.n52.oxf.util.web.PoolingConnectionManagerHttpClient.java

@Override
public ClientConnectionManager getConnectionManager() {
    PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
    // Increase max total connection to 200
    cm.setMaxTotal(200);//from  ww w.  ja  v a2s .c o  m
    // Increase default max connection per route to 20
    cm.setDefaultMaxPerRoute(20);
    // Increase max connections for localhost:80 to 50
    HttpHost localhost8080 = new HttpHost("localhost", 8080);
    cm.setMaxPerRoute(new HttpRoute(localhost8080), 50);
    HttpHost localhost = new HttpHost("localhost", 80);
    cm.setMaxPerRoute(new HttpRoute(localhost), 50);

    return cm;
}

From source file:com.netflix.http4.NFHttpClient.java

protected NFHttpClient(String host, int port) {
    super(new ThreadSafeClientConnManager());
    this.name = "UNNAMED_" + numNonNamedHttpClients.incrementAndGet();
    httpHost = new HttpHost(host, port);
    httpRoute = new HttpRoute(httpHost);
    init();//from  w  w w . ja  v a 2s .co m
}