mirror of https://github.com/apache/archiva.git
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
This commit is contained in:
parent
7b95f6c33c
commit
4ba8af2e0e
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue