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 sonatype-aether by sonatype.
the class WagonRepositoryConnector method getProxy.
private ProxyInfoProvider getProxy(RemoteRepository repository) {
ProxyInfoProvider proxy = null;
Proxy p = repository.getProxy();
if (p != null) {
final ProxyInfo prox = new ProxyInfo();
prox.setType(p.getType());
prox.setHost(p.getHost());
prox.setPort(p.getPort());
if (p.getAuthentication() != null) {
prox.setUserName(p.getAuthentication().getUsername());
prox.setPassword(p.getAuthentication().getPassword());
}
proxy = new ProxyInfoProvider() {
public ProxyInfo getProxyInfo(String protocol) {
return prox;
}
};
}
return proxy;
}
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 AbstractDeployMojo method getProxy.
/**
* Get proxy information for Maven 3.
*
* @param repository
* @param settingsDecrypter
* @return
*/
private ProxyInfo getProxy(Repository repository, SettingsDecrypter settingsDecrypter) {
String protocol = repository.getProtocol();
String url = repository.getUrl();
getLog().debug("repository protocol " + protocol);
String originalProtocol = protocol;
// so we will check both
if (StringUtils.equalsIgnoreCase("dav", protocol) && url.startsWith("dav:")) {
url = url.substring(4);
if (url.startsWith("http")) {
try {
URL urlSite = new URL(url);
protocol = urlSite.getProtocol();
getLog().debug("found dav protocol so transform to real transport protocol " + protocol);
} catch (MalformedURLException e) {
getLog().warn("fail to build URL with " + url);
}
}
} else {
getLog().debug("getProxy 'protocol': " + protocol);
}
if (mavenSession != null && protocol != null) {
MavenExecutionRequest request = mavenSession.getRequest();
if (request != null) {
List<Proxy> proxies = request.getProxies();
if (proxies != null) {
for (Proxy proxy : proxies) {
if (proxy.isActive() && (protocol.equalsIgnoreCase(proxy.getProtocol()) || originalProtocol.equalsIgnoreCase(proxy.getProtocol()))) {
SettingsDecryptionResult result = settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(proxy));
proxy = result.getProxy();
ProxyInfo proxyInfo = new ProxyInfo();
proxyInfo.setHost(proxy.getHost());
// so hackish for wagon the protocol is https for site dav:
// dav:https://dav.codehaus.org/mojo/
//proxy.getProtocol() );
proxyInfo.setType(protocol);
proxyInfo.setPort(proxy.getPort());
proxyInfo.setNonProxyHosts(proxy.getNonProxyHosts());
proxyInfo.setUserName(proxy.getUsername());
proxyInfo.setPassword(proxy.getPassword());
getLog().debug("found proxyInfo " + ("host:port " + proxyInfo.getHost() + ":" + proxyInfo.getPort() + ", " + proxyInfo.getUserName()));
return proxyInfo;
}
}
}
}
}
getLog().debug("getProxy 'protocol': " + protocol + " no ProxyInfo found");
return null;
}
Aggregations