Example usage for org.apache.commons.httpclient.params HttpConnectionManagerParams HttpConnectionManagerParams

List of usage examples for org.apache.commons.httpclient.params HttpConnectionManagerParams HttpConnectionManagerParams

Introduction

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

Prototype

HttpConnectionManagerParams

Source Link

Usage

From source file:org.opensaml.ws.soap.client.http.HttpClientBuilder.java

/**
 * Builds an HTTP client with the given settings. Settings are NOT reset to their default values after a client has
 * been created.//from www .  ja v  a2  s  .  com
 * 
 * @return the created client.
 */
public HttpClient buildClient() {
    if (httpsProtocolSocketFactory != null) {
        Protocol.registerProtocol("https", new Protocol("https", httpsProtocolSocketFactory, 443));
    }

    HttpClientParams clientParams = new HttpClientParams();
    clientParams.setAuthenticationPreemptive(isPreemptiveAuthentication());
    clientParams.setContentCharset(getContentCharSet());
    clientParams.setParameter(HttpClientParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(connectionRetryAttempts, false));

    HttpConnectionManagerParams connMgrParams = new HttpConnectionManagerParams();
    connMgrParams.setConnectionTimeout(getConnectionTimeout());
    connMgrParams.setDefaultMaxConnectionsPerHost(getMaxConnectionsPerHost());
    connMgrParams.setMaxTotalConnections(getMaxTotalConnections());
    connMgrParams.setReceiveBufferSize(getReceiveBufferSize());
    connMgrParams.setSendBufferSize(getSendBufferSize());
    connMgrParams.setTcpNoDelay(isTcpNoDelay());

    MultiThreadedHttpConnectionManager connMgr = new MultiThreadedHttpConnectionManager();
    connMgr.setParams(connMgrParams);

    HttpClient httpClient = new HttpClient(clientParams, connMgr);

    if (proxyHost != null) {
        HostConfiguration hostConfig = new HostConfiguration();
        hostConfig.setProxy(proxyHost, proxyPort);
        httpClient.setHostConfiguration(hostConfig);

        if (proxyUsername != null) {
            AuthScope proxyAuthScope = new AuthScope(proxyHost, proxyPort);
            UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials(proxyUsername,
                    proxyPassword);
            httpClient.getState().setProxyCredentials(proxyAuthScope, proxyCredentials);
        }
    }

    return httpClient;
}

From source file:org.opensaml.ws.soap.client.HTTPSOAPTransportFactory.java

/**
 * Initializes the {@link HttpClient} that will be used by the created {@link HTTPSOAPTransport} built by this
 * factory./*from ww w .  jav  a  2s. com*/
 */
protected void initializeHttpClient() {
    HttpConnectionManagerParams connectionParams = new HttpConnectionManagerParams();
    connectionParams.setConnectionTimeout(connectionTimeout);

    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(connectionParams);

    HttpClientParams clientParams = new HttpClientParams();
    clientParams.setSoTimeout(socketTimeout);
    if (httpVersion == HTTP_VERSION.HTTP1_0) {
        clientParams.setVersion(HttpVersion.HTTP_1_0);
    } else {
        clientParams.setVersion(HttpVersion.HTTP_1_1);
    }

    httpClient = new HttpClient(clientParams, connectionManager);
}

From source file:org.parosproxy.paros.core.proxy.WebSocketsConnectionIntegrationTest.java

@Test
public void getAutobahnCaseCount() throws HttpException {
    // use HTTP-client with custom connection manager
    // that allows us to expose the SocketChannel

    HttpConnectionManagerParams connectionParams = new HttpConnectionManagerParams();
    connectionParams.setTcpNoDelay(true);
    connectionParams.setStaleCheckingEnabled(false);
    connectionParams.setSoTimeout(500);//  w ww .  java  2 s. c  o  m

    ZapHttpConnectionManager connectionManager = new ZapHttpConnectionManager();
    connectionManager.setParams(connectionParams);

    HttpClient client = new HttpClient(connectionManager);
    client.getHostConfiguration().setProxy(PROXY_HOST, PROXY_PORT);

    // create minimal HTTP handshake request
    ZapGetMethod method = new ZapGetMethod("http://localhost:9001/getCaseCount");
    method.addRequestHeader("Connection", "upgrade");
    method.addRequestHeader("Upgrade", "websocket");
    method.addRequestHeader("Sec-WebSocket-Version", "13");
    method.addRequestHeader("Sec-WebSocket-Key", "5d5NazNjJ5hafSgFYJ7SOw==");
    try {
        client.executeMethod(method);
    } catch (IOException e) {
        assertTrue("executing HTTP method failed", false);
    }

    assertEquals("HTTP status code of WebSockets-handshake response should be 101.", 101,
            method.getStatusCode());

    InputStream remoteInput = method.getUpgradedInputStream();

    byte[] caseCountFrame = new byte[3];
    int readBytes = 0;

    try {
        readBytes = remoteInput.read(caseCountFrame);
    } catch (IOException e) {
        assertTrue("reading websocket frame failed", false);
    }

    assertEquals("Expected some bytes in the first frame.", 3, readBytes);
    assertEquals("First WebSocket frame is text message with the case count.", 0x1, caseCountFrame[0] & 0x0f);

    byte[] closeFrame = new byte[2];
    readBytes = 0;
    try {
        readBytes = remoteInput.read(closeFrame);
    } catch (IOException e) {
        assertTrue("reading websocket frame failed: " + e.getMessage(), false);
    }

    assertEquals("Expected some bytes in the second frame.", 2, readBytes);

    assertEquals("Second WebSocket frame is a close message.", 0x8, closeFrame[0] & 0x0f);

    // now I would send back a close frame and close the physical socket connection
}

