Example usage for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager

List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager

Introduction

In this page you can find the example usage for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager.

Prototype

public MultiThreadedHttpConnectionManager() 

Source Link

Usage

From source file:org.jasig.portal.security.provider.SamlAssertionFilter.java

@Override
protected void initFilterBean() throws ServletException {
    this.connectionManager = new MultiThreadedHttpConnectionManager();
    final HttpConnectionManagerParams params = this.connectionManager.getParams();
    params.setMaxTotalConnections(this.maxTotalConnections);
    params.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, this.maxTotalConnections);
    params.setConnectionTimeout(this.connectionTimeout);
    params.setSoTimeout(this.readTimeout);

    this.httpClient = new HttpClient(this.connectionManager);
}

From source file:org.jasig.portal.services.MultiThreadedHttpConnectionManagerFactoryBean.java

@Override
protected MultiThreadedHttpConnectionManager createInstance() throws Exception {
    final MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager();

    final HttpConnectionManagerParams pars = multiThreadedHttpConnectionManager.getParams();
    pars.setConnectionTimeout(this.connectionTimeout);
    pars.setSoTimeout(this.soTimeout);
    pars.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
    pars.setMaxTotalConnections(this.maxTotalConnections);
    pars.setDefaultMaxConnectionsPerHost(this.defaultMaxConnectionsPerHost);

    return multiThreadedHttpConnectionManager;
}

From source file:org.jasig.portlet.calendar.adapter.exchange.ExchangeHttpWebServiceMessageSender.java

public void afterPropertiesSet() throws Exception {
    // create a new connection manager with the configured connection parameters
    this.connectionManager = new MultiThreadedHttpConnectionManager();
    this.connectionManager.getParams().setConnectionTimeout(connectionTimeout);
    this.connectionManager.getParams().setSoTimeout(readTimeout);
    this.connectionManager.getParams().setDefaultMaxConnectionsPerHost(maxConnections);
    this.connectionManager.getParams().setMaxTotalConnections(maxConnections);
}

From source file:org.jboss.test.cluster.defaultcfg.web.test.CleanShutdownTestCase.java

/**
 * @see org.jboss.test.JBossClusteredTestCase#setUp()
 *//*from  w  ww. j  a v  a2 s  .  c  o  m*/
@Override
protected void setUp() throws Exception {
    super.setUp();

    this.name = ObjectName.getInstance(SERVER_NAME);
    this.server = this.getAdaptors()[0];
    this.baseURL = this.getHttpURLs()[0];

    this.manager = new MultiThreadedHttpConnectionManager();

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(MAX_THREADS);
    params.setMaxTotalConnections(MAX_THREADS);

    this.manager.setParams(params);

    this.client = new HttpClient();
}

From source file:org.jboss.web.loadbalancer.Loadbalancer.java

protected Loadbalancer(Element config) throws ServletException {
    try {/*from   w  w w  . j  a  v  a 2  s.c o  m*/
        schedulerName = new ObjectName(MetaData.getUniqueChildContent(config, "scheduler-name"));

        String schedulerClassName = MetaData.getUniqueChildContent(config, "scheduler-class-name");

        try {
            scheduler = (Scheduler) Thread.currentThread().getContextClassLoader().loadClass(schedulerClassName)
                    .newInstance();
            scheduler.init(config);
        } catch (Exception e) {
            log.error("Could not create scheduler", e);
            throw new ServletException(e);
        }
        try {
            connectionTimeout = Integer.parseInt(MetaData.getUniqueChildContent(config, "connection-timeout"));

            log.debug("Setting connection timeout to " + connectionTimeout);
        } catch (NumberFormatException ex) {
            log.warn("Cannot read connection timeout value. Using default connection timeout");
            //ignore -> use default
        }
    } catch (Exception ex) {
        log.error("Could not read config " + config, ex);
        throw new ServletException(ex);
    }
    connectionManager = new MultiThreadedHttpConnectionManager();

    // We disable this because the web-container limits the maximum connection count anyway
    connectionManager.setMaxConnectionsPerHost(Integer.MAX_VALUE);
    connectionManager.setMaxTotalConnections(Integer.MAX_VALUE);
}

From source file:org.jetbrains.jet.jvm.compiler.longTest.ResolveDescriptorsFromExternalLibraries.java

