maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joak...@apache.org
Subject svn commit: r485193 - /maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
Date Sun, 10 Dec 2006 15:24:51 GMT
Author: joakime
Date: Sun Dec 10 07:24:49 2006
New Revision: 485193

URL: http://svn.apache.org/viewvc?view=rev&rev=485193
Log:
Adding proxy support to webdav provider.

Modified:
    maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java

Modified: maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java?view=diff&rev=485193&r1=485192&r2=485193
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
Sun Dec 10 07:24:49 2006
@@ -16,27 +16,12 @@
  * limitations under the License.
  */
 
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-import java.util.Properties;
-import java.util.TimeZone;
-
 import org.apache.commons.httpclient.HttpException;
 import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.HttpURL;
 import org.apache.commons.httpclient.HttpsURL;
 import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
 import org.apache.maven.wagon.AbstractWagon;
 import org.apache.maven.wagon.ConnectionException;
 import org.apache.maven.wagon.LazyFileOutputStream;
@@ -54,6 +39,22 @@
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.Properties;
+import java.util.TimeZone;
+
 /**
  * <p>WebDavWagon</p>
  * 
@@ -114,6 +115,9 @@
     public void openConnection()
         throws AuthenticationException, ConnectionException
     {
+        final boolean hasProxy = ( proxyInfo != null && proxyInfo.getUserName() !=
null );
+        final boolean hasAuthentication = ( authenticationInfo != null && authenticationInfo.getUserName()
!= null );
+
         String url = getURL( repository );
 
         repository.setUrl( url );
@@ -123,8 +127,8 @@
         try
         {
             httpURL = urlToHttpURL( url );
-            
-            if ( authenticationInfo != null )
+
+            if ( hasAuthentication )
             {
                 String userName = authenticationInfo.getUserName();
                 String password = authenticationInfo.getPassword();
@@ -137,6 +141,20 @@
 
             CorrectedWebdavResource.setDefaultAction( CorrectedWebdavResource.NOACTION );
             webdavResource = new CorrectedWebdavResource( httpURL );
+
+            if ( hasProxy )
+            {
+                
+                
+                webdavResource.setProxy( proxyInfo.getHost(), proxyInfo.getPort() );
+                if ( !StringUtils.isEmpty( proxyInfo.getUserName() ) )
+                {
+                    UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials();
+                    proxyCredentials.setUserName( proxyInfo.getUserName() );
+                    proxyCredentials.setPassword( proxyInfo.getPassword() );
+                    webdavResource.setProxyCredentials( proxyCredentials );
+                }
+            }
         }
         catch ( HttpException he )
         {
@@ -268,7 +286,7 @@
             InputStream is = new PutInputStream( source, resource, this, getTransferEventSupport()
);
             boolean success = webdavResource.putMethod( dest, is, (int) source.length() );
             int statusCode = webdavResource.getStatusCode();
-            
+
             switch ( statusCode )
             {
                 case HttpStatus.SC_OK:
@@ -286,7 +304,7 @@
                 case HttpStatus.SC_LENGTH_REQUIRED:
                     throw new ResourceDoesNotExistException( "Transfer failed, server requires
Content-Length." );
 
-                //add more entries here
+                    //add more entries here
                 default:
                     if ( !success )
                     {
@@ -401,7 +419,7 @@
         }
 
         InputStream is = null;
-        OutputStream output = new LazyFileOutputStream( destination ); 
+        OutputStream output = new LazyFileOutputStream( destination );
         try
         {
             is = webdavResource.getMethodData( url );
@@ -416,7 +434,7 @@
         catch ( IOException e )
         {
             fireTransferError( resource, e, TransferEvent.REQUEST_GET );
-            
+
             if ( destination.exists() )
             {
                 boolean deleted = destination.delete();
@@ -447,8 +465,8 @@
 
                 default:
                     throw new TransferFailedException( "Failed to transfer file: " + url
+ ". Return code is: "
-                                                       + statusCode, e );
-            }                
+                        + statusCode, e );
+            }
         }
         finally
         {
@@ -482,7 +500,7 @@
                 throw new TransferFailedException( "Failed to transfer file: " + url + ".
Return code is: "
                     + statusCode );
         }
-        
+
     }
 
     private String getURL( Repository repository )
@@ -498,7 +516,7 @@
             return url;
         }
     }
-    
+
     /**
      * This wagon supports directory copying
      * 
@@ -508,7 +526,7 @@
     {
         return true;
     }
-    
+
     /**
      * Copy a directory from local system to remote webdav server
      * 
@@ -518,11 +536,11 @@
      * @throws ResourceDoesNotExistException
      * @throws AuthorizationException
      */
-    public void putDirectory( File sourceDirectory, String destinationDirectory ) 
+    public void putDirectory( File sourceDirectory, String destinationDirectory )
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
     {
-        
-        File [] listFiles = sourceDirectory.listFiles();
+
+        File[] listFiles = sourceDirectory.listFiles();
 
         for ( int i = 0; i < listFiles.length; i++ )
         {
@@ -533,7 +551,7 @@
             else
             {
                 String target = destinationDirectory + "/" + listFiles[i].getName();
-                
+
                 put( listFiles[i], target );
             }
         }
@@ -622,7 +640,7 @@
     }
 
     public boolean resourceExists( String resourceName )
-        throws TransferFailedException, AuthorizationException 
+        throws TransferFailedException, AuthorizationException
     {
         try
         {



---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-commits-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-commits-help@maven.apache.org


Mime
View raw message