aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base/archiva-proxy-common
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2012-10-24 19:50:16 +0000
committerOlivier Lamy <olamy@apache.org>2012-10-24 19:50:16 +0000
commit4ba8af2e0ed8cb7395678da0814ecc9c914c60cc (patch)
treefee1dcb1da529309dd1827f490116fb0654cdd7d /archiva-modules/archiva-base/archiva-proxy-common
parent7b95f6c33c0c96c23d135e8962998fbbf4cea590 (diff)
downloadarchiva-4ba8af2e0ed8cb7395678da0814ecc9c914c60cc.tar.gz
archiva-4ba8af2e0ed8cb7395678da0814ecc9c914c60cc.zip
transform this interface to use a bean request will ease future enhancements
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1401843 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base/archiva-proxy-common')
-rwxr-xr-xarchiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/DefaultWagonFactory.java26
-rw-r--r--archiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/WagonFactory.java6
-rw-r--r--archiva-modules/archiva-base/archiva-proxy-common/src/test/java/org/apache/archiva/proxy/common/WagonFactoryTest.java17
3 files changed, 30 insertions, 19 deletions
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 1c6ccbb76..8d711b82e 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
@@ -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 );
diff --git a/archiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/WagonFactory.java b/archiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/WagonFactory.java
index 98eb427c2..6e00c4a32 100644
--- a/archiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/WagonFactory.java
+++ b/archiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/WagonFactory.java
@@ -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;
}
diff --git a/archiva-modules/archiva-base/archiva-proxy-common/src/test/java/org/apache/archiva/proxy/common/WagonFactoryTest.java b/archiva-modules/archiva-base/archiva-proxy-common/src/test/java/org/apache/archiva/proxy/common/WagonFactoryTest.java
index c8c7860f0..4937a56da 100644
--- a/archiva-modules/archiva-base/archiva-proxy-common/src/test/java/org/apache/archiva/proxy/common/WagonFactoryTest.java
+++ b/archiva-modules/archiva-base/archiva-proxy-common/src/test/java/org/apache/archiva/proxy/common/WagonFactoryTest.java
@@ -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 );