private File getFileFromUrl(@NotNull String lib, @NotNull File file, @NotNull String uri) throws IOException {
    if (file.exists()) {
        return file;
    }/*from   w  ww .  j a  v a 2s  . c o  m*/

    JetTestUtils.mkdirs(file.getParentFile());

    File tmp = new File(file.getPath() + "~");

    GetMethod method = new GetMethod(uri);

    FileOutputStream os = null;

    System.out.println("Downloading library " + lib + " to " + file);

    MultiThreadedHttpConnectionManager connectionManager = null;
    try {
        connectionManager = new MultiThreadedHttpConnectionManager();
        HttpClient httpClient = new HttpClient(connectionManager);
        os = new FileOutputStream(tmp);
        String userAgent = ResolveDescriptorsFromExternalLibraries.class.getName() + "/commons-httpclient";
        method.getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent);
        int code = httpClient.executeMethod(method);
        if (code != 200) {
            throw new RuntimeException("failed to execute GET " + uri + ", code is " + code);
        }
        InputStream responseBodyAsStream = method.getResponseBodyAsStream();
        if (responseBodyAsStream == null) {
            throw new RuntimeException("method is executed fine, but response is null");
        }
        ByteStreams.copy(responseBodyAsStream, os);
        os.close();
        if (!tmp.renameTo(file)) {
            throw new RuntimeException("failed to rename file: " + tmp + " to " + file);
        }
        return file;
    } finally {
        if (method != null) {
            try {
                method.releaseConnection();
            } catch (Throwable e) {
            }
        }
        if (connectionManager != null) {
            try {
                connectionManager.shutdown();
            } catch (Throwable e) {
            }
        }
        if (os != null) {
            try {
                os.close();
            } catch (Throwable e) {
            }
        }
        tmp.delete();
    }
}

From source file:org.jetbrains.kotlin.jvm.compiler.longTest.ResolveDescriptorsFromExternalLibraries.java

private static File getFileFromUrl(@NotNull String lib, @NotNull File file, @NotNull String uri)
        throws IOException {
    if (file.exists()) {
        return file;
    }/*from  w ww.  j  a v  a2 s .co  m*/

    KotlinTestUtils.mkdirs(file.getParentFile());

    File tmp = new File(file.getPath() + "~");

    GetMethod method = new GetMethod(uri);

    FileOutputStream os = null;

    System.out.println("Downloading library " + lib + " to " + file);

    MultiThreadedHttpConnectionManager connectionManager = null;
    try {
        connectionManager = new MultiThreadedHttpConnectionManager();
        HttpClient httpClient = new HttpClient(connectionManager);
        os = new FileOutputStream(tmp);
        String userAgent = ResolveDescriptorsFromExternalLibraries.class.getName() + "/commons-httpclient";
        method.getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent);
        int code = httpClient.executeMethod(method);
        if (code != 200) {
            throw new RuntimeException("failed to execute GET " + uri + ", code is " + code);
        }
        InputStream responseBodyAsStream = method.getResponseBodyAsStream();
        if (responseBodyAsStream == null) {
            throw new RuntimeException("method is executed fine, but response is null");
        }
        ByteStreams.copy(responseBodyAsStream, os);
        os.close();
        if (!tmp.renameTo(file)) {
            throw new RuntimeException("failed to rename file: " + tmp + " to " + file);
        }
        return file;
    } finally {
        try {
            method.releaseConnection();
        } catch (Throwable e) {
        }
        if (connectionManager != null) {
            try {
                connectionManager.shutdown();
            } catch (Throwable e) {
            }
        }
        if (os != null) {
            try {
                os.close();
            } catch (Throwable e) {
            }
        }
        tmp.delete();
    }
}

From source file:org.jivesoftware.openfire.crowd.CrowdManager.java

