maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r348740 - in /maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src: main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java test/java/org/apache/maven/wagon/providers/http/LightweightHttpWagonTest.java
Date Thu, 24 Nov 2005 14:23:13 GMT
Author: evenisse
Date: Thu Nov 24 06:23:07 2005
New Revision: 348740

URL: http://svn.apache.org/viewcvs?rev=348740&view=rev
Log:
PR: WAGON-28
Submitted by: David Hawkins

Support PUT operations for file upload

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

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/viewcvs/maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java?rev=348740&r1=348739&r2=348740&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
Thu Nov 24 06:23:07 2005
@@ -23,13 +23,16 @@
 import org.apache.maven.wagon.StreamWagon;
 import org.apache.maven.wagon.TransferFailedException;
 import org.apache.maven.wagon.authentication.AuthenticationException;
+import org.apache.maven.wagon.authorization.AuthorizationException;
 import org.apache.maven.wagon.proxy.ProxyInfo;
 import org.apache.maven.wagon.repository.Repository;
 import org.apache.maven.wagon.resource.Resource;
 
+import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.Authenticator;
+import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.PasswordAuthentication;
 import java.net.URL;
@@ -47,6 +50,8 @@
     private String previousProxyHost;
 
     private String previousProxyPort;
+    
+    private HttpURLConnection putConnection;
 
     public void fillInputData( InputData inputData )
         throws TransferFailedException, ResourceDoesNotExistException
@@ -89,8 +94,52 @@
     public void fillOutputData( OutputData outputData )
         throws TransferFailedException
     {
-        throw new UnsupportedOperationException( "PUT operation is not supported by Light
Weight  HTTP wagon" );
+        Repository repository = getRepository();
+        String repositoryUrl = repository.getUrl();
+        
+        Resource resource = outputData.getResource();
+        try
+        {
+            URL url;
+            if ( repositoryUrl.endsWith( "/" ) )
+            {
+                url = new URL( repositoryUrl + resource.getName() );
+            }
+            else
+            {
+                url = new URL( repositoryUrl + "/" + resource.getName() );
+            }
+            putConnection = (HttpURLConnection) url.openConnection();
+            
+            putConnection.setRequestMethod("PUT");
+            putConnection.setDoOutput(true);
+            outputData.setOutputStream(putConnection.getOutputStream());
+        }
+        catch ( IOException e )
+        {
+            throw new TransferFailedException( "Error transferring file", e );
+        }
     }
+    
+    
+    public void put( File source, String resourceName )
+        throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+    {
+        super.put( source, resourceName );
+        
+        try
+        {
+            if ( putConnection.getResponseCode() != HttpURLConnection.HTTP_OK )
+            {
+                throw new TransferFailedException("Unable to transfer file. HttpURLConnection
returned the response code: " + putConnection.getResponseCode() );
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new TransferFailedException("Error transferring file", e);
+        }
+    }
+    
 
     public void openConnection()
         throws ConnectionException, AuthenticationException
@@ -149,6 +198,10 @@
     public void closeConnection()
         throws ConnectionException
     {
+        if ( putConnection != null )
+        {
+            putConnection.disconnect();
+        }
         if ( previousProxyHost != null )
         {
             System.setProperty( "http.proxyHost", previousProxyHost );

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/viewcvs/maven/wagon/trunk/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpWagonTest.java?rev=348740&r1=348739&r2=348740&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
Thu Nov 24 06:23:07 2005
@@ -72,12 +72,7 @@
 
         httpd = (Httpd) lookup( Httpd.ROLE );
     }
-
-    protected void fileRoundTripTesting()
-    {
-        // skip - PUT not supported
-    }
-
+    
     protected void tearDownWagonTestingFixtures()
         throws Exception
     {



---------------------------------------------------------------------
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