You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2020/04/19 21:35:30 UTC

[maven-wagon] 02/02: Second shot

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch WAGON-580
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git

commit 1814f009beae3113155f5ac6b578635fbe17ec96
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sun Apr 19 23:35:10 2020 +0200

    Second shot
---
 .../maven/wagon/providers/http/LightweightHttpWagon.java     | 12 ++++++------
 .../maven/wagon/shared/http/AbstractHttpClientWagon.java     |  4 ++--
 .../org/apache/maven/wagon/providers/webdav/WebDavWagon.java | 10 ++++++++--
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java b/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java
index 34240c4..f8bb92a 100644
--- a/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java
+++ b/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java
@@ -444,27 +444,27 @@ public class LightweightHttpWagon
             headConnection.setRequestMethod( "HEAD" );
 
             int statusCode = headConnection.getResponseCode();
+            String reasonPhrase = headConnection.getResponseMessage();
 
             switch ( statusCode )
             {
                 case HttpURLConnection.HTTP_OK:
                     return true;
 
-                case HttpURLConnection.HTTP_FORBIDDEN:
-                    throw new AuthorizationException( "Access denied to: " + url );
-
                 case HttpURLConnection.HTTP_NOT_FOUND:
                 case HttpURLConnection.HTTP_GONE:
                     return false;
 
                 // TODO Move 401/407 to AuthenticationException after WAGON-587
+                case HttpURLConnection.HTTP_FORBIDDEN:
                 case HttpURLConnection.HTTP_UNAUTHORIZED:
                 case HttpURLConnection.HTTP_PROXY_AUTH:
-                    throw new AuthorizationException( "Access denied to: " + url );
+                    throw new AuthorizationException( formatAuthorizationMessage( buildUrl( resource ),
+                            statusCode, reasonPhrase, getProxyInfo() ) );
 
                 default:
-                    throw new TransferFailedException(
-                        "Failed to look for file: " + buildUrl( resource ) + ". Return code is: " + statusCode );
+                    throw new TransferFailedException( formatTransferFailedMessage( buildUrl( resource ),
+                            statusCode, reasonPhrase, getProxyInfo() ) );
             }
         }
         catch ( IOException e )
diff --git a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
index bebadd8..1851d9b 100644
--- a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
+++ b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
@@ -329,8 +329,8 @@ public abstract class AbstractHttpClientWagon
         int nextWait = wait * 2;
         if ( nextWait >= getMaxBackoffWaitSeconds() )
         {
-            throw new TransferFailedException(
-                "Waited too long to access: " + url + ". Return code is: " + SC_TOO_MANY_REQUESTS );
+            throw new TransferFailedException( formatTransferFailedMessage( url, SC_TOO_MANY_REQUESTS,
+                    null, getProxyInfo() ) );
         }
         return nextWait;
     }
diff --git a/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java b/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
index e7736b4..9460875 100644
--- a/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
+++ b/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
@@ -53,6 +53,8 @@ import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.List;
 
+import static org.apache.maven.wagon.shared.http.HttpMessageUtils.formatResourceDoesNotExistMessage;
+
 /**
  * <p>WebDavWagon</p>
  * <p/>
@@ -299,10 +301,13 @@ public class WebDavWagon
                     return dirs;
                 }
 
-                if ( closeableHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND )
+                int statusCode = closeableHttpResponse.getStatusLine().getStatusCode();
+                String reasonPhrase = closeableHttpResponse.getStatusLine().getReasonPhrase();
+                if ( statusCode == HttpStatus.SC_NOT_FOUND || statusCode == HttpStatus.SC_GONE )
                 {
                     EntityUtils.consumeQuietly( closeableHttpResponse.getEntity() );
-                    throw new ResourceDoesNotExistException( "Destination directory does not exist: " + url );
+                    throw new ResourceDoesNotExistException( formatResourceDoesNotExistMessage( url, statusCode,
+                            reasonPhrase, getProxyInfo() ) );
                 }
             }
         }
@@ -337,6 +342,7 @@ public class WebDavWagon
                 }
             }
         }
+        // FIXME WAGON-580; actually the exception is wrong here; we need an IllegalStateException here
         throw new ResourceDoesNotExistException(
             "Destination path exists but is not a " + "WebDAV collection (directory): " + url );
     }