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 2019/10/30 22:43:40 UTC

[maven-wagon] 01/01: [WAGON-573] EntityUtils.consumeQuietly() never called on non-2xx status codes

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

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

commit 645787a67ee43a384ca6a1d69a58dbbec911a83a
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Wed Oct 30 23:43:24 2019 +0100

    [WAGON-573] EntityUtils.consumeQuietly() never called on non-2xx status codes
---
 .../maven/wagon/shared/http/AbstractHttpClientWagon.java       | 10 +++++++++-
 .../java/org/apache/maven/wagon/providers/http/HttpWagon.java  |  5 +++++
 .../org/apache/maven/wagon/providers/webdav/WebDavWagon.java   |  2 ++
 3 files changed, 16 insertions(+), 1 deletion(-)

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 3bf4291..dd1c690 100755
--- 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
@@ -798,25 +798,30 @@ public abstract class AbstractHttpClientWagon
                     case HttpStatus.SC_MOVED_PERMANENTLY: // 301
                     case HttpStatus.SC_MOVED_TEMPORARILY: // 302
                     case HttpStatus.SC_SEE_OTHER: // 303
+                        EntityUtils.consumeQuietly( response.getEntity() );
                         put( resource, source, httpEntity, calculateRelocatedUrl( response ) );
                         return;
                     //case HttpStatus.SC_UNAUTHORIZED:
                     case HttpStatus.SC_FORBIDDEN:
+                        EntityUtils.consumeQuietly( response.getEntity() );
                         fireSessionConnectionRefused();
                         throw new AuthorizationException( formatAuthorizationMessage( url,
                                 response.getStatusLine().getStatusCode(),
                                 response.getStatusLine().getReasonPhrase(), getProxyInfo() ) );
 
                     case HttpStatus.SC_NOT_FOUND:
+                        EntityUtils.consumeQuietly( response.getEntity() );
                         throw new ResourceDoesNotExistException( formatResourceDoesNotExistMessage( url,
                                 response.getStatusLine().getStatusCode(),
                                 response.getStatusLine().getReasonPhrase(), getProxyInfo() ) );
 
                     case SC_TOO_MANY_REQUESTS:
+                        EntityUtils.consumeQuietly( response.getEntity() );
                         put( backoff( wait, url ), resource, source, httpEntity, url );
                         break;
                     //add more entries here
                     default:
+                        EntityUtils.consumeQuietly( response.getEntity() );
                         TransferFailedException e = new TransferFailedException( formatTransferFailedMessage( url,
                                 response.getStatusLine().getStatusCode(),
                                 response.getStatusLine().getReasonPhrase(), getProxyInfo() ) );
@@ -905,7 +910,6 @@ public abstract class AbstractHttpClientWagon
                                 response.getStatusLine().getReasonPhrase(), getProxyInfo() ) );
                 }
 
-                EntityUtils.consume( response.getEntity() );
                 return result;
             }
             finally
@@ -1176,22 +1180,26 @@ public abstract class AbstractHttpClientWagon
                 case HttpStatus.SC_FORBIDDEN:
                 case HttpStatus.SC_UNAUTHORIZED:
                 case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
+                    EntityUtils.consumeQuietly( response.getEntity() );
                     fireSessionConnectionRefused();
                     throw new AuthorizationException( formatAuthorizationMessage( url,
                             response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase(),
                             getProxyInfo() ) );
 
                 case HttpStatus.SC_NOT_FOUND:
+                    EntityUtils.consumeQuietly( response.getEntity() );
                     throw new ResourceDoesNotExistException( formatResourceDoesNotExistMessage( url,
                             response.getStatusLine().getStatusCode(),
                             response.getStatusLine().getReasonPhrase(), getProxyInfo() ) );
 
                 case SC_TOO_MANY_REQUESTS:
+                    EntityUtils.consumeQuietly( response.getEntity() );
                     fillInputData( backoff( wait, url ), inputData );
                     break;
 
                 // add more entries here
                 default:
+                    EntityUtils.consumeQuietly( response.getEntity() );
                     cleanupGetTransfer( resource );
                     TransferFailedException e = new TransferFailedException( formatTransferFailedMessage( url,
                             response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase(),
diff --git a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
index 9d53729..532141c 100755
--- a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
+++ b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
@@ -24,6 +24,7 @@ import org.apache.http.HttpException;
 import org.apache.http.HttpStatus;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.util.EntityUtils;
 import org.apache.maven.wagon.ResourceDoesNotExistException;
 import org.apache.maven.wagon.TransferFailedException;
 import org.apache.maven.wagon.authorization.AuthorizationException;
@@ -82,18 +83,22 @@ public class HttpWagon
                     case HttpStatus.SC_FORBIDDEN:
                     case HttpStatus.SC_UNAUTHORIZED:
                     case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
+                        EntityUtils.consumeQuietly( response.getEntity() );
                         throw new AuthorizationException( HttpMessageUtils.formatAuthorizationMessage( url, statusCode,
                                 reasonPhrase, getProxyInfo() ) );
 
                     case HttpStatus.SC_NOT_FOUND:
+                        EntityUtils.consumeQuietly( response.getEntity() );
                         throw new ResourceDoesNotExistException( formatResourceDoesNotExistMessage( url, statusCode,
                                 reasonPhrase, getProxyInfo() ) );
 
                     case SC_TOO_MANY_REQUESTS:
+                        EntityUtils.consumeQuietly( response.getEntity() );
                         return getFileList( backoff( wait, url ), destinationDirectory );
 
                     //add more entries here
                     default:
+                        EntityUtils.consumeQuietly( response.getEntity() );
                         throw new TransferFailedException( formatTransferFailedMessage( url, statusCode, reasonPhrase,
                                 getProxyInfo() ) );
                 }
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 d991074..e7736b4 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
@@ -25,6 +25,7 @@ import org.apache.http.HttpStatus;
 import org.apache.http.auth.AuthScope;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.impl.auth.BasicScheme;
+import org.apache.http.util.EntityUtils;
 import org.apache.jackrabbit.webdav.DavConstants;
 import org.apache.jackrabbit.webdav.DavException;
 import org.apache.jackrabbit.webdav.MultiStatus;
@@ -300,6 +301,7 @@ public class WebDavWagon
 
                 if ( closeableHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND )
                 {
+                    EntityUtils.consumeQuietly( closeableHttpResponse.getEntity() );
                     throw new ResourceDoesNotExistException( "Destination directory does not exist: " + url );
                 }
             }