]> source.dussan.org Git - archiva.git/commitdiff
[MRM-631] ensure wagon lookups get a new instance on each request, reset HTTP propert...
authorBrett Porter <brett@apache.org>
Tue, 29 Jul 2008 16:24:02 +0000 (16:24 +0000)
committerBrett Porter <brett@apache.org>
Tue, 29 Jul 2008 16:24:02 +0000 (16:24 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@680755 13f79535-47bb-0310-9956-ffa450edef68

15 files changed:
archiva-modules/archiva-base/archiva-policies/src/main/resources/META-INF/spring-context.xml
archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java
archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/WagonFactory.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-proxy/src/main/resources/META-INF/spring-context.xml [new file with mode: 0644]
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/HttpProxyTransferTest.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/WagonFactoryTest.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.xml
archiva-modules/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ChecksumTransferTest.xml
archiva-modules/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ErrorHandlingTest.xml
archiva-modules/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/HttpProxyTransferTest.xml
archiva-modules/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.xml
archiva-modules/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.xml
archiva-modules/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/MetadataTransferTest.xml
archiva-modules/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/RelocateTransferTest.xml
archiva-modules/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/SnapshotTransferTest.xml

index 840223b1a0298a8f65002f81ab72f32ed8327df1..75a5d41c01e5cebce8a3525d8df419d6cf1f4c50 100644 (file)
@@ -1,12 +1,32 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+-->
 <beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="http://www.springframework.org/schema/beans
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
 
-  <bean id="urlFailureCache" class="org.apache.maven.archiva.policies.urlcache.DefaultUrlFailureCache">
+  <bean id="urlFailureCache"
+    class="org.apache.maven.archiva.policies.urlcache.DefaultUrlFailureCache">
     <!-- collaborators and configuration for this bean go here -->
-    <constructor-arg ref="cache#url-failures-cache" type="org.codehaus.plexus.cache.Cache"/>
+    <constructor-arg ref="cache#url-failures-cache"
+      type="org.codehaus.plexus.cache.Cache" />
   </bean>
 
 </beans>
\ No newline at end of file
index f8cfca84fc8c3ee3c7a409f553eb843d5fe53e61..f27b94aa7d28c16e147179d71ad033dd584616a0 100644 (file)
@@ -94,11 +94,6 @@ public class DefaultRepositoryProxyConnectors
      */
     private ArchivaConfiguration archivaConfiguration;
 
-    /**
-     * @plexus.requirement role="org.apache.maven.wagon.Wagon"
-     */
-    private Map<String, Wagon> wagons;
-
     /**
      * @plexus.requirement
      */
@@ -138,6 +133,11 @@ public class DefaultRepositoryProxyConnectors
      */
     private RepositoryContentConsumers consumers;
 
+    /**
+     * @plexus.requirement
+     */
+    private WagonFactory wagonFactory;
+
     public File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact )
         throws ProxyDownloadException
     {
@@ -589,12 +589,17 @@ public class DefaultRepositoryProxyConnectors
             return null;
         }
 