From source file:org.sakaiproject.kernel.proxy.ProxyClientServiceImpl.java

/**
 * Create resources used by this component.
 * /*from  w w  w  . j  ava  2  s. co  m*/
 * @param ctx
 * @throws Exception
 */
public void activate(ComponentContext ctx) throws Exception {
    velocityEngine = new VelocityEngine();
    velocityEngine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, new VelocityLogger(this.getClass()));

    velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, JCR_RESOURCE_LOADER);
    velocityEngine.setProperty(JCR_RESOURCE_LOADER_CLASS, JcrResourceLoader.class.getName());
    ExtendedProperties configuration = new ExtendedProperties();
    configuration.addProperty(JCR_RESOURCE_LOADER_PATH + ProxyNodeSource.JCR_RESOURCE_LOADER_RESOURCE_SOURCE,
            this);
    velocityEngine.setExtendedProperties(configuration);
    velocityEngine.init();

    httpClientConnectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    // could set a whole load of connection properties
    httpClientConnectionManager.setParams(params);

    httpClient = new HttpClient(httpClientConnectionManager);
}

From source file:org.sakaiproject.nakamura.proxy.ProxyClientServiceImpl.java

/**
 * Create resources used by this component.
 *
 * @param ctx/* ww w  .j  a  v  a  2 s  .c om*/
 * @throws Exception
 */
@SuppressWarnings("unchecked")
protected void activate(ComponentContext ctx) throws Exception {
    if (ctx != null) {
        Dictionary<String, Object> props = ctx.getProperties();
        configProperties = new HashMap<String, Object>();
        for (Enumeration<String> e = props.keys(); e.hasMoreElements();) {
            String k = e.nextElement();
            configProperties.put(k, props.get(k));
        }
        String[] safePostProcessorNames = (String[]) configProperties.get(SAFE_POSTPROCESSORS);
        if (safePostProcessorNames == null) {
            safeOpenProcessors.add("rss");
            safeOpenProcessors.add("trustedLoginTokenProxyPostProcessor");
        } else {
            for (String pp : safePostProcessorNames) {
                safeOpenProcessors.add(pp);
            }
        }
    } else {
        configProperties = new HashMap<String, Object>();
    }
    velocityEngine = new VelocityEngine();
    velocityEngine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, new VelocityLogger(this.getClass()));

    velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, JCR_RESOURCE_LOADER);
    velocityEngine.setProperty(JCR_RESOURCE_LOADER_CLASS, JcrResourceLoader.class.getName());
    ExtendedProperties configuration = new ExtendedProperties();
    configuration.addProperty(JCR_RESOURCE_LOADER_PATH + ProxyNodeSource.JCR_RESOURCE_LOADER_RESOURCE_SOURCE,
            this);
    velocityEngine.setExtendedProperties(configuration);
    velocityEngine.init();

    httpClientConnectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    // could set a whole load of connection properties
    httpClientConnectionManager.setParams(params);

    httpClient = new HttpClient(httpClientConnectionManager);

    // allow communications via a proxy server if command line
    // java parameters http.proxyHost,http.proxyPort,http.proxyUser,
    // http.proxyPassword have been provided.
    externalAuthenticatingProxy = false;
    String proxyHost = System.getProperty("http.proxyHost", "");
    int proxyPort = Integer.parseInt(System.getProperty("http.proxyPort", "80"));
    if (!proxyHost.equals("")) {
        // allow communications via a non-authenticating proxy
        httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);

        String proxyUser = System.getProperty("http.proxyUser", "");
        String proxyPassword = System.getProperty("http.proxyPassword", "");
        if (!proxyUser.equals("")) {
            // allow communications via an authenticating proxy
            Credentials credentials = new UsernamePasswordCredentials(proxyUser, proxyPassword);
            AuthScope authScope = new AuthScope(proxyHost, proxyPort);
            httpClient.getState().setProxyCredentials(authScope, credentials);
            externalAuthenticatingProxy = true;
        }
    }
}

