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

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

Introduction

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

Prototype

public HostConfiguration() 

Source Link

Usage

From source file:com.trendmicro.hdfs.webdav.test.MiniClusterTestUtil.java

public HttpClient getClient() {
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost("localhost");
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setMaxConnectionsPerHost(hostConfig, 100);
    connectionManager.setParams(params);
    HttpClient client = new HttpClient(connectionManager);
    client.setHostConfiguration(hostConfig);
    return client;
}

From source file:com.twinsoft.convertigo.beans.connectors.HttpConnector.java

public HttpConnector() {
    super();

    certificateManager = new CertificateManager();

    hostConfiguration = new HostConfiguration();
}

From source file:com.autentia.mvn.plugin.changes.BugzillaChangesMojo.java

public void execute() throws MojoExecutionException, MojoFailureException {

    this.getLog().debug("Entering.");
    this.getLog().info("Component:" + this.componentName);

    // si el informe el solo para el padre y es un hijo salimos
    // si es un hijo y no est definido el component salimos
    if (isParentProject() || (parentOnly && isEmpty(componentName))) {
        return;//  w  w w  . jav  a  2  s . com
    }

    versionName = getVersionNameFromProject();

    // inicializamos el gestor de peticiones
    this.httpRequest = new HttpRequest(this.getLog());

    // inicializamos la url del Bugzilla
    this.bugzillaUrl = this.project.getIssueManagement().getUrl();

    // preparamos el cliente HTTP para las peticiones
    final HttpClient client = new HttpClient();
    final HttpClientParams clientParams = client.getParams();
    clientParams.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
    final HttpState state = new HttpState();
    final HostConfiguration hc = new HostConfiguration();
    client.setHostConfiguration(hc);
    client.setState(state);
    this.determineProxy(client);

    if (!performLogin(client)) {
        throw new MojoExecutionException(
                "The username or password you entered is not valid. Cannot login in Bugzilla: " + bugzillaUrl);
    }

    final String bugsIds = this.getBugList(client);
    final Document bugsDocument = this.getBugsDocument(client, bugsIds);
    builChangesXML(bugsDocument);

    this.getLog().debug("Exiting.");
}

From source file:com.springsource.insight.plugin.apache.http.hc3.HttpClientExecutionCollectionAspectTest.java

private void runExecuteHostMethodTest(String testName, HttpState state) throws Exception {
    HttpHost host = new HttpHost("localhost", TEST_PORT);
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost(host);/*from w  w w.jav  a  2 s  .co m*/
    runExecuteMethodTest(testName, hostConfig, state);
}

From source file:com.amazonaws.elasticmapreduce.AmazonElasticMapReduceClient.java

/**
 * Configure HttpClient with set of defaults as well as configuration
 * from AmazonElasticMapReduceConfig instance
 *
 *//*from   www  .j a v a 2  s . c  om*/
