<?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
*/
private ArchivaConfiguration archivaConfiguration;
- /**
- * @plexus.requirement role="org.apache.maven.wagon.Wagon"
- */
- private Map<String, Wagon> wagons;
-
/**
* @plexus.requirement
*/
*/
private RepositoryContentConsumers consumers;
+ /**
+ * @plexus.requirement
+ */
+ private WagonFactory wagonFactory;
+
public File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact )
throws ProxyDownloadException
{
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 );
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 )
{
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 )
--- /dev/null
+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 );
+}
--- /dev/null
+<?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
import java.io.File;
import java.io.IOException;
-import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
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)
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()
--- /dev/null
+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 );
+ }
+}
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>