aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2012-08-07 23:21:01 +0000
committerOlivier Lamy <olamy@apache.org>2012-08-07 23:21:01 +0000
commit2b224893bceb711e01e1db308dbc00f7609e25a2 (patch)
treedd4e36fbaf612d3d832ebc3924a6e9e0bdb3d6dd
parent7dfd478f18d121da4a496cbc9eddf3ea79aa85d9 (diff)
downloadarchiva-2b224893bceb711e01e1db308dbc00f7609e25a2.tar.gz
archiva-2b224893bceb711e01e1db308dbc00f7609e25a2.zip
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
-rwxr-xr-xarchiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/DefaultWagonFactory.java32
-rw-r--r--archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java3
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-js/src/test/tomcat/log4j.xml10
3 files changed, 42 insertions, 3 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 8bf469a7a..629eda0e6 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
@@ -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 );
+ }
+ }
}
diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java
index b348ab2f4..fc1d4b069 100644
--- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java
+++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java
@@ -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 );
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/test/tomcat/log4j.xml b/archiva-modules/archiva-web/archiva-webapp-js/src/test/tomcat/log4j.xml
index 934409da7..76dead0e1 100644
--- a/archiva-modules/archiva-web/archiva-webapp-js/src/test/tomcat/log4j.xml
+++ b/archiva-modules/archiva-web/archiva-webapp-js/src/test/tomcat/log4j.xml
@@ -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"/>