use of org.apache.maven.wagon.proxy.ProxyInfo in project maven-plugins by apache.
the class JavadocUtil method createHttpClient.
/**
* Creates a new {@code HttpClient} instance.
*
* @param settings The settings to use for setting up the client or {@code null}.
* @param url The {@code URL} to use for setting up the client or {@code null}.
*
* @return A new {@code HttpClient} instance.
*
* @see #DEFAULT_TIMEOUT
* @since 2.8
*/
private static HttpClient createHttpClient(Settings settings, URL url) {
DefaultHttpClient httpClient = new DefaultHttpClient(new PoolingClientConnectionManager());
httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, DEFAULT_TIMEOUT);
httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, DEFAULT_TIMEOUT);
httpClient.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
// Some web servers don't allow the default user-agent sent by httpClient
httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
if (settings != null && settings.getActiveProxy() != null) {
Proxy activeProxy = settings.getActiveProxy();
ProxyInfo proxyInfo = new ProxyInfo();
proxyInfo.setNonProxyHosts(activeProxy.getNonProxyHosts());
if (StringUtils.isNotEmpty(activeProxy.getHost()) && (url == null || !ProxyUtils.validateNonProxyHosts(proxyInfo, url.getHost()))) {
HttpHost proxy = new HttpHost(activeProxy.getHost(), activeProxy.getPort());
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
if (StringUtils.isNotEmpty(activeProxy.getUsername()) && activeProxy.getPassword() != null) {
Credentials credentials = new UsernamePasswordCredentials(activeProxy.getUsername(), activeProxy.getPassword());
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
}
}
}
return httpClient;
}
use of org.apache.maven.wagon.proxy.ProxyInfo in project maven-plugins by apache.
the class DoapUtil method fetchURL.
/**
* Fetch an URL
*
* @param settings the user settings used to fetch the url with an active proxy, if defined.
* @param url the url to fetch
* @throws IOException if any
* @see #DEFAULT_TIMEOUT
* @since 1.1
*/
public static void fetchURL(Settings settings, URL url) throws IOException {
if (url == null) {
throw new IllegalArgumentException("The url is null");
}
if ("file".equals(url.getProtocol())) {
InputStream in = null;
try {
in = url.openStream();
in.close();
in = null;
} finally {
IOUtil.close(in);
}
return;
}
// http, https...
HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(DEFAULT_TIMEOUT);
httpClient.getHttpConnectionManager().getParams().setSoTimeout(DEFAULT_TIMEOUT);
httpClient.getParams().setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
// Some web servers don't allow the default user-agent sent by httpClient
httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
if (settings != null && settings.getActiveProxy() != null) {
Proxy activeProxy = settings.getActiveProxy();
ProxyInfo proxyInfo = new ProxyInfo();
proxyInfo.setNonProxyHosts(activeProxy.getNonProxyHosts());
if (StringUtils.isNotEmpty(activeProxy.getHost()) && !ProxyUtils.validateNonProxyHosts(proxyInfo, url.getHost())) {
httpClient.getHostConfiguration().setProxy(activeProxy.getHost(), activeProxy.getPort());
if (StringUtils.isNotEmpty(activeProxy.getUsername()) && activeProxy.getPassword() != null) {
Credentials credentials = new UsernamePasswordCredentials(activeProxy.getUsername(), activeProxy.getPassword());
httpClient.getState().setProxyCredentials(AuthScope.ANY, credentials);
}
}
}
GetMethod getMethod = new GetMethod(url.toString());
try {
int status;
try {
status = httpClient.executeMethod(getMethod);
} catch (SocketTimeoutException e) {
// could be a sporadic failure, one more retry before we give up
status = httpClient.executeMethod(getMethod);
}
if (status != HttpStatus.SC_OK) {
throw new FileNotFoundException(url.toString());
}
} finally {
getMethod.releaseConnection();
}
}
use of org.apache.maven.wagon.proxy.ProxyInfo in project maven-plugins by apache.
the class RepositoryUtils method dependencyExistsInRepo.
/**
* @param repo not null
* @param artifact not null
* @return <code>true</code> if the artifact exists in the given repo, <code>false</code> otherwise or if
* the repo is blacklisted.
*/
public boolean dependencyExistsInRepo(ArtifactRepository repo, Artifact artifact) {
if (repo.isBlacklisted()) {
if (log.isDebugEnabled()) {
log.debug("The repo '" + repo.getId() + "' is black listed - Ignored it");
}
return false;
}
if (UNKNOWN_HOSTS.contains(repo.getUrl())) {
if (log.isDebugEnabled()) {
log.debug("The repo url '" + repo.getUrl() + "' is unknown - Ignored it");
}
return false;
}
repo = wagonManager.getMirrorRepository(repo);
String id = repo.getId();
Repository repository = new Repository(id, repo.getUrl());
Wagon wagon;
try {
wagon = wagonManager.getWagon(repository);
} catch (UnsupportedProtocolException e) {
logError("Unsupported protocol: '" + repo.getProtocol() + "'", e);
return false;
} catch (WagonConfigurationException e) {
logError("Unsupported protocol: '" + repo.getProtocol() + "'", e);
return false;
}
wagon.setTimeout(1000);
if (log.isDebugEnabled()) {
Debug debug = new Debug();
wagon.addSessionListener(debug);
wagon.addTransferListener(debug);
}
try {
// FIXME when upgrading to maven 3.x : this must be changed.
AuthenticationInfo auth = wagonManager.getAuthenticationInfo(repo.getId());
ProxyInfo proxyInfo = getProxyInfo();
if (proxyInfo != null) {
wagon.connect(repository, auth, proxyInfo);
} else {
wagon.connect(repository, auth);
}
return wagon.resourceExists(StringUtils.replace(getDependencyUrlFromRepository(artifact, repo), repo.getUrl(), ""));
} catch (ConnectionException e) {
logError("Unable to connect to: " + repo.getUrl(), e);
return false;
} catch (AuthenticationException e) {
logError("Unable to connect to: " + repo.getUrl(), e);
return false;
} catch (TransferFailedException e) {
if (e.getCause() instanceof UnknownHostException) {
log.error("Unknown host " + e.getCause().getMessage() + " - ignored it");
UNKNOWN_HOSTS.add(repo.getUrl());
} else {
logError("Unable to determine if resource " + artifact + " exists in " + repo.getUrl(), e);
}
return false;
} catch (AuthorizationException e) {
logError("Unable to connect to: " + repo.getUrl(), e);
return false;
} catch (AbstractMethodError e) {
log.error("Wagon " + wagon.getClass().getName() + " does not support the resourceExists method");
return false;
} finally {
try {
wagon.disconnect();
} catch (ConnectionException e) {
logError("Error disconnecting wagon - ignored", e);
}
}
}
use of org.apache.maven.wagon.proxy.ProxyInfo in project maven-plugins by apache.
the class RepositoryUtils method getProxyInfo.
// ----------------------------------------------------------------------
// Private methods
// ----------------------------------------------------------------------
/**
* Convenience method to map a <code>Proxy</code> object from the user system settings to a <code>ProxyInfo</code>
* object.
*
* @return a proxyInfo object instanced or null if no active proxy is define in the settings.xml
*/
private ProxyInfo getProxyInfo() {
if (settings == null || settings.getActiveProxy() == null) {
return null;
}
Proxy settingsProxy = settings.getActiveProxy();
ProxyInfo proxyInfo = new ProxyInfo();
proxyInfo.setHost(settingsProxy.getHost());
proxyInfo.setType(settingsProxy.getProtocol());
proxyInfo.setPort(settingsProxy.getPort());
proxyInfo.setNonProxyHosts(settingsProxy.getNonProxyHosts());
proxyInfo.setUserName(settingsProxy.getUsername());
proxyInfo.setPassword(settingsProxy.getPassword());
return proxyInfo;
}
use of org.apache.maven.wagon.proxy.ProxyInfo in project maven-plugins by apache.
the class JavadocUtil method createHttpClient.
/**
* Creates a new {@code HttpClient} instance.
*
* @param settings The settings to use for setting up the client or {@code null}.
* @param url The {@code URL} to use for setting up the client or {@code null}.
*
* @return A new {@code HttpClient} instance.
*
* @see #DEFAULT_TIMEOUT
* @since 2.8
*/
private static HttpClient createHttpClient(Settings settings, URL url) {
DefaultHttpClient httpClient = new DefaultHttpClient(new PoolingClientConnectionManager());
httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, DEFAULT_TIMEOUT);
httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, DEFAULT_TIMEOUT);
httpClient.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
// Some web servers don't allow the default user-agent sent by httpClient
httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
if (settings != null && settings.getActiveProxy() != null) {
Proxy activeProxy = settings.getActiveProxy();
ProxyInfo proxyInfo = new ProxyInfo();
proxyInfo.setNonProxyHosts(activeProxy.getNonProxyHosts());
if (StringUtils.isNotEmpty(activeProxy.getHost()) && (url == null || !ProxyUtils.validateNonProxyHosts(proxyInfo, url.getHost()))) {
HttpHost proxy = new HttpHost(activeProxy.getHost(), activeProxy.getPort());
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
if (StringUtils.isNotEmpty(activeProxy.getUsername()) && activeProxy.getPassword() != null) {
Credentials credentials = new UsernamePasswordCredentials(activeProxy.getUsername(), activeProxy.getPassword());
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
}
}
}
return httpClient;
}
Aggregations