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
{
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 )
}
}
- protected void configureUserAgent( Wagon wagon )
+ protected void configureUserAgent( Wagon wagon, WagonFactoryRequest wagonFactoryRequest )
{
try
{
{
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 );
/**
* 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;
}
*/
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
{
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 );
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;
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 );
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;
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 );
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;
// 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 );
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;
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";
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
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;
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
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;
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";
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