Example usage for org.apache.http.impl.conn PoolingClientConnectionManager PoolingClientConnectionManager

List of usage examples for org.apache.http.impl.conn PoolingClientConnectionManager PoolingClientConnectionManager

Introduction

In this page you can find the example usage for org.apache.http.impl.conn PoolingClientConnectionManager PoolingClientConnectionManager.

Prototype

public PoolingClientConnectionManager() 

Source Link

Usage

From source file:org.zaizi.manifoldcf.authorities.authorities.alfresco.AlfrescoAuthorityConnector.java

/**
 * Connect./*  w ww . j a  v a  2  s.  c o m*/
 * 
 * @param configParams is the set of configuration parameters, which in this case describe the target appliance,
 *            basic auth configuration, etc. (This formerly came out of the ini file.)
 */
@Override
public void connect(ConfigParams configParams) {
    super.connect(configParams);
    username = params.getParameter(AlfrescoConfig.USERNAME_PARAM);
    password = params.getObfuscatedParameter(AlfrescoConfig.PASSWORD_PARAM);
    protocol = params.getParameter(AlfrescoConfig.PROTOCOL_PARAM);
    server = params.getParameter(AlfrescoConfig.SERVER_PARAM);
    port = params.getParameter(AlfrescoConfig.PORT_PARAM);
    path = params.getParameter(AlfrescoConfig.PATH_PARAM);

    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    httpClient = new DefaultHttpClient(connectionManager);
    UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
    httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
}

From source file:com.google.apphosting.vmruntime.VmApiProxyDelegateTest.java

private HttpClient createMockHttpClient() {
    HttpClient httpClient = mock(HttpClient.class);
    when(httpClient.getConnectionManager()).thenReturn(new PoolingClientConnectionManager());
    return httpClient;
}

From source file:com.asakusafw.yaess.jobqueue.client.HttpJobClient.java

private DefaultHttpClient createClient() {
    try {// www  . jav  a  2s.  c om
        DefaultHttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager());
        SSLSocketFactory socketFactory = TrustedSSLSocketFactory.create();
        Scheme sch = new Scheme("https", 443, socketFactory);
        client.getConnectionManager().getSchemeRegistry().register(sch);
        return client;
    } catch (GeneralSecurityException e) {
        throw new IllegalStateException(
                MessageFormat.format("Failed to initialize SSL socket factory: {0}", baseUri), e);
    }
}

From source file:com.google.appengine.tck.jsp.JspMojo.java

