mirror of https://github.com/apache/archiva.git
add hack to configure User-Agent to download index from central
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1370588 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7dfd478f18
commit
2b224893bc
|
@ -19,14 +19,17 @@ package org.apache.archiva.proxy.common;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.maven.wagon.Wagon;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
|
@ -39,6 +42,8 @@ public class DefaultWagonFactory
|
|||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger( getClass() );
|
||||
|
||||
private DebugTransferListener debugTransferListener = new DebugTransferListener();
|
||||
|
||||
@Inject
|
||||
|
@ -56,6 +61,7 @@ public class DefaultWagonFactory
|
|||
|
||||
Wagon wagon = applicationContext.getBean( protocol, Wagon.class );
|
||||
wagon.addTransferListener( debugTransferListener );
|
||||
configureUserAgent( wagon );
|
||||
return wagon;
|
||||
}
|
||||
catch ( BeansException e )
|
||||
|
@ -63,4 +69,28 @@ public class DefaultWagonFactory
|
|||
throw new WagonFactoryException( e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
|
||||
protected void configureUserAgent( Wagon wagon )
|
||||
{
|
||||
try
|
||||
{
|
||||
Class clazz = wagon.getClass();
|
||||
Method getHttpHeaders = clazz.getMethod( "getHttpHeaders", null );
|
||||
|
||||
Properties headers = (Properties) getHttpHeaders.invoke( wagon, null );
|
||||
if ( headers == null )
|
||||
{
|
||||
headers = new Properties();
|
||||
}
|
||||
headers.put( "User-Agent", "Java" );
|
||||
Method setHttpHeaders = clazz.getMethod( "setHttpHeaders", new Class[]{ Properties.class } );
|
||||
setHttpHeaders.invoke( wagon, headers );
|
||||
|
||||
logger.debug( "http headers set to: {}", headers );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
logger.warn( "fail to configure User-Agent: " + e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.apache.maven.index.updater.IndexUpdater;
|
|||
import org.apache.maven.index.updater.ResourceFetcher;
|
||||
import org.apache.maven.wagon.ConnectionException;
|
||||
import org.apache.maven.wagon.ResourceDoesNotExistException;
|
||||
import org.apache.maven.wagon.StreamWagon;
|
||||
import org.apache.maven.wagon.TransferFailedException;
|
||||
import org.apache.maven.wagon.Wagon;
|
||||
import org.apache.maven.wagon.authentication.AuthenticationException;
|
||||
|
@ -128,7 +129,7 @@ public class DownloadRemoteIndexTask
|
|||
new URL( this.remoteRepository.getUrl() ).getProtocol() + ( ( this.networkProxy != null
|
||||
&& this.networkProxy.isUseNtlm() ) ? "-ntlm" : "" );
|
||||
|
||||
final Wagon wagon = wagonFactory.getWagon( wagonProtocol );
|
||||
final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon( wagonProtocol );
|
||||
int timeoutInMilliseconds = remoteRepository.getTimeout() * 1000;
|
||||
// FIXME olamy having 2 config values
|
||||
wagon.setReadTimeout( timeoutInMilliseconds );
|
||||
|
|
|
@ -46,7 +46,15 @@
|
|||
<level value="debug"/>
|
||||
</logger>
|
||||
|
||||
|
||||
<!-- apache httpclient debug content transfer-->
|
||||
<!--
|
||||
<logger name="org.apache.http.wire">
|
||||
<level value="debug"/>
|
||||
</logger>
|
||||
-->
|
||||
<logger name="org.apache.http.headers">
|
||||
<level value="debug"/>
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework">
|
||||
<level value="info"/>
|
||||
|
|
Loading…
Reference in New Issue