Example usage for org.apache.commons.httpclient ProxyHost getProtocol

List of usage examples for org.apache.commons.httpclient ProxyHost getProtocol

Introduction

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

Prototype

public Protocol getProtocol() 

Source Link

Usage

From source file:org.alfresco.util.HttpClientHelperTest.java

public void testHTTPProxySettings() {
    String host = "testHost";
    Integer port = 8080;//  w w  w.  jav  a  2 s.c o m

    setHTTPSystemProperties(host, port, "user1", "password", null);
    ProxyHost proxyHost = HttpClientHelper.createProxyHost("http.proxyHost", "http.proxyPort",
            DEFAULT_HTTP_PORT);
    UsernamePasswordCredentials proxyCredentials = (UsernamePasswordCredentials) HttpClientHelper
            .createProxyCredentials("http.proxyUser", "http.proxyPassword");

    assertEquals(HTTP, proxyHost.getProtocol().getScheme());
    assertEquals(host, proxyHost.getHostName());
    assertEquals(port, Integer.valueOf(proxyHost.getPort()));
    assertEquals("user1", proxyCredentials.getUserName());
    assertEquals("password", proxyCredentials.getPassword());

    // Test default port and no credentials
    setHTTPSystemProperties(host, null, null, null, null);
    proxyHost = HttpClientHelper.createProxyHost("http.proxyHost", "http.proxyPort", DEFAULT_HTTP_PORT);
    proxyCredentials = (UsernamePasswordCredentials) HttpClientHelper.createProxyCredentials("http.proxyUser",
            "http.proxyPassword");

    assertEquals(HTTP, proxyHost.getProtocol().getScheme());
    assertEquals(host, proxyHost.getHostName());
    assertEquals(DEFAULT_HTTP_PORT, proxyHost.getPort());
    assertNull(proxyCredentials);
}

From source file:org.alfresco.util.HttpClientHelperTest.java

public void testHTTPSProxySettings() {
    String host = "testHost";
    Integer port = 8444;/*from   ww  w  . ja v  a 2s  . c  om*/

    setHTTPSSystemProperties(host, port, "user1", "password", null);
    ProxyHost proxyHost = HttpClientHelper.createProxyHost("https.proxyHost", "https.proxyPort",
            DEFAULT_HTTPS_PORT);
    UsernamePasswordCredentials proxyCredentials = (UsernamePasswordCredentials) HttpClientHelper
            .createProxyCredentials("https.proxyUser", "https.proxyPassword");

    // Proxy hosts always use plain HTTP connection when communicating with clients (by commons.httpclient doc)
    assertEquals(HTTP, proxyHost.getProtocol().getScheme());
    assertEquals(host, proxyHost.getHostName());
    assertEquals(port, Integer.valueOf(proxyHost.getPort()));
    assertEquals("user1", proxyCredentials.getUserName());
    assertEquals("password", proxyCredentials.getPassword());

    // Test default port and no credentials
    setHTTPSSystemProperties(host, null, null, null, null);
    proxyHost = HttpClientHelper.createProxyHost("https.proxyHost", "https.proxyPort", DEFAULT_HTTPS_PORT);
    proxyCredentials = (UsernamePasswordCredentials) HttpClientHelper.createProxyCredentials("https.proxyUser",
            "https.proxyPassword");

    assertEquals(host, proxyHost.getHostName());
    assertEquals(DEFAULT_HTTPS_PORT, proxyHost.getPort());
    assertNull(proxyCredentials);
}