maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nico...@apache.org
Subject svn commit: r1162529 - in /maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src: main/java/org/apache/maven/wagon/providers/http/ test/java/org/apache/maven/wagon/providers/http/
Date Sun, 28 Aug 2011 14:24:23 GMT
Author: nicolas
Date: Sun Aug 28 14:24:23 2011
New Revision: 1162529

URL: http://svn.apache.org/viewvc?rev=1162529&view=rev
Log:
[WAGON-346] use openConnection(Proxy) in replacement to system properties

Modified:
    maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java
    maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpWagonTest.java
    maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpsWagonTest.java

Modified: maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java?rev=1162529&r1=1162528&r2=1162529&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java
Sun Aug 28 14:24:23 2011
@@ -38,8 +38,12 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.Authenticator;
 import java.net.HttpURLConnection;
+import java.net.InetSocketAddress;
 import java.net.MalformedURLException;
 import java.net.PasswordAuthentication;
+import java.net.Proxy;
+import java.net.Proxy.Type;
+import java.net.SocketAddress;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.ArrayList;
@@ -58,14 +62,10 @@ import java.util.zip.GZIPInputStream;
 public class LightweightHttpWagon
     extends StreamWagon
 {
-    private String previousProxyExclusions;
-
-    private String previousHttpProxyHost;
-
-    private String previousHttpProxyPort;
-
     private HttpURLConnection putConnection;
 
+    private Proxy proxy = Proxy.NO_PROXY;
+
     public static final int MAX_REDIRECTS = 10;
 
     /**
@@ -80,13 +80,6 @@ public class LightweightHttpWagon
      */
     private Properties httpHeaders;
 
-
-    private static final String HTTP_PROXY_HOST_SYSPROPS = "http.proxyHost";
-
-    private static final String HTTP_PROXY_PORT_SYSPROPS = "http.proxyPort";
-
-    private static final String HTTP_NON_PROXY_HOSTS_SYSPROPS = "http.nonProxyHosts";
-
     /**
      * Builds a complete URL string from the repository URL and the relative path passed.
      *
@@ -126,7 +119,7 @@ public class LightweightHttpWagon
                 visitedUrls.add( visitingUrl );
 
                 URL url = new URL( visitingUrl );
-                HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
+                HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(
this.proxy );
                 urlConnection.setRequestProperty( "Accept-Encoding", "gzip" );
                 if ( !useCache )
                 {
@@ -178,8 +171,6 @@ public class LightweightHttpWagon
             if ( getProxyInfo() != null && getProxyInfo().getHost() != null )
             {
                 message.append( " with proxyInfo " ).append( getProxyInfo().toString() );
-                message.append( " , proxy sysprops current " + System.getProperty( HTTP_PROXY_HOST_SYSPROPS
) + "/"
-                                    + System.getProperty( HTTP_PROXY_PORT_SYSPROPS ) );
             }
             throw new TransferFailedException( message.toString(), e );
         }
@@ -204,7 +195,7 @@ public class LightweightHttpWagon
         try
         {
             URL url = new URL( buildUrl( resource.getName() ) );
-            putConnection = (HttpURLConnection) url.openConnection();
+            putConnection = (HttpURLConnection) url.openConnection( this.proxy );
 
             addHeaders( putConnection );
 
@@ -259,23 +250,10 @@ public class LightweightHttpWagon
     protected void openConnectionInternal()
         throws ConnectionException, AuthenticationException
     {
-
-        previousHttpProxyHost = System.getProperty( HTTP_PROXY_HOST_SYSPROPS );
-        previousHttpProxyPort = System.getProperty( HTTP_PROXY_PORT_SYSPROPS );
-        previousProxyExclusions = System.getProperty( HTTP_NON_PROXY_HOSTS_SYSPROPS );
-
         final ProxyInfo proxyInfo = getProxyInfo( "http", getRepository().getHost() );
         if ( proxyInfo != null )
         {
-            setSystemProperty( HTTP_PROXY_HOST_SYSPROPS, proxyInfo.getHost() );
-            setSystemProperty( HTTP_PROXY_PORT_SYSPROPS, String.valueOf( proxyInfo.getPort()
) );
-            setSystemProperty( HTTP_NON_PROXY_HOSTS_SYSPROPS, proxyInfo.getNonProxyHosts()
);
-            System.out.println(" open connection with proxyInfo " + proxyInfo );
-        }
-        else
-        {
-            setSystemProperty( HTTP_PROXY_HOST_SYSPROPS, null );
-            setSystemProperty( HTTP_PROXY_PORT_SYSPROPS, null );
+            this.proxy = getProxy( proxyInfo );
         }
 
         final boolean hasProxy = ( proxyInfo != null && proxyInfo.getUserName() !=
null );
@@ -316,6 +294,24 @@ public class LightweightHttpWagon
         }
     }
 
+    private Proxy getProxy( ProxyInfo proxyInfo )
+    {
+        return new Proxy( getProxyType( proxyInfo ), getSocketAddress( proxyInfo ) );
+    }
+
+    private Type getProxyType( ProxyInfo proxyInfo ) {
+        if ( ProxyInfo.PROXY_SOCKS4.equals( proxyInfo.getType() ) || ProxyInfo.PROXY_SOCKS5.equals(
proxyInfo.getType() ) )
+        {
+            return Type.SOCKS;
+        }
+        else return Type.HTTP;
+    }
+
+    public SocketAddress getSocketAddress( ProxyInfo proxyInfo )
+    {
+        return InetSocketAddress.createUnresolved(proxyInfo.getHost(), proxyInfo.getPort());
+    }
+
     public void closeConnection()
         throws ConnectionException
     {
@@ -323,10 +319,6 @@ public class LightweightHttpWagon
         {
             putConnection.disconnect();
         }
-
-        setSystemProperty( HTTP_PROXY_HOST_SYSPROPS, previousHttpProxyHost );
-        setSystemProperty( HTTP_PROXY_PORT_SYSPROPS, previousHttpProxyPort );
-        setSystemProperty( HTTP_NON_PROXY_HOSTS_SYSPROPS, previousProxyExclusions );
     }
 
     public List getFileList( String destinationDirectory )
@@ -366,7 +358,7 @@ public class LightweightHttpWagon
         try
         {
             URL url = new URL( buildUrl( new Resource( resourceName ).getName() ) );
-            headConnection = (HttpURLConnection) url.openConnection();
+            headConnection = (HttpURLConnection) url.openConnection( this.proxy );
 
             addHeaders( headConnection );
 
@@ -422,7 +414,6 @@ public class LightweightHttpWagon
 
     void setSystemProperty( String key, String value )
     {
-        //System.out.println(" set sys prop  " + key + "/" + value);
         if ( value != null )
         {
             System.setProperty( key, value );

Modified: maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpWagonTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpWagonTest.java?rev=1162529&r1=1162528&r2=1162529&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpWagonTest.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpWagonTest.java
Sun Aug 28 14:24:23 2011
@@ -24,9 +24,7 @@ import org.apache.maven.wagon.Wagon;
 import org.apache.maven.wagon.http.HttpWagonTestCase;
 import org.apache.maven.wagon.proxy.ProxyInfo;
 import org.apache.maven.wagon.repository.Repository;
-import org.codehaus.plexus.util.FileUtils;
 
-import java.io.File;
 import java.util.Properties;
 
 /**
@@ -52,128 +50,4 @@ public class LightweightHttpWagonTest
         ( (LightweightHttpWagon) wagon ).setHttpHeaders( properties );
     }
 
-    public void testProxyReset()
-        throws Exception
-    {
-        ProxyInfo proxyInfo = new ProxyInfo();
-        proxyInfo.setType( "http" );
-        proxyInfo.setHost( "proxyhost" );
-        proxyInfo.setPort( 1234 );
-        proxyInfo.setNonProxyHosts( "non" );
-
-        Repository repository = new Repository();
-
-        String proxyHost = System.getProperty( "http.proxyHost" );
-        String proxyPort = System.getProperty( "http.proxyPort" );
-        String nonProxyHosts = System.getProperty( "http.nonProxyHosts" );
-
-        System.getProperties().remove( "http.proxyHost" );
-        System.getProperties().remove( "http.proxyPort" );
-
-        Wagon wagon = getWagon();
-
-        wagon.connect( repository, proxyInfo );
-
-        assertEquals( "proxyhost", System.getProperty( "http.proxyHost" ) );
-        assertEquals( "1234", System.getProperty( "http.proxyPort" ) );
-        assertEquals( "non", System.getProperty( "http.nonProxyHosts" ) );
-
-        wagon.disconnect();
-
-        assertNull( System.getProperty( "http.proxyHost" ) );
-        assertNull( System.getProperty( "http.proxyPort" ) );
-
-        System.setProperty( "http.proxyHost", "host" );
-        System.setProperty( "http.proxyPort", "port" );
-        System.setProperty( "http.nonProxyHosts", "hosts" );
-
-        wagon = getWagon();
-
-        wagon.connect( repository, proxyInfo );
-
-        assertEquals( "proxyhost", System.getProperty( "http.proxyHost" ) );
-        assertEquals( "1234", System.getProperty( "http.proxyPort" ) );
-        assertEquals( "non", System.getProperty( "http.nonProxyHosts" ) );
-
-        wagon.disconnect();
-
-        assertEquals( "host", System.getProperty( "http.proxyHost" ) );
-        assertEquals( "port", System.getProperty( "http.proxyPort" ) );
-        assertEquals( "hosts", System.getProperty( "http.nonProxyHosts" ) );
-
-        wagon = getWagon();
-
-        wagon.connect( repository );
-
-        assertNull( System.getProperty( "http.proxyHost" ) );
-        assertNull( System.getProperty( "http.proxyPort" ) );
-
-        wagon.disconnect();
-
-        assertEquals( "host", System.getProperty( "http.proxyHost" ) );
-        assertEquals( "port", System.getProperty( "http.proxyPort" ) );
-        assertEquals( "hosts", System.getProperty( "http.nonProxyHosts" ) );
-
-        if ( proxyHost != null )
-        {
-            System.setProperty( "http.proxyHost", proxyHost );
-        }
-        else
-        {
-            System.getProperties().remove( "http.proxyHost" );
-        }
-        if ( proxyPort != null )
-        {
-            System.setProperty( "http.proxyPort", proxyPort );
-        }
-        else
-        {
-            System.getProperties().remove( "http.proxyPort" );
-        }
-        if ( nonProxyHosts != null )
-        {
-            System.setProperty( "http.nonProxyHosts", nonProxyHosts );
-        }
-        else
-        {
-            System.getProperties().remove( "http.nonProxyHosts" );
-        }
-    }
-
-    /**
-     * This unit test will verify the behaviour of WAGON-314.
-     * Handling a HTTP redirect (301) properly
-     *
-     * It is disabled by default because it needs an online connection to maven.central
-     */
-    public void disabledtestHttpRedirect() throws Exception
-    {
-        Repository repository = new Repository( "apache.releases",
-                                        "http://repository.apache.org/service/local/repositories/releases/content/"
);
-
-        Wagon wagon = getWagon();
-
-        wagon.connect( repository );
-
-        File destinationDir = new File( "./target/" );
-        assertTrue( destinationDir.exists() );
-
-        File downloadedFile = new File( destinationDir, "downloadedFile.pom" );
-
-        if ( downloadedFile.exists() )
-        {
-            downloadedFile.delete();
-            assertFalse( downloadedFile.exists() );
-        }
-
-        wagon.get( "org/apache/maven/maven-parent/19/maven-parent-19.pom", downloadedFile
);
-
-        assertTrue( downloadedFile.exists() );
-
-        String artifactContent = FileUtils.fileRead( downloadedFile, "UTF-8" );
-        assertNotNull( artifactContent );
-        assertTrue( artifactContent.contains( "<artifactId>maven-parent</artifactId>"
) );
-
-        wagon.disconnect();
-    }
 }