private HttpClient configureHttpClient() {

    /* Set http client parameters */
    HttpClientParams httpClientParams = new HttpClientParams();
    httpClientParams.setParameter(HttpMethodParams.USER_AGENT, config.getUserAgent());
    httpClientParams.setParameter(HttpClientParams.RETRY_HANDLER, new HttpMethodRetryHandler() {

        public boolean retryMethod(HttpMethod method, IOException exception, int executionCount) {
            if (executionCount > 3) {
                log.debug("Maximum Number of Retry attempts reached, will not retry");
                return false;
            }
            log.debug("Retrying request. Attempt " + executionCount);
            if (exception instanceof NoHttpResponseException) {
                log.debug("Retrying on NoHttpResponseException");
                return true;
            }
            if (exception instanceof InterruptedIOException) {
                log.debug("Will not retry on InterruptedIOException", exception);
                return false;
            }
            if (exception instanceof UnknownHostException) {
                log.debug("Will not retry on UnknownHostException", exception);
                return false;
            }
            if (!method.isRequestSent()) {
                log.debug("Retrying on failed sent request");
                return true;
            }
            return false;
        }
    });

    /* Set host configuration */
    HostConfiguration hostConfiguration = new HostConfiguration();

    /* Set connection manager parameters */
    HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams();
    connectionManagerParams.setConnectionTimeout(50000);
    connectionManagerParams.setSoTimeout(50000);
    connectionManagerParams.setStaleCheckingEnabled(true);
    connectionManagerParams.setTcpNoDelay(true);
    connectionManagerParams.setMaxTotalConnections(config.getMaxConnections());
    connectionManagerParams.setMaxConnectionsPerHost(hostConfiguration, config.getMaxConnections());

    /* Set connection manager */
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(connectionManagerParams);

    /* Set http client */
    httpClient = new HttpClient(httpClientParams, connectionManager);

    /* Set proxy if configured */
    if (config.isSetProxyHost() && config.isSetProxyPort()) {
        log.info("Configuring Proxy. Proxy Host: " + config.getProxyHost() + "Proxy Port: "
                + config.getProxyPort());
        hostConfiguration.setProxy(config.getProxyHost(), config.getProxyPort());
        if (config.isSetProxyUsername() && config.isSetProxyPassword()) {
            httpClient.getState().setProxyCredentials(
                    new AuthScope(config.getProxyHost(), config.getProxyPort()),
                    new UsernamePasswordCredentials(config.getProxyUsername(), config.getProxyPassword()));

        }
    }

    httpClient.setHostConfiguration(hostConfiguration);
    return httpClient;
}

From source file:com.twinsoft.convertigo.beans.connectors.HttpConnector.java

@Override
public HttpConnector clone() throws CloneNotSupportedException {
    HttpConnector clonedObject = (HttpConnector) super.clone();
    clonedObject.httpStateListeners = new EventListenerList();
    clonedObject.sUrl = "";
    clonedObject.handleCookie = true;//from w w w.ja va  2s. c o m
    clonedObject.httpParameters = new XMLVector<XMLVector<String>>();
    clonedObject.postQuery = "";

    clonedObject.certificateManager = new CertificateManager();

    clonedObject.hostConfiguration = new HostConfiguration();
    clonedObject.givenAuthPassword = null;
    clonedObject.givenAuthUser = null;

    return clonedObject;
}

From source file:de.juwimm.cms.common.http.HttpClientWrapper.java

public void setHostConfiguration(HttpClient client, URL targetURL) {
    int port = targetURL.getPort();
    String host = targetURL.getHost();
    HostConfiguration config = hostMap.get(host + ":" + port);
    if (config == null) {
        config = new HostConfiguration();
        if (port == -1) {
            if (targetURL.getProtocol().equalsIgnoreCase("https")) {
                port = 443;/*from   w w  w.jav  a 2  s  .  com*/
            } else {
                port = 80;
            }
        }
        config.setHost(host, port, targetURL.getProtocol());
    }
    // in the meantime HttpProxyUser and HttpProxyPasword might have changed
    // (DlgUsernamePassword) or now trying NTLM instead of BASE
    // authentication
    if (getHttpProxyHost() != null && getHttpProxyPort() != null && getHttpProxyHost().length() > 0
            && getHttpProxyPort().length() > 0) {
        client.getParams().setAuthenticationPreemptive(true);
        int proxyPort = new Integer(getHttpProxyPort()).intValue();
        config.setProxy(getHttpProxyHost(), proxyPort);
        if (getHttpProxyUser() != null && getHttpProxyUser().length() > 0) {
            Credentials proxyCred = null;
            if (isUseNTproxy()) {
                proxyCred = new NTCredentials(getHttpProxyUser(), getHttpProxyPassword(), getHttpProxyHost(),
                        "");
            } else {
                proxyCred = new UsernamePasswordCredentials(getHttpProxyUser(), getHttpProxyPassword());
            }
            client.getState().setProxyCredentials(AUTHSCOPE_ANY, proxyCred);

        }
    }
    hostMap.put(host + ":" + port, config);
    client.setHostConfiguration(config);

}

