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
This commit is contained in:
Olivier Lamy 2012-10-31 21:40:38 +00:00
parent 94a0638344
commit 27c8f4047c
5 changed files with 39 additions and 16 deletions

View File

@ -32,6 +32,10 @@
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-plexus-bridge</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-admin-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
@ -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
</Import-Package>

View File

@ -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 );

View File

@ -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 )
{

View File

@ -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 );

View File

@ -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 );