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

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

Introduction

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

Prototype

public HttpHost(String paramString, int paramInt) 

Source Link

Usage

From source file:de.softwareforge.pgpsigner.util.HKPSender.java

public HKPSender(final String serverName) {
    HttpHost httpHost = new HttpHost(serverName, HKP_DEFAULT_PORT);
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost(httpHost);//from  www .ja va2 s .  c o m
    this.httpClient = new HttpClient();
    this.httpClient.getParams().setParameter("http.useragent", PGPSigner.APPLICATION_VERSION);
    httpClient.setHostConfiguration(hostConfig);
}

From source file:com.orange.mmp.net.http.HttpConnectionManager.java

public Connection getConnection() throws MMPNetException {
    SimpleHttpConnectionManager shcm = new SimpleHttpConnectionManager();

    HttpClientParams defaultHttpParams = new HttpClientParams();
    defaultHttpParams.setParameter(HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    defaultHttpParams.setParameter(HttpConnectionParams.TCP_NODELAY, true);
    defaultHttpParams.setParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false);
    defaultHttpParams.setParameter(HttpConnectionParams.SO_LINGER, 0);
    defaultHttpParams.setParameter(HttpClientParams.MAX_REDIRECTS, 3);
    defaultHttpParams.setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, false);

    HttpClient httpClient2 = new HttpClient(defaultHttpParams, shcm);

    if (HttpConnectionManager.proxyHost != null) {
        defaultHttpParams.setParameter("http.route.default-proxy",
                new HttpHost(HttpConnectionManager.proxyHost, HttpConnectionManager.proxyPort)); // TODO Host configuration !
        if (HttpConnectionManager.proxyHost != null/* && this.useProxy*/) {
            HostConfiguration config = new HostConfiguration();
            config.setProxy(HttpConnectionManager.proxyHost, HttpConnectionManager.proxyPort);
            httpClient2.setHostConfiguration(config);
        } else {/*from  w w  w  . j a  v a2  s. co  m*/
            HostConfiguration config = new HostConfiguration();
            config.setProxyHost(null);
            httpClient2.setHostConfiguration(config);
        }
    }

    return new HttpConnection(httpClient2);
}

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);/* w w w .  j a  va 2s  .  co m*/
    runExecuteMethodTest(testName, hostConfig, state);
}

From source file:org.apache.hadoop.fs.swift.http.SwiftRestClient.java

/**
 * Execute a method in a new HttpClient instance.
 * If the auth failed, authenticate then retry the method.
 * @param method methot to exec//from   w  ww .j  a  v a2 s. c om
 * @param <M> Method type
 * @return the status code
 * @throws IOException on any failure
 * @throws SwiftConnectionException failure to connect or authenticate
 */
private <M extends HttpMethod> int exec(M method) throws IOException, SwiftConnectionException {
    final HttpClient client = new HttpClient();
    if (proxyHost != null) {
        client.getParams().setParameter(HTTP_ROUTE_DEFAULT_PROXY, new HttpHost(proxyHost, proxyPort));
    }

    int statusCode = execWithDebugOutput(method, client);
    if (method.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
        //unauthed -look at what raised the response

        if (method.getURI().toString().equals(authUri.toString())) {
            //unauth response from the AUTH URI itself.
            throw new SwiftConnectionException("Authentication failed, URI credentials are incorrect,"
                    + " or Openstack Keystone is configured incorrectly. URL='" + authUri + "' " + "username={"
                    + username + "} " + "password length=" + password.length());
        } else {
            //any other URL: try again
            if (LOG.isDebugEnabled()) {
                LOG.debug("Reauthenticating");
            }
            authenticate();
            if (LOG.isDebugEnabled()) {
                LOG.debug("Retrying original request");
            }
            statusCode = execWithDebugOutput(method, client);
        }
    }
    return statusCode;
}

From source file:org.crosswire.common.util.WebResource.java

public WebResource(URI theURI, String theProxyHost, Integer theProxyPort) {
    uri = theURI;/* w w  w .  jav a2 s . com*/
    client = new HttpClient();
    HostConfiguration config = client.getHostConfiguration();
    config.setHost(new HttpHost(theURI.getHost(), theURI.getPort()));
    if (theProxyHost != null && theProxyHost.length() > 0) {
        config.setProxyHost(new ProxyHost(theProxyHost, theProxyPort == null ? -1 : theProxyPort.intValue()));
    }
}

From source file:org.mule.transport.http.MuleHostConfigurationTestCase.java

@Test
public void testSetHostViaHttpHost() {
    HostConfiguration hostConfig = createHostConfiguration();

    HttpHost host = new HttpHost("www.mulesoft.org", 8080);
    hostConfig.setHost(host);//  w  w  w .  j  av a  2s.co m

    assertMockSocketFactory(hostConfig);
    assertEquals("www.mulesoft.org", hostConfig.getHost());
    assertEquals(8080, hostConfig.getPort());
}

From source file:org.wso2.siddhi.extension.output.transport.http.HttpOutputTransport.java

private void checkHTTPClientInit(Map<String, String> staticProperties) {
    if (httpClient != null)
        return;/*from w w  w .  j a v  a 2  s  .c om*/
    synchronized (HttpOutputTransport.class) {
        if (this.httpClient != null)
            return;
        httpClient = new HttpClient(connectionManager);
        String proxyHost = staticProperties.get(ADAPTER_PROXY_HOST);
        String proxyPort = staticProperties.get(ADAPTER_PROXY_PORT);
        if (proxyHost != null && proxyHost.trim().length() > 0) {
            try {
                HttpHost host = new HttpHost(proxyHost, Integer.parseInt(proxyPort));
                this.httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, host);
            } catch (NumberFormatException e) {
                log.error("Invalid proxy port: " + proxyPort + ", "
                        + "ignoring proxy settings for HTTP output event adaptor...");
            }
        }

        // TODO: 1/8/17 fix properly
        // String messageFormat = eventAdapterConfiguration.getMessageFormat();
        String messageFormat = "json";
        if (messageFormat.equalsIgnoreCase("json")) {
            contentType = "application/json";
        } else if (messageFormat.equalsIgnoreCase("text")) {
            contentType = "text/plain";
        } else {
            contentType = "text/xml";
        }
    }
}

From source file:smartrics.rest.fitnesse.fixture.support.http.URIBuilder.java

public URI getURI(String scheme, String host, int port, String path, String queryString,
        HttpMethodParams params) throws URIException {
    HttpHost httphost = new HttpHost(host, port);
    StringBuffer buffer = new StringBuffer();
    if (httphost != null) {
        buffer.append(httphost.getProtocol().getScheme());
        buffer.append("://");
        buffer.append(httphost.getHostName());
        int p = httphost.getPort();
        if (p != -1 && p != httphost.getProtocol().getDefaultPort()) {
            buffer.append(":");
            buffer.append(p);//w  ww  .j  a v a 2 s .  c om
        }
    }
    buffer.append(path);
    if (queryString != null) {
        buffer.append('?');
        buffer.append(queryString);
    }
    String charset = params.getUriCharset();
    return new HttpURL(buffer.toString(), charset);
}