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

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

Introduction

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

Prototype

public void setHost(String paramString, int paramInt)

Source Link

Usage

From source file:fr.dutra.confluence2wordpress.xmlrpc.CommonsXmlRpcTransportFactory.java

public CommonsXmlRpcTransportFactory(URL url, String proxyHost, int proxyPort, int maxConnections) {
    this.url = url;
    HostConfiguration hostConf = new HostConfiguration();
    hostConf.setHost(url.getHost(), url.getPort());
    if (proxyHost != null && proxyPort != -1) {
        hostConf.setProxy(proxyHost, proxyPort);
    }/*from w  ww  . j av a  2s .com*/
    HttpConnectionManagerParams connParam = new HttpConnectionManagerParams();
    connParam.setMaxConnectionsPerHost(hostConf, maxConnections);
    connParam.setMaxTotalConnections(maxConnections);
    MultiThreadedHttpConnectionManager conMgr = new MultiThreadedHttpConnectionManager();
    conMgr.setParams(connParam);
    client = new HttpClient(conMgr);
    client.setHostConfiguration(hostConf);
}

From source file:com.taobao.metamorphosis.client.http.SimpleHttpClient.java

protected void initHttpClient(HttpClientConfig config) {
    HostConfiguration hostConfiguration = new HostConfiguration();
    hostConfiguration.setHost(config.getHost(), config.getPort());

    connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.closeIdleConnections(config.getPollingIntervalTime() * 4000);

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setStaleCheckingEnabled(config.isConnectionStaleCheckingEnabled());
    params.setMaxConnectionsPerHost(hostConfiguration, config.getMaxHostConnections());
    params.setMaxTotalConnections(config.getMaxTotalConnections());
    params.setConnectionTimeout(config.getTimeout());
    params.setSoTimeout(60 * 1000);/*ww w.  j  a v  a 2s .  c o m*/

    connectionManager.setParams(params);
    httpclient = new HttpClient(connectionManager);
    httpclient.setHostConfiguration(hostConfiguration);
}

From source file:com.lazerycode.ebselen.customhandlers.FileDownloader.java

/**
 * Mimic the WebDriver host configuration
 *
 * @param hostURL/*from  www  . j  ava  2s.  c o  m*/
 * @return
 */
private HostConfiguration mimicHostConfiguration(String hostURL, int hostPort) {
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost(hostURL, hostPort);
    return hostConfig;
}

From source file:jhc.redsniff.webdriver.download.FileDownloader.java

private HostConfiguration mimicHostConfiguration(String hostURL, int hostPort) {
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost(hostURL, hostPort);
    return hostConfig;
}

From source file:games.strategy.engine.random.PropertiesDiceRoller.java

public String postRequest(final int max, final int numDice, final String subjectMessage, String gameID,
        final String gameUUID) throws IOException {
    if (gameID.trim().length() == 0)
        gameID = "TripleA";
    String message = gameID + ":" + subjectMessage;
    final int maxLength = Integer.valueOf(m_props.getProperty("message.maxlength"));
    if (message.length() > maxLength)
        message = message.substring(0, maxLength - 1);
    final PostMethod post = new PostMethod(m_props.getProperty("path"));
    final NameValuePair[] data = { new NameValuePair("numdice", "" + numDice),
            new NameValuePair("numsides", "" + max), new NameValuePair("modroll", "No"),
            new NameValuePair("numroll", "" + 1), new NameValuePair("subject", message),
            new NameValuePair("roller", getToAddress()), new NameValuePair("gm", getCcAddress()),
            new NameValuePair("send", "true"), };
    post.setRequestHeader("User-Agent", "triplea/" + EngineVersion.VERSION);
    // this is to allow a dice server to allow the user to request the emails for the game
    // rather than sending out email for each roll
    post.setRequestHeader("X-Triplea-Game-UUID", gameUUID);
    post.setRequestBody(data);/*from w w  w  . java2  s  .  co m*/
    final HttpClient client = new HttpClient();
    try {
        final String host = m_props.getProperty("host");
        int port = 80;
        if (m_props.getProperty("port") != null) {
            port = Integer.parseInt(m_props.getProperty("port"));
        }
        final HostConfiguration config = client.getHostConfiguration();
        config.setHost(host, port);
        // add the proxy
        GameRunner2.addProxy(config);
        client.executeMethod(post);
        final String result = post.getResponseBodyAsString();
        return result;
    } finally {
        post.releaseConnection();
    }
}