@Test
public void compile() throws Exception {
    final PathHandler servletPath = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    JspMojo mojo = TL.get();/*from  ww w.  j  a  va  2 s . co m*/

    final File root = mojo.getJspLocation();

    getLog().info(String.format("JSP location: %s", root));

    final FileFilter filter = new FileFilter() {
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".jsp");
        }
    };

    ServletInfo servlet = JspServletBuilder.createServlet("Default Jsp Servlet", "*.jsp");
    servlet.addInitParam("mappedfile", Boolean.TRUE.toString());

    DeploymentInfo builder = new DeploymentInfo().setClassLoader(JspMojo.class.getClassLoader())
            .setContextPath("/tck").setClassIntrospecter(DefaultClassIntrospector.INSTANCE)
            .setDeploymentName("tck.war").setResourceManager(new FileResourceManager(root, Integer.MAX_VALUE))
            .setTempDir(mojo.getTempDir()).setServletStackTraces(ServletStackTraces.NONE).addServlet(servlet);
    JspServletBuilder.setupDeployment(builder, new HashMap<String, JspPropertyGroup>(),
            new HashMap<String, TagLibraryInfo>(), new HackInstanceManager());

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    servletPath.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(servletPath);

    HttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager());
    try {
        for (File jsp : root.listFiles(filter)) {
            touchJsp(client, jsp.getName());
        }
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:com.alibaba.dubbo.rpc.protocol.rest.RestProtocol.java

protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
    if (connectionMonitor == null) {
        connectionMonitor = new ConnectionMonitor();
    }/* w ww. j a v a  2 s . c o  m*/

    // TODO more configs to add

    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    // 20 is the default maxTotal of current PoolingClientConnectionManager
    connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, 20));
    connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, 20));

    connectionMonitor.addConnectionManager(connectionManager);

    //        BasicHttpContext localContext = new BasicHttpContext();

    DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);

    httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
        public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
            HeaderElementIterator it = new BasicHeaderElementIterator(
                    response.headerIterator(HTTP.CONN_KEEP_ALIVE));
            while (it.hasNext()) {
                HeaderElement he = it.nextElement();
                String param = he.getName();
                String value = he.getValue();
                if (value != null && param.equalsIgnoreCase("timeout")) {
                    return Long.parseLong(value) * 1000;
                }
            }
            // TODO constant
            return 30 * 1000;
        }
    });

    HttpParams params = httpClient.getParams();
    // TODO currently no xml config for Constants.CONNECT_TIMEOUT_KEY so we directly reuse Constants.TIMEOUT_KEY for now
    HttpConnectionParams.setConnectionTimeout(params,
            url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
    HttpConnectionParams.setSoTimeout(params,
            url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
    HttpConnectionParams.setTcpNoDelay(params, true);
    HttpConnectionParams.setSoKeepalive(params, true);

    ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/*, localContext*/);

    ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
    clients.add(client);

    client.register(RpcContextFilter.class);
    for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) {
        if (!StringUtils.isEmpty(clazz)) {
            try {
                client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim()));
            } catch (ClassNotFoundException e) {
                throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e);
            }
        }
    }

    // TODO protocol
    ResteasyWebTarget target = client
            .target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url));
    return target.proxy(serviceType);
}

From source file:com.alibaba.dubbo.rpc.protocol.resteasy.RestProtocol.java

protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
    if (connectionMonitor == null) {
        connectionMonitor = new ConnectionMonitor();
    }/*from w ww .  ja  v a 2 s. c om*/

    // TODO more configs to add

    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    // 20 is the default maxTotal of current PoolingClientConnectionManager
    connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, 20));
    connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, 20));

    connectionMonitor.addConnectionManager(connectionManager);

    // BasicHttpContext localContext = new BasicHttpContext();

    DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);

    httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
        public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
            HeaderElementIterator it = new BasicHeaderElementIterator(
                    response.headerIterator(HTTP.CONN_KEEP_ALIVE));
            while (it.hasNext()) {
                HeaderElement he = it.nextElement();
                String param = he.getName();
                String value = he.getValue();
                if (value != null && param.equalsIgnoreCase("timeout")) {
                    return Long.parseLong(value) * 1000;
                }
            }
            // TODO constant
            return 30 * 1000;
        }
    });

    HttpParams params = httpClient.getParams();
    // TODO currently no xml config for Constants.CONNECT_TIMEOUT_KEY so we directly reuse Constants.TIMEOUT_KEY for now
    HttpConnectionParams.setConnectionTimeout(params,
            url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
    HttpConnectionParams.setSoTimeout(params,
            url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
    HttpConnectionParams.setTcpNoDelay(params, true);
    HttpConnectionParams.setSoKeepalive(params, true);

    ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/* , localContext */);

    ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
    clients.add(client);

    client.register(RpcContextFilter.class);
    for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) {
        if (!StringUtils.isEmpty(clazz)) {
            try {
                client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim()));
            } catch (ClassNotFoundException e) {
                throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e);
            }
        }
    }

    // dubbo ?
    String version = url.getParameter(Constants.VERSION_KEY);
    String versionPath = "";
    if (StringUtils.isNotEmpty(version)) {
        versionPath = version + "/";
    }
    // TODO protocol
    ResteasyWebTarget target = client
            .target("http://" + url.getHost() + ":" + url.getPort() + "/" + versionPath + getContextPath(url));
    return target.proxy(serviceType);
}