private CrowdManager() {
    try {//  www  .j  a v  a  2 s.c  o  m
        // loading crowd.properties file
        CrowdProperties crowdProps = new CrowdProperties();

        MultiThreadedHttpConnectionManager threadedConnectionManager = new MultiThreadedHttpConnectionManager();
        HttpClient hc = new HttpClient(threadedConnectionManager);

        HttpClientParams hcParams = hc.getParams();
        hcParams.setAuthenticationPreemptive(true);

        HttpConnectionManagerParams hcConnectionParams = hc.getHttpConnectionManager().getParams();
        hcConnectionParams.setDefaultMaxConnectionsPerHost(crowdProps.getHttpMaxConnections());
        hcConnectionParams.setMaxTotalConnections(crowdProps.getHttpMaxConnections());
        hcConnectionParams.setConnectionTimeout(crowdProps.getHttpConnectionTimeout());
        hcConnectionParams.setSoTimeout(crowdProps.getHttpSocketTimeout());

        crowdServer = new URI(crowdProps.getCrowdServerUrl()).resolve("rest/usermanagement/latest/");

        // setting BASIC authentication in place for connection with Crowd
        HttpState httpState = hc.getState();
        Credentials crowdCreds = new UsernamePasswordCredentials(crowdProps.getApplicationName(),
                crowdProps.getApplicationPassword());
        httpState.setCredentials(new AuthScope(crowdServer.getHost(), crowdServer.getPort()), crowdCreds);

        // setting Proxy config in place if needed
        if (StringUtils.isNotBlank(crowdProps.getHttpProxyHost()) && crowdProps.getHttpProxyPort() > 0) {
            hc.getHostConfiguration().setProxy(crowdProps.getHttpProxyHost(), crowdProps.getHttpProxyPort());

            if (StringUtils.isNotBlank(crowdProps.getHttpProxyUsername())
                    || StringUtils.isNotBlank(crowdProps.getHttpProxyPassword())) {
                Credentials proxyCreds = new UsernamePasswordCredentials(crowdProps.getHttpProxyUsername(),
                        crowdProps.getHttpProxyPassword());
                httpState.setProxyCredentials(
                        new AuthScope(crowdProps.getHttpProxyHost(), crowdProps.getHttpProxyPort()),
                        proxyCreds);
            }
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug("HTTP Client config");
            LOG.debug(crowdServer.toString());
            LOG.debug("Max connections:" + hcConnectionParams.getMaxTotalConnections());
            LOG.debug("Socket timeout:" + hcConnectionParams.getSoTimeout());
            LOG.debug("Connect timeout:" + hcConnectionParams.getConnectionTimeout());
            LOG.debug("Proxy host:" + crowdProps.getHttpProxyHost() + ":" + crowdProps.getHttpProxyPort());
            LOG.debug("Crowd application name:" + crowdProps.getApplicationName());
        }

        client = hc;
    } catch (Exception e) {
        LOG.error("Failure to load the Crowd manager", e);
    }
}

From source file:org.kchine.r.server.http.applets.SupervisorApplet.java

@Override
public void init() {
    super.init();
    getContentPane().setLayout(new BorderLayout());
    try {//ww w.ja v  a  2  s. c o m
        HashMap<String, Object> options = new HashMap<String, Object>();
        final String sessionId = RHttpProxy.logOnDB(getParameter("url"), "", getParameter("login"),
                getParameter("password"), options);
        DBLayerInterface db = (DBLayerInterface) RHttpProxy.getDynamicProxy(getParameter("url"), sessionId,
                "REGISTRY", new Class<?>[] { DBLayerInterface.class },
                new HttpClient(new MultiThreadedHttpConnectionManager()));
        SupervisorInterface supervisorInterface = (SupervisorInterface) RHttpProxy.getDynamicProxy(
                getParameter("url"), sessionId, "SUPERVISOR", new Class<?>[] { SupervisorInterface.class },
                new HttpClient(new MultiThreadedHttpConnectionManager()));
        getContentPane().add(new Supervisor(db, supervisorInterface).getPanel());
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:org.kchine.r.server.http.DBHttpProxy.java

public Registry getRegistry() throws Exception {
    HashMap<String, Object> options = new HashMap<String, Object>();
    final String sessionId = RHttpProxy.logOnDB(System.getProperty("dbhttp.url"), "",
            System.getProperty("dbhttp.login"), System.getProperty("dbhttp.password"), options);
    DBLayerInterface db = (DBLayerInterface) RHttpProxy.getDynamicProxy(System.getProperty("dbhttp.url"),
            sessionId, "REGISTRY", new Class<?>[] { DBLayerInterface.class },
            new HttpClient(new MultiThreadedHttpConnectionManager()));
    return db;//from ww w  .j  av  a 2s  .c  o m
}