Java Code Examples for org.apache.commons.httpclient.HttpState#setProxyCredentials()
The following examples show how to use
org.apache.commons.httpclient.HttpState#setProxyCredentials() .
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: OAuth2Client.java From Knowage-Server with GNU Affero General Public License v3.0 | 6 votes |
public HttpClient getHttpClient() { String proxyUrl = System.getProperty("http.proxyHost"); String proxyPort = System.getProperty("http.proxyPort"); String proxyUser = System.getProperty("http.proxyUsername"); String proxyPassword = System.getProperty("http.proxyPassword"); HttpClient client = new HttpClient(); if (proxyUrl != null && proxyPort != null) { logger.debug("Setting proxy configuration ..."); client.getHostConfiguration().setProxy(proxyUrl, Integer.parseInt(proxyPort)); if (proxyUser != null) { logger.debug("Setting proxy authentication configuration ..."); HttpState state = new HttpState(); state.setProxyCredentials(null, null, new UsernamePasswordCredentials(proxyUser, proxyPassword)); client.setState(state); } } else { logger.debug("No proxy configuration found"); } return client; }
Example 2
Source File: RORClient.java From development with Apache License 2.0 | 5 votes |
public HttpClient createHttpClient() { HttpClient client = new HttpClient(); String proxyHost = System.getProperty(HTTPS_PROXY_HOST); String proxyPort = System.getProperty(HTTPS_PROXY_PORT); String proxyUser = System.getProperty(HTTPS_PROXY_USER); String proxyPassword = System.getProperty(HTTPS_PROXY_PASSWORD); int proxyPortInt = 0; try { proxyPortInt = Integer.parseInt(proxyPort); } catch (NumberFormatException e) { // ignore } if (!useProxyByPass(this.apiUrl)) { if (proxyHost != null && proxyPortInt > 0) { client.getHostConfiguration().setProxy(proxyHost, proxyPortInt); if (proxyUser != null && proxyUser.length() > 0 && proxyPassword != null && proxyPassword.length() > 0) { HttpState state = new HttpState(); Credentials proxyCredentials = new UsernamePasswordCredentials( proxyUser, proxyPassword); state.setProxyCredentials(new AuthScope(proxyHost, proxyPortInt), proxyCredentials); client.setState(state); } } } return client; }
Example 3
Source File: CredentialsUtils.java From httpclientAuthHelper with Apache License 2.0 | 5 votes |
public static void setProxyHost(HttpClient httpClient, UsernamePasswordCredentials proxyCredentials, String proxyHost, int proxyPort) { if (proxyHost != null && !proxyHost.isEmpty()) { httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort); if (proxyCredentials != null) { HttpState state = new HttpState(); state.setProxyCredentials(new AuthScope(proxyHost, proxyPort), proxyCredentials); httpClient.setState(state); } } }
Example 4
Source File: HttpClientTransmitterImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Get the HTTPState for a transfer target * @param target TransferTarget * @return HttpState */ private HttpState getHttpState(TransferTarget target) { HttpState httpState = new HttpState(); httpState.setCredentials(new AuthScope(target.getEndpointHost(), target.getEndpointPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials(target.getUsername(), new String(target.getPassword()))); 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: " + requiredProtocol); throw new TransferException(MSG_UNSUPPORTED_PROTOCOL, new Object[] {requiredProtocol}); } // Use the appropriate Proxy credentials if required if (httpProxyHost != null && HTTP_SCHEME_NAME.equals(protocol.getScheme()) && HttpClientHelper.requiresProxy(target.getEndpointHost())) { if (httpProxyCredentials != null) { httpState.setProxyCredentials(httpAuthScope, httpProxyCredentials); if (log.isDebugEnabled()) { log.debug("Using HTTP proxy credentials for proxy: " + httpProxyHost.getHostName()); } } } else if (httpsProxyHost != null && HTTPS_SCHEME_NAME.equals(protocol.getScheme()) && HttpClientHelper.requiresProxy(target.getEndpointHost())) { if (httpsProxyCredentials != null) { httpState.setProxyCredentials(httpsAuthScope, httpsProxyCredentials); if (log.isDebugEnabled()) { log.debug("Using HTTPS proxy credentials for proxy: " + httpsProxyHost.getHostName()); } } } return httpState; }