From source file:org.sonar.wsclient.connectors.HttpClient3Connector.java

private void createClient() {
    final HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setConnectionTimeout(AbstractQuery.DEFAULT_TIMEOUT_MILLISECONDS);
    params.setSoTimeout(AbstractQuery.DEFAULT_TIMEOUT_MILLISECONDS);
    params.setDefaultMaxConnectionsPerHost(MAX_HOST_CONNECTIONS);
    params.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
    final MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    this.httpClient = new HttpClient(connectionManager);
    configureCredentials();/*from   w  w w  .j  a v a  2s .  co m*/
}

From source file:org.sonar.wsclient.WSClientFactory.java

/**
 * @see org.sonar.wsclient.connectors.HttpClient3Connector#createClient()
 *///w  ww  .  java 2  s  . c om
private static HttpClient createHttpClient() {
    final HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setConnectionTimeout(TIMEOUT_MS);
    params.setSoTimeout(TIMEOUT_MS);
    params.setDefaultMaxConnectionsPerHost(MAX_HOST_CONNECTIONS);
    params.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
    final MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return new HttpClient(connectionManager);
}

From source file:org.wso2.carbon.andes.authentication.andes.oauth.OAuthTokenValidaterStubFactory.java

/**
 * This created httpclient pool that can be used to connect to external entity. This connection can be configured
 * via broker.xml by setting up the required http connection parameters.
 * @return an instance of HttpClient that is configured with MultiThreadedHttpConnectionManager
 *///from   w w w.  ja  va  2 s  .c o  m
private HttpClient createHttpClient() {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(config.getMaximumHttpConnectionPerHost());
    params.setMaxTotalConnections(config.getMaximumTotalHttpConnection());
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return new HttpClient(connectionManager);
}

From source file:org.wso2.carbon.automation.test.utils.axis2client.ConfigurationContextProvider.java

private ConfigurationContextProvider() {
    try {// w w  w. ja  va2s.  c o m
        MultiThreadedHttpConnectionManager httpConnectionManager;
        HttpClient httpClient;
        HttpConnectionManagerParams params;
        configurationContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(
                FrameworkPathUtil.getSystemResourceLocation() + File.separator + "client", null);
        httpConnectionManager = new MultiThreadedHttpConnectionManager();
        params = new HttpConnectionManagerParams();
        params.setDefaultMaxConnectionsPerHost(25);
        httpConnectionManager.setParams(params);
        httpClient = new HttpClient(httpConnectionManager);
        configurationContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
        configurationContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE);
    } catch (AxisFault axisFault) {
        log.error(axisFault);
    }
}

From source file:org.wso2.carbon.core.init.CarbonServerManager.java

private ConfigurationContext getClientConfigurationContext() throws AxisFault {
    String clientRepositoryLocation = serverConfig.getFirstProperty(CLIENT_REPOSITORY_LOCATION);
    String clientAxis2XmlLocationn = serverConfig.getFirstProperty(CLIENT_AXIS2_XML_LOCATION);
    ConfigurationContext clientConfigContextToReturn = ConfigurationContextFactory
            .createConfigurationContextFromFileSystem(clientRepositoryLocation, clientAxis2XmlLocationn);
    MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();

    // Set the default max connections per host
    int defaultMaxConnPerHost = 500;
    Parameter defaultMaxConnPerHostParam = clientConfigContextToReturn.getAxisConfiguration()
            .getParameter("defaultMaxConnPerHost");
    if (defaultMaxConnPerHostParam != null) {
        defaultMaxConnPerHost = Integer.parseInt((String) defaultMaxConnPerHostParam.getValue());
    }/* ww  w  .  j  ava  2 s  .  c om*/
    params.setDefaultMaxConnectionsPerHost(defaultMaxConnPerHost);

    // Set the max total connections
    int maxTotalConnections = 15000;
    Parameter maxTotalConnectionsParam = clientConfigContextToReturn.getAxisConfiguration()
            .getParameter("maxTotalConnections");
    if (maxTotalConnectionsParam != null) {
        maxTotalConnections = Integer.parseInt((String) maxTotalConnectionsParam.getValue());
    }
    params.setMaxTotalConnections(maxTotalConnections);

    params.setSoTimeout(600000);
    params.setConnectionTimeout(600000);

    httpConnectionManager.setParams(params);
    clientConfigContextToReturn.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER,
            httpConnectionManager);
    registerHouseKeepingTask(clientConfigContextToReturn);
    clientConfigContextToReturn.setProperty(ServerConstants.WORK_DIR, serverWorkDir);
    return clientConfigContextToReturn;
}