From 27c8f4047caf10fa1a0db28e61f2170faa437785 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 31 Oct 2012 21:40:38 +0000 Subject: [PATCH] move ntlm wagon trick in wagonFactory to avoid duplicate code git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1404367 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva-base/archiva-proxy-common/pom.xml | 5 +++++ .../proxy/common/DefaultWagonFactory.java | 7 +++++++ .../proxy/common/WagonFactoryRequest.java | 20 +++++++++++++++++++ .../indexing/DownloadRemoteIndexTask.java | 7 +++---- .../maven2/RepositoryModelResolver.java | 16 ++++----------- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-proxy-common/pom.xml b/archiva-modules/archiva-base/archiva-proxy-common/pom.xml index b55beafeb..cc3285a0e 100644 --- a/archiva-modules/archiva-base/archiva-proxy-common/pom.xml +++ b/archiva-modules/archiva-base/archiva-proxy-common/pom.xml @@ -32,6 +32,10 @@ org.apache.archiva archiva-plexus-bridge + + org.apache.archiva + archiva-repository-admin-api + org.apache.maven.wagon wagon-provider-api @@ -87,6 +91,7 @@ org.springframework.stereotype;version="[3,4)", org.springframework.context;version="[3,4)", org.springframework.beans;version="[3,4)", + org.apache.archiva.admin.model.beans;version=${project.version}, org.apache.maven.wagon*, org.slf4j;resolution:=optional diff --git a/archiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/DefaultWagonFactory.java b/archiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/DefaultWagonFactory.java index 8d711b82e..50e9d616c 100755 --- a/archiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/DefaultWagonFactory.java +++ b/archiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/DefaultWagonFactory.java @@ -62,6 +62,13 @@ public class DefaultWagonFactory ? wagonFactoryRequest.getProtocol() : "wagon#" + wagonFactoryRequest.getProtocol(); + // if it's a ntlm proxy we have to lookup the wagon light which support thats + // wagon http client doesn't support that + if ( wagonFactoryRequest.getNetworkProxy() != null && wagonFactoryRequest.getNetworkProxy().isUseNtlm() ) + { + protocol = protocol + "-ntlm"; + } + Wagon wagon = applicationContext.getBean( protocol, Wagon.class ); wagon.addTransferListener( debugTransferListener ); configureUserAgent( wagon, wagonFactoryRequest ); diff --git a/archiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/WagonFactoryRequest.java b/archiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/WagonFactoryRequest.java index 13ffce6d0..613f20cde 100644 --- a/archiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/WagonFactoryRequest.java +++ b/archiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/WagonFactoryRequest.java @@ -18,6 +18,8 @@ package org.apache.archiva.proxy.common; * under the License. */ +import org.apache.archiva.admin.model.beans.NetworkProxy; + import java.util.HashMap; import java.util.Map; @@ -37,6 +39,8 @@ public class WagonFactoryRequest private String userAgent = "Java-Archiva"; + private NetworkProxy networkProxy; + public WagonFactoryRequest() { // no op @@ -100,6 +104,22 @@ public class WagonFactoryRequest return this; } + public NetworkProxy getNetworkProxy() + { + return networkProxy; + } + + public void setNetworkProxy( NetworkProxy networkProxy ) + { + this.networkProxy = networkProxy; + } + + public WagonFactoryRequest networkProxy( NetworkProxy networkProxy ) + { + this.networkProxy = networkProxy; + return this; + } + @Override public boolean equals( Object o ) { diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java index 5c08d8d4b..eb8053c6f 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java @@ -132,12 +132,11 @@ public class DownloadRemoteIndexTask tempIndexDirectory.deleteOnExit(); String baseIndexUrl = indexingContext.getIndexUpdateUrl(); - String wagonProtocol = - new URL( this.remoteRepository.getUrl() ).getProtocol() + ( ( this.networkProxy != null - && this.networkProxy.isUseNtlm() ) ? "-ntlm" : "" ); + String wagonProtocol = new URL( this.remoteRepository.getUrl() ).getProtocol(); final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon( - new WagonFactoryRequest( wagonProtocol, this.remoteRepository.getExtraHeaders() ) ); + new WagonFactoryRequest( wagonProtocol, this.remoteRepository.getExtraHeaders() ).networkProxy( + this.networkProxy ) ); int timeoutInMilliseconds = remoteRepository.getTimeout() * 1000; // FIXME olamy having 2 config values wagon.setReadTimeout( timeoutInMilliseconds ); diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java index 545312762..08aacd166 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java @@ -235,18 +235,10 @@ public class RepositoryModelResolver String protocol = getProtocol( remoteRepository.getUrl() ); final NetworkProxy networkProxy = this.networkProxyMap.get( remoteRepository.getId() ); - // if it's a ntlm proxy we have to lookup the wagon light which support thats - // wagon http client doesn't support that - wagon = ( networkProxy != null && networkProxy.isUseNtlm() ) - ? wagonFactory.getWagon( - new WagonFactoryRequest( "wagon#" + protocol + "-ntlm", remoteRepository.getExtraHeaders() ) ) - : wagonFactory.getWagon( - new WagonFactoryRequest( "wagon#" + protocol, remoteRepository.getExtraHeaders() ) ); - if ( wagon == null ) - { - wagon = wagonFactory.getWagon( - new WagonFactoryRequest( "wagon#" + protocol, remoteRepository.getExtraHeaders() ) ); - } + wagon = wagonFactory.getWagon( + new WagonFactoryRequest( "wagon#" + protocol, remoteRepository.getExtraHeaders() ).networkProxy( + networkProxy ) ); + if ( wagon == null ) { throw new RuntimeException( "Unsupported remote repository protocol: " + protocol ); -- 2.39.5