Java Code Examples for org.apache.commons.httpclient.HostConfiguration#setHost()

The following examples show how to use org.apache.commons.httpclient.HostConfiguration#setHost() . 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: HTTPNotificationStrategy.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
public HTTPNotificationStrategy(PushNotificationConfig config) {
    this.config = config;
    if (this.config == null) {
        throw new InvalidConfigurationException("Properties Cannot be found");
    }
    endpoint = config.getProperties().get(URL_PROPERTY);
    if (endpoint == null || endpoint.isEmpty()) {
        throw new InvalidConfigurationException("Property - 'url' cannot be found");
    }
    try {
        this.uri = endpoint;
        URL url = new URL(endpoint);
        hostConfiguration = new HostConfiguration();
        hostConfiguration.setHost(url.getHost(), url.getPort(), url.getProtocol());
        this.authorizationHeaderValue = config.getProperties().get(AUTHORIZATION_HEADER_PROPERTY);
        executorService = Executors.newFixedThreadPool(1);
        httpClient = new HttpClient();
    } catch (MalformedURLException e) {
        throw new InvalidConfigurationException("Property - 'url' is malformed.", e);
    }
}
 
Example 4
Source File: HttpClientIT.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Test
public void hostConfig() {
    HttpClient client = new HttpClient();
    client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT);
    client.getParams().setSoTimeout(SO_TIMEOUT);

    HostConfiguration config = new HostConfiguration();
    config.setHost("weather.naver.com", 80, "http");
    GetMethod method = new GetMethod("/rgn/cityWetrMain.nhn");

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
    method.setQueryString(new NameValuePair[] { new NameValuePair("key2", "value2") });

    try {
        // Execute the method.
        client.executeMethod(config, method);
    } catch (Exception ignored) {
    } finally {
        method.releaseConnection();
    }

    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
}
 
Example 5
Source File: HttpClientTransmitterImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @param target TransferTarget
 * @return HostConfiguration
 */
private HostConfiguration getHostConfig(TransferTarget target)
{
    String requiredProtocol = target.getEndpointProtocol();
    if (requiredProtocol == null)
    {
        throw new TransferException(MSG_UNSUPPORTED_PROTOCOL, new Object[] {requiredProtocol});
    }

    Protocol protocol = protocolMap.get(requiredProtocol.toLowerCase().trim());
    if (protocol == null) 
    {
        log.error("Unsupported protocol: " + target.getEndpointProtocol());
        throw new TransferException(MSG_UNSUPPORTED_PROTOCOL, new Object[] {requiredProtocol});
    }

    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost(target.getEndpointHost(), target.getEndpointPort(), protocol);
    
    // Use the appropriate Proxy Host if required
    if (httpProxyHost != null && HTTP_SCHEME_NAME.equals(protocol.getScheme()) && HttpClientHelper.requiresProxy(target.getEndpointHost()))
    {
        hostConfig.setProxyHost(httpProxyHost);

        if (log.isDebugEnabled())
        {
            log.debug("Using HTTP proxy host for: " + target.getEndpointHost());
        }
    }
    else if (httpsProxyHost != null && HTTPS_SCHEME_NAME.equals(protocol.getScheme()) && HttpClientHelper.requiresProxy(target.getEndpointHost()))
    {
        hostConfig.setProxyHost(httpsProxyHost);

        if (log.isDebugEnabled())
        {
            log.debug("Using HTTPS proxy host for: " + target.getEndpointHost());
        }
    } 
    return hostConfig;
}
 
Example 6
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 7
Source File: Confluence.java    From maven-confluence-plugin with Apache License 2.0 5 votes vote down vote up
protected Confluence(String endpoint, ConfluenceProxy proxyInfo ) throws URISyntaxException, MalformedURLException {
       this(new XmlRpcClient());
if (endpoint.endsWith("/")) {
           endpoint = endpoint.substring(0, endpoint.length() - 1);
       }

       endpoint = ConfluenceService.Protocol.XMLRPC.addTo(endpoint);
   
       final java.net.URI serviceURI = new java.net.URI(endpoint);

       XmlRpcClientConfigImpl clientConfig = new XmlRpcClientConfigImpl();
       clientConfig.setServerURL(serviceURI.toURL() );

       clientConfig.setEnabledForExtensions(true); // add this to support attachment upload

       client.setConfig( clientConfig );

       if( isProxyEnabled(proxyInfo, serviceURI) ) {
           
           final XmlRpcCommonsTransportFactory transportFactory = new XmlRpcCommonsTransportFactory( client );

           final HttpClient httpClient = new HttpClient();
           final HostConfiguration hostConfiguration = httpClient.getHostConfiguration();
           hostConfiguration.setProxy( proxyInfo.host, proxyInfo.port );
           hostConfiguration.setHost(serviceURI.getHost(), serviceURI.getPort(), serviceURI.toURL().getProtocol());

           if( !isNullOrEmpty(proxyInfo.userName) && !isNullOrEmpty(proxyInfo.password) ) {
               Credentials cred = new UsernamePasswordCredentials(proxyInfo.userName,proxyInfo.password);
               httpClient.getState().setProxyCredentials(AuthScope.ANY, cred);
           }

           transportFactory.setHttpClient( httpClient );
           client.setTransportFactory( transportFactory );
       }
   }