Search in sources :

Example 6 with ProxyInfo

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;
}
Also used : ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) Proxy(org.apache.maven.settings.Proxy)

Example 7 with 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;
}
Also used : ProxyInfoProvider(org.apache.maven.wagon.proxy.ProxyInfoProvider) ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) Proxy(org.sonatype.aether.repository.Proxy)

Example 8 with 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;
}
Also used : ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) Proxy(org.apache.maven.settings.Proxy) HttpHost(org.apache.http.HttpHost) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 9 with ProxyInfo

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;
}
Also used : ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) MalformedURLException(java.net.MalformedURLException) Proxy(org.apache.maven.settings.Proxy) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) URL(java.net.URL)

Aggregations

ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)9 Proxy (org.apache.maven.settings.Proxy)5 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 ConnectionException (org.apache.maven.wagon.ConnectionException)2 TransferFailedException (org.apache.maven.wagon.TransferFailedException)2 Wagon (org.apache.maven.wagon.Wagon)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 SocketTimeoutException (java.net.SocketTimeoutException)1 UnknownHostException (java.net.UnknownHostException)1 Credentials (org.apache.commons.httpclient.Credentials)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 MultiThreadedHttpConnectionManager (org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)1 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)1 GetMethod (org.apache.commons.httpclient.methods.GetMethod)1 HttpHost (org.apache.http.HttpHost)1 Credentials (org.apache.http.auth.Credentials)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)1