public void initProxy()

in commons-transfer/commons-transfer-http/src/main/java/org/apache/archiva/commons/transfer/http/HttpTransferBase.java [171:219]


    public void initProxy( URI uri )
    {
        TransferNetworkProxy proxy = getTransferStore().getNetworkProxy();

        // Skip if no proxy is defined.
        if ( proxy == null )
        {
            LOG.debug( "Not proxying [" + uri + "], NetworkProxy is null" );
            unsetProxy();
            return;
        }

        // Skip if proxy is not enabled.
        if ( !proxy.isEnabled() )
        {
            LOG.debug( "Not proxying [" + uri + "], NetworkProxy.enabled is false" );
            return;
        }

        // Skip if proxy is invalid.
        if ( !proxy.valid() )
        {
            LOG.debug( "Not proxying [" + uri + "], NetworkProxy is invalid" );
            return;
        }

        String hostname = uri.getHost();

        // Do settings exist?
        if ( proxy.needsProxy( hostname ) )
        {
            LOG.debug( "Setting up http proxy: " + proxy.getHost() + ":" + proxy.getPort() );
            ProxyHost netproxy = new ProxyHost( proxy.getHost(), proxy.getPort() );
            client.getHostConfiguration().setProxyHost( netproxy );

            // Do auth settings exist?
            if ( proxy.authExists() )
            {
                Credentials credentials = new UsernamePasswordCredentials( proxy.getUsername(), proxy.getPassword() );
                AuthScope authScope = new AuthScope( proxy.getHost(), proxy.getPort() );
                client.getState().setProxyCredentials( authScope, credentials );
                LOG.debug( "Setting up http proxy credentials for : " + proxy.getUsername() );
            }
        }
        else
        {
            LOG.debug( "Not proxying [" + uri + "], proxy.needsProxy(\"" + hostname + "\") is false" );
        }
    }