From source file:com.exalead.io.failover.MonitoredHttpConnectionManager.java

public synchronized void removeHost(String host, int port) {
    HostConfiguration hc = new HostConfiguration();
    hc.setHost(host, port);

    if (hosts.size() == 1) {
        throw new IllegalArgumentException("Can't remove last host of pool");
    }//from w w  w.jav  a  2  s  .c o m

    hostsMap.remove(hc);

    /* Clean-up the round robin structure */
    Iterator<HostState> iter = hostsForSelection.listIterator();
    while (iter.hasNext()) {
        HostState hs = iter.next();
        if (hs.configuration.equals(hc)) {
            iter.remove();
        }
    }
    currentHost = 0;

    /* Cleanup the monitoring structure and the main list */

    nextToMonitorList.clear();
    alreadyMonitored.clear();

    iter = hosts.listIterator();
    while (iter.hasNext()) {
        HostState hs = iter.next();
        if (hs.configuration.equals(hc)) {
            iter.remove();
        } else {
            nextToMonitorList.add(hs);
        }
    }
}

From source file:com.taobao.diamond.client.impl.DefaultDiamondPublisher.java

private void initHttpClient() {
    if (MockServer.isTestMode()) {
        return;//from  www.  ja  v  a2  s  .c  o  m
    }
    HostConfiguration hostConfiguration = new HostConfiguration();
    hostConfiguration.setHost(diamondConfigure.getDomainNameList().get(domainNamePos.get()),
            diamondConfigure.getPort());
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.closeIdleConnections(60 * 1000);

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled());
    params.setMaxConnectionsPerHost(hostConfiguration, diamondConfigure.getMaxHostConnections());
    params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections());
    params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
    params.setSoTimeout(requestTimeout);

    connectionManager.setParams(params);

    httpClient = new HttpClient(connectionManager);
    httpClient.setHostConfiguration(hostConfiguration);
}

From source file:colt.nicity.performance.agent.LatentHttpPump.java

private void configureSsl(HostConfiguration hostConfiguration, String host, int port)
        throws IllegalStateException {
    //        HttpClientSSLConfig httpClientSSLConfig = locateConfig(HttpClientSSLConfig.class, null);
    //        if (httpClientSSLConfig != null) {
    //            Protocol sslProtocol;
    //            if (httpClientSSLConfig.getCustomSSLSocketFactory() != null) {
    //                sslProtocol = new Protocol(HTTPS_PROTOCOL,
    //                        new CustomSecureProtocolSocketFactory(httpClientSSLConfig.getCustomSSLSocketFactory()), SSL_PORT);
    //            } else {
    //                sslProtocol = Protocol.getProtocol(HTTPS_PROTOCOL);
    //            }
    //            hostConfiguration.setHost(host, port, sslProtocol);
    //            httpClient.setUsingSSL();
    //        } else {
    hostConfiguration.setHost(host, port);
    //        }/*from   w  ww. j  av  a  2 s.  c o  m*/
}

From source file:com.taobao.diamond.client.processor.ServerAddressProcessor.java

/**
 * diamond//from  w  ww . ja v a 2 s  . c o m
 * 
 * @param acquireCount
 *            01
 * @return
 */