From source file:com.liferay.portal.util.HttpImpl.java

public HostConfiguration getHostConfiguration(String location) throws IOException {

    if (_log.isDebugEnabled()) {
        _log.debug("Location is " + location);
    }/*from w w  w  .  j  a  va 2 s.c o  m*/

    HostConfiguration hostConfiguration = new HostConfiguration();

    hostConfiguration.setHost(new URI(location, false));

    if (isProxyHost(hostConfiguration.getHost())) {
        hostConfiguration.setProxy(_PROXY_HOST, _PROXY_PORT);
    }

    HttpConnectionManager httpConnectionManager = _httpClient.getHttpConnectionManager();

    HttpConnectionManagerParams httpConnectionManagerParams = httpConnectionManager.getParams();

    int defaultMaxConnectionsPerHost = httpConnectionManagerParams.getMaxConnectionsPerHost(hostConfiguration);

    int maxConnectionsPerHost = GetterUtil.getInteger(PropsUtil.get(
            HttpImpl.class.getName() + ".max.connections.per.host", new Filter(hostConfiguration.getHost())));

    if ((maxConnectionsPerHost > 0) && (maxConnectionsPerHost != defaultMaxConnectionsPerHost)) {

        httpConnectionManagerParams.setMaxConnectionsPerHost(hostConfiguration, maxConnectionsPerHost);
    }

    int timeout = GetterUtil.getInteger(
            PropsUtil.get(HttpImpl.class.getName() + ".timeout", new Filter(hostConfiguration.getHost())));

    if (timeout > 0) {
        HostParams hostParams = hostConfiguration.getParams();

        hostParams.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, timeout);
        hostParams.setIntParameter(HttpConnectionParams.SO_TIMEOUT, timeout);
    }

    return hostConfiguration;
}

From source file:com.legstar.http.client.CicsHttp.java

/**
 * Create an http host configuration using the protocol/host/port triple.
 * @param cicsHttpEndpoint the connection configuration
 * @return a valid host configuration/*  w w w .  j  a  v  a  2s.c  o m*/
 */
protected HostConfiguration createHostConfiguration(final CicsHttpEndpoint cicsHttpEndpoint) {
    HostConfiguration hostConfiguration = new HostConfiguration();
    hostConfiguration.setHost(cicsHttpEndpoint.getHostIPAddress(), cicsHttpEndpoint.getHostIPPort(),
            cicsHttpEndpoint.getHostURLProtocol());
    /* TODO add proxy handling */
    return hostConfiguration;
}

From source file:com.xerox.amazonws.common.AWSQueryConnection.java

private void configureHttpClient() {
    MultiThreadedHttpConnectionManager connMgr = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams connParams = connMgr.getParams();
    connParams.setMaxTotalConnections(maxConnections);
    connParams.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, maxConnections);
    connMgr.setParams(connParams);//from  w  ww.  j  a va2  s.  c  o m
    hc = new HttpClient(connMgr);
    // NOTE: These didn't seem to help in my initial testing
    //         hc.getParams().setParameter("http.tcp.nodelay", true);
    //         hc.getParams().setParameter("http.connection.stalecheck", false); 
    if (proxyHost != null) {
        HostConfiguration hostConfig = new HostConfiguration();
        hostConfig.setProxy(proxyHost, proxyPort);
        hc.setHostConfiguration(hostConfig);
        log.info("Proxy Host set to " + proxyHost + ":" + proxyPort);
        if (proxyUser != null && !proxyUser.trim().equals("")) {
            if (proxyDomain != null) {
                hc.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort),
                        new NTCredentials(proxyUser, proxyPassword, proxyHost, proxyDomain));
            } else {
                hc.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort),
                        new UsernamePasswordCredentials(proxyUser, proxyPassword));
            }
        }
    }
}