List of usage examples for org.apache.commons.httpclient ProxyHost getPort
public int getPort()
From source file:org.alfresco.repo.remoteconnector.RemoteConnectorServiceImpl.java
/** * Create suitable AuthScope for ProxyHost. * If the ProxyHost is null, no AuthsScope will be created. * @param proxyHost ProxyHost//from ww w .j av a 2 s . c o m * @return Authscope for provided ProxyHost, null otherwise. */ private static AuthScope createProxyAuthScope(final ProxyHost proxyHost) { AuthScope authScope = null; if (proxyHost != null) { authScope = new AuthScope(proxyHost.getHostName(), proxyHost.getPort()); } return authScope; }
From source file:org.alfresco.util.HttpClientHelperTest.java
public void testHTTPProxySettings() { String host = "testHost"; Integer port = 8080;/*from www .ja va 2s. co 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;/*ww w . j a va 2 s . 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); }
From source file:org.openrdf.http.client.HTTPClient.java
private static void configureProxySettings(HttpClient httpClient) { String proxyHostName = System.getenv("http.proxyHost"); if (proxyHostName != null && proxyHostName.length() > 0) { int proxyPort = 80; // default try {//w w w . j a va 2s.c o m proxyPort = Integer.parseInt(System.getenv("http.proxyPort")); } catch (NumberFormatException e) { // do nothing, revert to default } ProxyHost proxyHost = new ProxyHost(proxyHostName, proxyPort); httpClient.getHostConfiguration().setProxyHost(proxyHost); String proxyUser = System.getenv("http.proxyUser"); if (proxyUser != null) { String proxyPassword = System.getenv("http.proxyPassword"); httpClient.getState().setProxyCredentials( new AuthScope(proxyHost.getHostName(), proxyHost.getPort()), new UsernamePasswordCredentials(proxyUser, proxyPassword)); httpClient.getParams().setAuthenticationPreemptive(true); } } }