+        // MRM-631 - the lightweight wagon does not reset these - remove if we switch to httpclient based wagon
+        String previousHttpProxyHost = System.getProperty( "http.proxyHost" );
+        String previousHttpProxyPort = System.getProperty( "http.proxyPort" );
+        String previousProxyExclusions = System.getProperty( "http.nonProxyHosts" );
+
         Wagon wagon = null;
         try
         {
             RepositoryURL repoUrl = remoteRepository.getURL();
             String protocol = repoUrl.getProtocol();
-            wagon = (Wagon) wagons.get( protocol );
+            wagon = (Wagon) wagonFactory.getWagon( "wagon#" + protocol );
             if ( wagon == null )
             {
                 throw new ProxyException( "Unsupported target repository protocol: " + protocol );
@@ -633,6 +638,32 @@ public class DefaultRepositoryProxyConnectors
                 try
                 {
                     wagon.disconnect();
+
+                    // MRM-631 - the lightweight wagon does not reset these - remove if we switch to httpclient based wagon
+                    if ( previousHttpProxyHost != null )
+                    {
+                        System.setProperty( "http.proxyHost", previousHttpProxyHost );
+                    }
+                    else
+                    {
+                        System.getProperties().remove( "http.proxyHost" );
+                    }
+                    if ( previousHttpProxyPort != null )
+                    {
+                        System.setProperty( "http.proxyPort", previousHttpProxyPort );
+                    }
+                    else
+                    {
+                        System.getProperties().remove( "http.proxyPort" );
+                    }
+                    if ( previousProxyExclusions != null )
+                    {
+                        System.setProperty( "http.nonProxyHosts", previousProxyExclusions );
+                    }
+                    else
+                    {
+                        System.getProperties().remove( "http.nonProxyHosts" );
+                    }
                 }
                 catch ( ConnectionException e )
                 {
@@ -970,14 +1001,7 @@ public class DefaultRepositoryProxyConnectors
             wagon.setTimeout(timeoutInMilliseconds);
 
             Repository wagonRepository = new Repository( remoteRepository.getId(), remoteRepository.getURL().toString() );
-            if ( networkProxy != null )
-            {
-                wagon.connect( wagonRepository, authInfo, networkProxy );
-            }
-            else
-            {
-                wagon.connect( wagonRepository, authInfo );
-            }
+            wagon.connect( wagonRepository, authInfo, networkProxy );
             connected = true;
         }
         catch ( ConnectionException e )
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/WagonFactory.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/WagonFactory.java
new file mode 100644 (file)
index 0000000..a32d155
--- /dev/null
@@ -0,0 +1,39 @@
+package org.apache.maven.archiva.proxy;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.wagon.Wagon;
+
+/**
+ * Create a Wagon instance for the given protocol. Implementation will be provided by a Spring service locator.
+ * 
+ * @author Brett Porter
+ */
+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>.
+     * @return  the Wagon instance
+     */
+    Wagon getWagon( String protocol );
+}
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-proxy/src/main/resources/META-INF/spring-context.xml
new file mode 100644 (file)
index 0000000..baae587
--- /dev/null
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans
+           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+  <bean id="wagonFactory"
+    class="org.springframework.beans.factory.config.ServiceLocatorFactoryBean">
+    <property name="serviceLocatorInterface"
+      value="org.apache.maven.archiva.proxy.WagonFactory" />
+  </bean>
+</beans>
\ No newline at end of file
index 63285c658c42c97ad2dc5985da69a8698ce05800..1c2aa9a20d262d8fecbb82a3728c17e970b88113 100644 (file)
@@ -21,7 +21,6 @@ package org.apache.maven.archiva.proxy;
 
 import java.io.File;
 import java.io.IOException;
-import java.util.Enumeration;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -160,6 +159,9 @@ public class HttpProxyTransferTest
     public void testGetOverHttpProxy()
         throws Exception
     {
+        assertNull( System.getProperty( "http.proxyHost" ) );
+        assertNull( System.getProperty( "http.proxyPort" ) );
+        
         String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
 
         // Configure Connector (usually done within archiva.xml configuration)
@@ -183,6 +185,9 @@ public class HttpProxyTransferTest
         String expectedContents = FileUtils.readFileToString( sourceFile, null );
         String actualContents = FileUtils.readFileToString( downloadedFile, null );
         assertEquals( "Check file contents.", expectedContents, actualContents );
+        
+        assertNull( System.getProperty( "http.proxyHost" ) );
+        assertNull( System.getProperty( "http.proxyPort" ) );
     }
 
     private void addConnector()
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/WagonFactoryTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/WagonFactoryTest.java
new file mode 100644 (file)
index 0000000..3e31f9a
--- /dev/null
@@ -0,0 +1,43 @@
+package org.apache.maven.archiva.proxy;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.wagon.Wagon;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+
+/**
+ * Test the WagonFactory works through Spring to be bound into the RepositoryProxyConnectors implementation.
+ * 
+ * @author Brett Porter
+ */
+public class WagonFactoryTest
+    extends PlexusInSpringTestCase
+{
+    public void testLookupSuccessiveWagons()
+    {
+        WagonFactory factory = (WagonFactory) lookup( WagonFactory.class );
+        
+        Wagon first = factory.getWagon( "wagon#file" );
+        
+        Wagon second = factory.getWagon( "wagon#file" );
+        
+        assertNotSame( first, second );
+    }
+}
index 70fec59ff2bc7c4e8fc402e36f687725ae772a99..7ad475f57f90b4d97d719e414c57b06f5ebd11f6 100644 (file)
@@ -54,8 +54,7 @@
           <field-name>archivaConfiguration</field-name>
         </requirement>
         <requirement>
-          <role>org.apache.maven.wagon.Wagon</role>
-          <field-name>wagons</field-name>
+          <role>org.apache.maven.archiva.proxy.WagonFactory</role>
         </requirement>
         <requirement>
           <role>org.apache.maven.archiva.repository.RepositoryContentFactory</role>
index 5e48717e4f21666b03d960b7657833e0d86574d0..e9dfa4cc6991fd4aecec16521d46e8b69381ff62 100644 (file)
@@ -54,8 +54,7 @@
           <field-name>archivaConfiguration</field-name>
         </requirement>
         <requirement>
-          <role>org.apache.maven.wagon.Wagon</role>
-          <field-name>wagons</field-name>
+          <role>org.apache.maven.archiva.proxy.WagonFactory</role>
         </requirement>
         <requirement>
           <role>org.apache.maven.archiva.repository.RepositoryContentFactory</role>
index b1ada8f0287a73cb387e8ded83fc11c5f7db696b..fad392c509a1f7d6c2c6e6c0d287f6be886e24fd 100644 (file)
@@ -54,8 +54,7 @@
           <field-name>archivaConfiguration</field-name>
         </requirement>
         <requirement>
-          <role>org.apache.maven.wagon.Wagon</role>
-          <field-name>wagons</field-name>
+          <role>org.apache.maven.archiva.proxy.WagonFactory</role>
         </requirement>
         <requirement>
           <role>org.apache.maven.archiva.repository.RepositoryContentFactory</role>
index 9c3909d626c5303da85fbd1894056a83aa31fe42..bc10178b5b740c58eac11a0995ac652a86756a1e 100644 (file)
           <role-hint>mock</role-hint>
           <field-name>archivaConfiguration</field-name>
         </requirement>
-        <requirement>
-          <role>org.apache.maven.wagon.Wagon</role>
-          <field-name>wagons</field-name>
-        </requirement>
         <requirement>
           <role>org.apache.maven.archiva.repository.RepositoryContentFactory</role>
           <role-hint>mocked</role-hint>
           <role>org.apache.maven.archiva.policies.urlcache.UrlFailureCache</role>
           <field-name>urlFailureCache</field-name>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.proxy.WagonFactory</role>
+          <role-hint>default</role-hint>
+        </requirement>
       </requirements>
     </component>
 
index 5e48717e4f21666b03d960b7657833e0d86574d0..e9dfa4cc6991fd4aecec16521d46e8b69381ff62 100644 (file)
@@ -54,8 +54,7 @@
           <field-name>archivaConfiguration</field-name>
         </requirement>
         <requirement>
-          <role>org.apache.maven.wagon.Wagon</role>
-          <field-name>wagons</field-name>
+          <role>org.apache.maven.archiva.proxy.WagonFactory</role>
         </requirement>
         <requirement>
           <role>org.apache.maven.archiva.repository.RepositoryContentFactory</role>
index 5e48717e4f21666b03d960b7657833e0d86574d0..e9dfa4cc6991fd4aecec16521d46e8b69381ff62 100644 (file)
@@ -54,8 +54,7 @@
           <field-name>archivaConfiguration</field-name>
         </requirement>
         <requirement>
-          <role>org.apache.maven.wagon.Wagon</role>
-          <field-name>wagons</field-name>
+          <role>org.apache.maven.archiva.proxy.WagonFactory</role>
         </requirement>
         <requirement>
           <role>org.apache.maven.archiva.repository.RepositoryContentFactory</role>
index 1ca34af8a9861fdad66fd3cc126c711987a9b812..fe348d3f7007cc8c1163054e28d5f6da9fdbc19c 100644 (file)
@@ -73,8 +73,7 @@
           <field-name>archivaConfiguration</field-name>
         </requirement>
         <requirement>
-          <role>org.apache.maven.wagon.Wagon</role>
-          <field-name>wagons</field-name>
+          <role>org.apache.maven.archiva.proxy.WagonFactory</role>
         </requirement>
         <requirement>
           <role>org.apache.maven.archiva.repository.RepositoryContentFactory</role>
index 5e48717e4f21666b03d960b7657833e0d86574d0..e9dfa4cc6991fd4aecec16521d46e8b69381ff62 100644 (file)
@@ -54,8 +54,7 @@
           <field-name>archivaConfiguration</field-name>
         </requirement>
         <requirement>
-          <role>org.apache.maven.wagon.Wagon</role>
-          <field-name>wagons</field-name>
+          <role>org.apache.maven.archiva.proxy.WagonFactory</role>
         </requirement>
         <requirement>
           <role>org.apache.maven.archiva.repository.RepositoryContentFactory</role>
index 5e48717e4f21666b03d960b7657833e0d86574d0..e9dfa4cc6991fd4aecec16521d46e8b69381ff62 100644 (file)
@@ -54,8 +54,7 @@
           <field-name>archivaConfiguration</field-name>
         </requirement>
         <requirement>
-          <role>org.apache.maven.wagon.Wagon</role>
-          <field-name>wagons</field-name>
+          <role>org.apache.maven.archiva.proxy.WagonFactory</role>
         </requirement>
         <requirement>
           <role>org.apache.maven.archiva.repository.RepositoryContentFactory</role>