Modified: maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpsWagonTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpsWagonTest.java?rev=1162529&r1=1162528&r2=1162529&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpsWagonTest.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpsWagonTest.java
Sun Aug 28 14:24:23 2011
@@ -19,9 +19,6 @@ package org.apache.maven.wagon.providers
  * under the License.
  */
 
-import org.apache.maven.wagon.Wagon;
-import org.apache.maven.wagon.proxy.ProxyInfo;
-import org.apache.maven.wagon.repository.Repository;
 import org.mortbay.jetty.Connector;
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.security.SslSocketConnector;
@@ -48,93 +45,4 @@ public class LightweightHttpsWagonTest
         connector.setTrustPassword( "wagonhttp" );
         server.setConnectors( new Connector[] { connector } );
     }
-
-    public void testHttpsProxyReset()
-        throws Exception
-    {
-        ProxyInfo proxyInfo = new ProxyInfo();
-        proxyInfo.setType( "https" );
-        proxyInfo.setHost( "proxyhost" );
-        proxyInfo.setPort( 1234 );
-        proxyInfo.setNonProxyHosts( "non" );
-
-        Repository repository = new Repository();
-
-        String proxyHost = System.getProperty( "https.proxyHost" );
-        String proxyPort = System.getProperty( "https.proxyPort" );
-        String nonProxyHosts = System.getProperty( "https.nonProxyHosts" );
-
-        System.getProperties().remove( "https.proxyHost" );
-        System.getProperties().remove( "https.proxyPort" );
-
-        Wagon wagon = getWagon();
-
-        wagon.connect( repository, proxyInfo );
-
-        assertEquals( "proxyhost", System.getProperty( "https.proxyHost" ) );
-        assertEquals( "1234", System.getProperty( "https.proxyPort" ) );
-        assertEquals( "non", System.getProperty( "https.nonProxyHosts" ) );
-
-        wagon.disconnect();
-
-        assertNull( System.getProperty( "https.proxyHost" ) );
-        assertNull( System.getProperty( "https.proxyPort" ) );
-
-        System.setProperty( "https.proxyHost", "host" );
-        System.setProperty( "https.proxyPort", "port" );
-        System.setProperty( "https.nonProxyHosts", "hosts" );
-
-        wagon = getWagon();
-
-        wagon.connect( repository, proxyInfo );
-
-        assertEquals( "proxyhost", System.getProperty( "https.proxyHost" ) );
-        assertEquals( "1234", System.getProperty( "https.proxyPort" ) );
-        assertEquals( "non", System.getProperty( "https.nonProxyHosts" ) );
-
-        wagon.disconnect();
-
-        assertEquals( "host", System.getProperty( "https.proxyHost" ) );
-        assertEquals( "port", System.getProperty( "https.proxyPort" ) );
-        assertEquals( "hosts", System.getProperty( "https.nonProxyHosts" ) );
-
-        wagon = getWagon();
-
-        wagon.connect( repository );
-
-        assertNull( System.getProperty( "https.proxyHost" ) );
-        assertNull( System.getProperty( "https.proxyPort" ) );
-
-        wagon.disconnect();
-
-        assertEquals( "host", System.getProperty( "https.proxyHost" ) );
-        assertEquals( "port", System.getProperty( "https.proxyPort" ) );
-        assertEquals( "hosts", System.getProperty( "https.nonProxyHosts" ) );
-
-        if ( proxyHost != null )
-        {
-            System.setProperty( "https.proxyHost", proxyHost );
-        }
-        else
-        {
-            System.getProperties().remove( "https.proxyHost" );
-        }
-        if ( proxyPort != null )
-        {
-            System.setProperty( "https.proxyPort", proxyPort );
-        }
-        else
-        {
-            System.getProperties().remove( "https.proxyPort" );
-        }
-        if ( nonProxyHosts != null )
-        {
-            System.setProperty( "https.nonProxyHosts", nonProxyHosts );
-        }
-        else
-        {
-            System.getProperties().remove( "https.nonProxyHosts" );
-        }
-    }
-
 }



Mime
View raw message