private boolean acquireServerAddressOnce(int acquireCount) {
    HostConfiguration hostConfiguration = configHttpClient.getHostConfiguration();
    String configServerAddress;
    int port;
    if (null != diamondConfigure.getConfigServerAddress()) {
        configServerAddress = diamondConfigure.getConfigServerAddress();
        port = diamondConfigure.getConfigServerPort();
    } else {
        if (acquireCount == 0) {
            configServerAddress = Constants.DEFAULT_DOMAINNAME;
            port = Constants.DEFAULT_PORT;
        } else {
            configServerAddress = Constants.DAILY_DOMAINNAME;
            port = Constants.DEFAULT_PORT;
        }
    }
    hostConfiguration.setHost(configServerAddress, port);

    String serverAddressUrl = Constants.CONFIG_HTTP_URI_FILE;

    HttpMethod httpMethod = new GetMethod(serverAddressUrl);
    // HttpMethod
    HttpMethodParams params = new HttpMethodParams();
    params.setSoTimeout(diamondConfigure.getOnceTimeout());
    // ///////////////////////
    httpMethod.setParams(params);

    try {
        if (SC_OK == configHttpClient.executeMethod(httpMethod)) {
            InputStreamReader reader = new InputStreamReader(httpMethod.getResponseBodyAsStream());
            BufferedReader bufferedReader = new BufferedReader(reader);
            String address = null;
            List<String> newDomainNameList = new LinkedList<String>();
            while ((address = bufferedReader.readLine()) != null) {
                address = address.trim();
                if (StringUtils.isNotBlank(address)) {
                    newDomainNameList.add(address);
                }
            }
            if (newDomainNameList.size() > 0) {
                log.debug("");
                this.diamondConfigure.setDomainNameList(newDomainNameList);
                return true;
            }
        } else {
            log.warn("");
        }
    } catch (HttpException e) {
        log.error(getErrorMessage(configServerAddress) + ", " + e);
    } catch (IOException e) {
        log.error(getErrorMessage(configServerAddress) + ", " + e);
    } catch (Exception e) {
        log.error(getErrorMessage(configServerAddress) + ", " + e);
    } finally {
        httpMethod.releaseConnection();
    }
    return false;
}

From source file:cn.leancloud.diamond.client.processor.ServerAddressProcessor.java

/**
 * ?diamond??// w w  w .ja va 2s.  co m
 * 
 * @param acquireCount
 *            ?01?
 * @return
 */
private boolean acquireServerAddressOnce(int acquireCount) {
    HostConfiguration hostConfiguration = configHttpClient.getHostConfiguration();
    String configServerAddress;
    int port;
    if (null != diamondConfigure.getConfigServerAddress()) {
        configServerAddress = diamondConfigure.getConfigServerAddress();
        port = diamondConfigure.getConfigServerPort();
    } else {
        if (acquireCount == 0) {
            configServerAddress = Constants.DEFAULT_DOMAINNAME;
            port = Constants.DEFAULT_PORT;
        } else {
            configServerAddress = Constants.DAILY_DOMAINNAME;
            port = Constants.DEFAULT_PORT;
        }
    }
    hostConfiguration.setHost(configServerAddress, port);

    String serverAddressUrl = Constants.CONFIG_HTTP_URI_FILE;

    HttpMethod httpMethod = new GetMethod(serverAddressUrl);
    // HttpMethod?
    HttpMethodParams params = new HttpMethodParams();
    params.setSoTimeout(diamondConfigure.getOnceTimeout());
    // ///////////////////////
    httpMethod.setParams(params);

    try {
        if (SC_OK == configHttpClient.executeMethod(httpMethod)) {
            InputStreamReader reader = new InputStreamReader(httpMethod.getResponseBodyAsStream());
            BufferedReader bufferedReader = new BufferedReader(reader);
            String address = null;
            List<String> newDomainNameList = new LinkedList<String>();
            while ((address = bufferedReader.readLine()) != null) {
                address = address.trim();
                if (StringUtils.isNotBlank(address)) {
                    newDomainNameList.add(address);
                }
            }
            if (newDomainNameList.size() > 0) {
                log.debug("?");
                this.diamondConfigure.setDomainNameList(newDomainNameList);
                return true;
            }
        } else {
            log.warn("??");
        }
    } catch (HttpException e) {
        log.error(getErrorMessage(configServerAddress) + ", " + e);
    } catch (IOException e) {
        log.error(getErrorMessage(configServerAddress) + ", " + e);
    } catch (Exception e) {
        log.error(getErrorMessage(configServerAddress) + ", " + e);
    } finally {
        httpMethod.releaseConnection();
    }
    return false;
}