]> source.dussan.org Git - archiva.git/commitdiff
transform this interface to use a bean request will ease future enhancements
authorOlivier Lamy <olamy@apache.org>
Wed, 24 Oct 2012 19:50:16 +0000 (19:50 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 24 Oct 2012 19:50:16 +0000 (19:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1401843 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/DefaultWagonFactory.java
archiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/WagonFactory.java
archiva-modules/archiva-base/archiva-proxy-common/src/test/java/org/apache/archiva/proxy/common/WagonFactoryTest.java
archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411RepoGroupTest.java
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411Test.java
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java

index 1c6ccbb765648c589ab178c8d3a03029ca9e0967..8d711b82ea571002fd4884f1630f92dd7ede2198 100755 (executable)
@@ -29,13 +29,14 @@ import org.springframework.stereotype.Service;
 
 import javax.inject.Inject;
 import java.lang.reflect.Method;
+import java.util.Map;
 import java.util.Properties;
 
 /**
  * @author Olivier Lamy
  * @since 1.4-M1
  */
-@Service( "wagonFactory" )
+@Service ("wagonFactory")
 public class DefaultWagonFactory
     implements WagonFactory
 {
@@ -52,16 +53,18 @@ public class DefaultWagonFactory
         this.applicationContext = applicationContext;
     }
 
-    public Wagon getWagon( String protocol )
+    public Wagon getWagon( WagonFactoryRequest wagonFactoryRequest )
         throws WagonFactoryException
     {
         try
         {
-            protocol = StringUtils.startsWith( protocol, "wagon#" ) ? protocol : "wagon#" + protocol;
+            String protocol = StringUtils.startsWith( wagonFactoryRequest.getProtocol(), "wagon#" )
+                ? wagonFactoryRequest.getProtocol()
+                : "wagon#" + wagonFactoryRequest.getProtocol();
 
             Wagon wagon = applicationContext.getBean( protocol, Wagon.class );
             wagon.addTransferListener( debugTransferListener );
-            configureUserAgent( wagon );
+            configureUserAgent( wagon, wagonFactoryRequest );
             return wagon;
         }
         catch ( BeansException e )
@@ -70,7 +73,7 @@ public class DefaultWagonFactory
         }
     }
 
-    protected void configureUserAgent( Wagon wagon )
+    protected void configureUserAgent( Wagon wagon, WagonFactoryRequest wagonFactoryRequest )
     {
         try
         {
@@ -82,8 +85,17 @@ public class DefaultWagonFactory
             {
                 headers = new Properties();
             }
-            // FIXME make this configurable !!
-            headers.put( "User-Agent", "Java" );
+
+            headers.put( "User-Agent", wagonFactoryRequest.getUserAgent() );
+
+            if ( !wagonFactoryRequest.getHeaders().isEmpty() )
+            {
+                for ( Map.Entry<String, String> entry : wagonFactoryRequest.getHeaders().entrySet() )
+                {
+                    headers.put( entry.getKey(), entry.getValue() );
+                }
+            }
+
             Method setHttpHeaders = clazz.getMethod( "setHttpHeaders", new Class[]{ Properties.class } );
             setHttpHeaders.invoke( wagon, headers );
 
index 98eb427c287c0d91e16ba95735bf5eec2701d833..6e00c4a32422e5dc54753f484837fd2182b7ef15 100644 (file)
@@ -29,10 +29,10 @@ public interface WagonFactory
     /**
      * Create a new Wagon instance for the given protocol.
      *
-     * @param protocol the protocol to find the Wagon for, which must be prefixed with <code>wagon#</code>, for example
-     *                 <code>wagon#http</code>. <b>to have a wagon supporting ntlm add -ntlm</b>
+     * @param wagonFactoryRequest
+     *
      * @return the Wagon instance
      */
-    Wagon getWagon( String protocol )
+    Wagon getWagon( WagonFactoryRequest wagonFactoryRequest )
         throws WagonFactoryException;
 }
index c8c7860f02fd84cd3ad10cb84d233118f8d5650a..4937a56da6425ddc321f28781071be99b7eb3d40 100644 (file)
@@ -20,20 +20,19 @@ package org.apache.archiva.proxy.common;
  */
 
 import junit.framework.TestCase;
+import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 import org.apache.maven.wagon.Wagon;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.test.context.ContextConfiguration;
 
 import javax.inject.Inject;
-import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 
 /**
  * Test the WagonFactory works through Spring to be bound into the RepositoryProxyConnectors implementation.
- * 
  */
-@RunWith( ArchivaSpringJUnit4ClassRunner.class )
-@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml" } )
+@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
+@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml" } )
 public class WagonFactoryTest
     extends TestCase
 {
@@ -46,13 +45,13 @@ public class WagonFactoryTest
         throws Exception
     {
 
-        Wagon first = factory.getWagon( "wagon#file" );
-        
-        Wagon second = factory.getWagon( "wagon#file" );
+        Wagon first = factory.getWagon( new WagonFactoryRequest().protocol( "wagon#file" ) );
+
+        Wagon second = factory.getWagon( new WagonFactoryRequest().protocol( "wagon#file" ) );
 
         // ensure we support only protocol name too
-        Wagon third = factory.getWagon( "file" );
-        
+        Wagon third = factory.getWagon( new WagonFactoryRequest().protocol( "file" ) );
+
         assertNotSame( first, second );
 
         assertNotSame( first, third );
index bf2a8039fad40796e6e8d7b00a73462a5879fdf6..9334a88f0e923752a630b9adf26160f333194ff6 100644 (file)
@@ -43,6 +43,7 @@ import org.apache.archiva.policies.ProxyDownloadException;
 import org.apache.archiva.policies.urlcache.UrlFailureCache;
 import org.apache.archiva.proxy.common.WagonFactory;
 import org.apache.archiva.proxy.common.WagonFactoryException;
+import org.apache.archiva.proxy.common.WagonFactoryRequest;
 import org.apache.archiva.redback.components.registry.Registry;
 import org.apache.archiva.redback.components.registry.RegistryListener;
 import org.apache.archiva.redback.components.taskqueue.TaskQueueException;
@@ -703,8 +704,9 @@ public class DefaultRepositoryProxyConnectors
                     networkProxy = networkProxyAdmin.getNetworkProxy( connector.getProxyId() );
                 }
 
-                wagon = ( networkProxy != null && networkProxy.isUseNtlm() ) ? wagonFactory.getWagon(
-                    "wagon#" + protocol + "-ntlm" ) : wagonFactory.getWagon( "wagon#" + protocol );
+                wagon = ( networkProxy != null && networkProxy.isUseNtlm() )
+                    ? wagonFactory.getWagon( new WagonFactoryRequest().protocol( "wagon#" + protocol + "-ntlm" ) )
+                    : wagonFactory.getWagon( new WagonFactoryRequest().protocol( "wagon#" + protocol ) );
                 if ( wagon == null )
                 {
                     throw new ProxyException( "Unsupported target repository protocol: " + protocol );
index 8777fe9e22586b75990e5ffbe201018de189d339..92b6e04ad51e4937056981be929fd8d6f15cb0ad 100644 (file)
@@ -24,6 +24,7 @@ import org.apache.archiva.admin.model.beans.RemoteRepository;
 import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
 import org.apache.archiva.proxy.common.WagonFactory;
 import org.apache.archiva.proxy.common.WagonFactoryException;
+import org.apache.archiva.proxy.common.WagonFactoryRequest;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.time.StopWatch;
 import org.apache.maven.index.context.IndexingContext;
@@ -134,7 +135,8 @@ public class DownloadRemoteIndexTask
                 new URL( this.remoteRepository.getUrl() ).getProtocol() + ( ( this.networkProxy != null
                     && this.networkProxy.isUseNtlm() ) ? "-ntlm" : "" );
 
-            final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon( wagonProtocol );
+            final StreamWagon wagon =
+                (StreamWagon) wagonFactory.getWagon( new WagonFactoryRequest().protocol( wagonProtocol ) );
             int timeoutInMilliseconds = remoteRepository.getTimeout() * 1000;
             // FIXME olamy having 2 config values
             wagon.setReadTimeout( timeoutInMilliseconds );
index 142ba26b0973f3321ae984d68da6b9c99fe660bb..7351d8aa17e387a5c2534395b15a4fed3c33322c 100644 (file)
@@ -30,6 +30,7 @@ import org.apache.archiva.model.ArchivaRepositoryMetadata;
 import org.apache.archiva.model.SnapshotVersion;
 import org.apache.archiva.proxy.common.WagonFactory;
 import org.apache.archiva.proxy.common.WagonFactoryException;
+import org.apache.archiva.proxy.common.WagonFactoryRequest;
 import org.apache.archiva.xml.XMLException;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
@@ -236,9 +237,10 @@ public class RepositoryModelResolver
 
                 // 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(
-                    "wagon#" + protocol + "-ntlm" ) : wagonFactory.getWagon( "wagon#" + protocol );
-                wagon = wagonFactory.getWagon( "wagon#" + protocol );
+                wagon = ( networkProxy != null && networkProxy.isUseNtlm() )
+                    ? wagonFactory.getWagon( new WagonFactoryRequest().protocol( "wagon#" + protocol + "-ntlm" ) )
+                    : wagonFactory.getWagon( new WagonFactoryRequest().protocol( "wagon#" + protocol ) );
+                wagon = wagonFactory.getWagon( new WagonFactoryRequest().protocol( "wagon#" + protocol ) );
                 if ( wagon == null )
                 {
                     throw new RuntimeException( "Unsupported remote repository protocol: " + protocol );
index fc2488bbe0274b5488ca1d691de0d5d7a0264cf5..9a3a78cf6f9c76182244f77b82bfc5cc41381cfc 100644 (file)
@@ -36,6 +36,7 @@ import org.apache.archiva.metadata.repository.filter.AllFilter;
 import org.apache.archiva.metadata.repository.filter.Filter;
 import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest;
 import org.apache.archiva.proxy.common.WagonFactory;
+import org.apache.archiva.proxy.common.WagonFactoryRequest;
 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 import org.apache.commons.io.FileUtils;
 import org.apache.maven.wagon.Wagon;
@@ -55,15 +56,15 @@ import java.util.List;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
-@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
+@RunWith (ArchivaSpringJUnit4ClassRunner.class)
+@ContextConfiguration (locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
 public class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest
     extends TestCase
 {
     private static final Filter<String> ALL = new AllFilter<String>();
 
     @Inject
-    @Named ( value = "repositoryStorage#maven2" )
+    @Named (value = "repositoryStorage#maven2")
     private Maven2RepositoryStorage storage;
 
     private static final String TEST_REPO_ID = "test";
@@ -166,7 +167,7 @@ public class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest
         storage.setWagonFactory( wagonFactory );
 
         Wagon wagon = new MockWagon();
-        when( wagonFactory.getWagon( "wagon#http" ) ).thenReturn( wagon );
+        when( wagonFactory.getWagon( new WagonFactoryRequest().protocol( "wagon#http" ) ) ).thenReturn( wagon );
     }
 
     // Tests for MRM-1411 - START
index 292441d0cabdb3b41a8c1683f15dc9660d2709b6..af4ca72472e70f7c292227c7a9e706f46acb24b2 100644 (file)
@@ -36,6 +36,7 @@ import org.apache.archiva.metadata.repository.filter.Filter;
 import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest;
 import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException;
 import org.apache.archiva.proxy.common.WagonFactory;
+import org.apache.archiva.proxy.common.WagonFactoryRequest;
 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 import org.apache.commons.io.FileUtils;
 import org.apache.maven.wagon.Wagon;
@@ -134,7 +135,7 @@ public class Maven2RepositoryMetadataResolverMRM1411Test
         storage.setWagonFactory( wagonFactory );
 
         Wagon wagon = new MockWagon();
-        when( wagonFactory.getWagon( "wagon#http" ) ).thenReturn( wagon );
+        when( wagonFactory.getWagon( new WagonFactoryRequest().protocol( "wagon#http" ) ) ).thenReturn( wagon );
     }
 
     // Tests for MRM-1411 - START
index e173e3e4cfdb64cb75cdf060b2d0fd7c2938e282..0509b76df22b2c02010e3378fd4eebaa7777eba8 100644 (file)
@@ -38,6 +38,7 @@ import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest;
 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
 import org.apache.archiva.proxy.common.WagonFactory;
+import org.apache.archiva.proxy.common.WagonFactoryRequest;
 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 import org.apache.commons.io.FileUtils;
 import org.apache.maven.wagon.Wagon;
@@ -60,15 +61,15 @@ import java.util.List;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-@RunWith (ArchivaSpringJUnit4ClassRunner.class)
-@ContextConfiguration (locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
+@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
+@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
 public class Maven2RepositoryMetadataResolverTest
     extends TestCase
 {
     private static final Filter<String> ALL = new AllFilter<String>();
 
     @Inject
-    @Named (value = "repositoryStorage#maven2")
+    @Named ( value = "repositoryStorage#maven2" )
     private Maven2RepositoryStorage storage;
 
     private static final String TEST_REPO_ID = "test";
@@ -139,7 +140,7 @@ public class Maven2RepositoryMetadataResolverTest
         storage.setWagonFactory( wagonFactory );
 
         Wagon wagon = new MockWagon();
-        when( wagonFactory.getWagon( "wagon#http" ) ).thenReturn( wagon );
+        when( wagonFactory.getWagon( new WagonFactoryRequest().protocol( "wagon#http" ) ) ).thenReturn( wagon );
     }
 
     @Test