use of org.apache.commons.httpclient.auth.AuthScope in project maven-plugins by apache.
the class AbstractCheckDocumentationMojo method setupProxy.
/**
* Setup proxy access if needed.
*/
private void setupProxy() {
Proxy settingsProxy = settings.getActiveProxy();
if (settingsProxy != null) {
String proxyUsername = settingsProxy.getUsername();
String proxyPassword = settingsProxy.getPassword();
String proxyHost = settingsProxy.getHost();
int proxyPort = settingsProxy.getPort();
if (StringUtils.isNotEmpty(proxyHost)) {
httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
getLog().info("Using proxy [" + proxyHost + "] at port [" + proxyPort + "].");
if (StringUtils.isNotEmpty(proxyUsername)) {
getLog().info("Using proxy user [" + proxyUsername + "].");
Credentials creds = new UsernamePasswordCredentials(proxyUsername, proxyPassword);
httpClient.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort), creds);
httpClient.getParams().setAuthenticationPreemptive(true);
}
}
}
}
use of org.apache.commons.httpclient.auth.AuthScope in project jaggery by wso2.
the class HostObjectUtil method getURL.
public static int getURL(String urlString, String username, String password) throws IOException {
HttpMethod method = new GetMethod(urlString);
URL url = new URL(urlString);
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
HttpClient httpClient = new HttpClient(connectionManager);
// We should not use method.setURI and set the complete URI here.
// If we do so commons-httpclient will not use our custom socket factory.
// Hence we set the path and query separatly
method.setPath(url.getPath());
method.setQueryString(url.getQuery());
method.setRequestHeader("Host", url.getHost());
method.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
// If a username and a password is provided we support basic auth
if ((username != null) && (password != null)) {
Credentials creds = new UsernamePasswordCredentials(username, password);
int port = url.getPort();
httpClient.getState().setCredentials(new AuthScope(url.getHost(), port), creds);
}
return httpClient.executeMethod(method);
}
Aggregations