Java Code Examples for org.apache.commons.httpclient.HttpClient#setHostConfiguration()

The following examples show how to use org.apache.commons.httpclient.HttpClient#setHostConfiguration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultDiamondSubscriber.java    From diamond with Apache License 2.0 6 votes vote down vote up
protected void initHttpClient() {
    if (MockServer.isTestMode()) {
        return;
    }
    HostConfiguration hostConfiguration = new HostConfiguration();
    hostConfiguration.setHost(diamondConfigure.getDomainNameList().get(this.domainNamePos.get()),
        diamondConfigure.getPort());

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

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled());
    params.setMaxConnectionsPerHost(hostConfiguration, diamondConfigure.getMaxHostConnections());
    params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections());
    params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
    // 设置读超时为1分钟,
    // [email protected]
    params.setSoTimeout(60 * 1000);

    connectionManager.setParams(params);
    httpClient = new HttpClient(connectionManager);
    httpClient.setHostConfiguration(hostConfiguration);
}
 
Example 2
Source File: DefaultDiamondSubscriber.java    From diamond with Apache License 2.0 6 votes vote down vote up
protected void initHttpClient() {
    if (MockServer.isTestMode()) {
        return;
    }
    HostConfiguration hostConfiguration = new HostConfiguration();
    hostConfiguration.setHost(diamondConfigure.getDomainNameList().get(this.domainNamePos.get()),
        diamondConfigure.getPort());

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

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled());
    params.setMaxConnectionsPerHost(hostConfiguration, diamondConfigure.getMaxHostConnections());
    params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections());
    params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
    // 设置读超时为1分钟,
    // [email protected]
    params.setSoTimeout(60 * 1000);

    connectionManager.setParams(params);
    httpClient = new HttpClient(connectionManager);
    httpClient.setHostConfiguration(hostConfiguration);
}
 
Example 3
Source File: ErrorReportSender.java    From otroslogviewer with Apache License 2.0 6 votes vote down vote up
public String sendReport(Map<String, String> values) throws IOException {
  HttpClient httpClient = new HttpClient();

  HostConfiguration hostConfiguration = new HostConfiguration();
  if (!StringUtils.isBlank(proxy)) {
    hostConfiguration.setProxy(proxy, proxyPort);
    if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(password)) {
      httpClient.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
    }
  }
  httpClient.setHostConfiguration(hostConfiguration);
  PostMethod method = new PostMethod(getSendUrl());

  addHttpPostParams(values, method);

  int executeMethod = httpClient.executeMethod(method);
  LOGGER.info("HTTP result of report send POST: " + executeMethod);
  return IOUtils.toString(method.getResponseBodyAsStream());
}
 
Example 4
Source File: BitlyUrlShortenerImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public BitlyUrlShortenerImpl()
{
    httpClient = new HttpClient();
    httpClient.setHttpConnectionManager(new MultiThreadedHttpConnectionManager());
    HostConfiguration hostConfiguration = new HostConfiguration();
    hostConfiguration.setHost("api-ssl.bitly.com", 443, Protocol.getProtocol("https"));
    httpClient.setHostConfiguration(hostConfiguration);
}
 
Example 5
Source File: HttpClientFactory.java    From alfresco-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected HttpClient getHttpsClient(String httpsHost, int httpsPort)
{
    // Configure a custom SSL socket factory that will enforce mutual authentication
    HttpClient httpClient = constructHttpClient();
    // Default port is 443 for the HostFactory, when including customised port (like 8983) the port name is skipped from "getHostURL" string
    HttpHostFactory hostFactory = new HttpHostFactory(new Protocol("https", sslSocketFactory, HttpsURL.DEFAULT_PORT));
    httpClient.setHostConfiguration(new HostConfigurationWithHostFactory(hostFactory));
    httpClient.getHostConfiguration().setHost(httpsHost, httpsPort, "https");
    return httpClient;
}
 
Example 6
Source File: ServerAddressProcessor.java    From diamond with Apache License 2.0 5 votes vote down vote up
private void initHttpClient() {
    HostConfiguration hostConfiguration = new HostConfiguration();

    SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager();
    connectionManager.closeIdleConnections(5000L);

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled());
    params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
    connectionManager.setParams(params);

    configHttpClient = new HttpClient(connectionManager);
    configHttpClient.setHostConfiguration(hostConfiguration);
}
 
Example 7
Source File: HttpClientBuilder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Builds an HTTP client with the given settings. Settings are NOT reset to their default values after a client has
 * been created.
 * 
 * @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;
}
 
Example 8
Source File: ServerAddressProcessor.java    From diamond with Apache License 2.0 5 votes vote down vote up
private void initHttpClient() {
    HostConfiguration hostConfiguration = new HostConfiguration();

    SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager();
    connectionManager.closeIdleConnections(5000L);

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled());
    params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
    connectionManager.setParams(params);

    configHttpClient = new HttpClient(connectionManager);
    configHttpClient.setHostConfiguration(hostConfiguration);
}
 
Example 9
Source File: ApacheHttp31SLRFactory.java    From webarchive-commons with Apache License 2.0 5 votes vote down vote up
public ApacheHttp31SLRFactory() {
  	connectionManager = new MultiThreadedHttpConnectionManager();
  	//connectionManager = new ThreadLocalHttpConnectionManager();
  	hostConfiguration = new HostConfiguration();
HttpClientParams params = new HttpClientParams();
  	http = new HttpClient(params,connectionManager);
  	http.setHostConfiguration(hostConfiguration);
  }