You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2019/05/07 11:33:48 UTC

[maven-doxia] 01/01: [DOXIA-576] Upgrade httpcomponents httpclient 4.5.8, httpcore 4.4.11

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

slachiewicz pushed a commit to branch DOXIA-576
in repository https://gitbox.apache.org/repos/asf/maven-doxia.git

commit 2a0566c0e6dd4fa35fc601acbcaa98cda081f797
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Tue May 7 13:24:54 2019 +0200

    [DOXIA-576] Upgrade httpcomponents httpclient 4.5.8, httpcore 4.4.11
---
 doxia-core/pom.xml                                 |  4 +--
 .../maven/doxia/parser/AbstractXmlParser.java      | 34 +++++++++-------------
 2 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/doxia-core/pom.xml b/doxia-core/pom.xml
index 867c20c..6f675a6 100644
--- a/doxia-core/pom.xml
+++ b/doxia-core/pom.xml
@@ -62,12 +62,12 @@ under the License.
     <dependency>
       <groupId>org.apache.httpcomponents</groupId>
       <artifactId>httpclient</artifactId>
-      <version>4.0.2</version>
+      <version>4.5.8</version>
     </dependency>
     <dependency>
       <groupId>org.apache.httpcomponents</groupId>
       <artifactId>httpcore</artifactId>
-      <version>4.0.1</version>
+      <version>4.4.11</version>
     </dependency>
 
     <!-- test -->
diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java b/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java
index dbeed05..1ac62fb 100644
--- a/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java
+++ b/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java
@@ -36,16 +36,13 @@ import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.HttpRequestRetryHandler;
+import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
+import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.util.EntityUtils;
-
 import org.apache.maven.doxia.macro.MacroExecutionException;
 import org.apache.maven.doxia.markup.XmlMarkup;
 import org.apache.maven.doxia.sink.Sink;
@@ -811,19 +808,17 @@ public abstract class AbstractXmlParser
             }
 
             // it is an HTTP url, using HttpClient...
-            DefaultHttpClient client = new DefaultHttpClient();
-            HttpGet method = new HttpGet( url.toString() );
-            // Set a user-agent that doesn't contain the word "java", otherwise it will be blocked by the W3C
-            // The default user-agent is "Apache-HttpClient/4.0.2 (java 1.5)"
-            method.setHeader( "user-agent", "Apache-Doxia/" + doxiaVersion() );
-
-            HttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler( 3, false );
-            client.setHttpRequestRetryHandler( retryHandler );
-
-            HttpEntity entity = null;
+            HttpClientBuilder httpClientBuilder = HttpClientBuilder.create()
+                    .useSystemProperties()
+                    .setRetryHandler( new DefaultHttpRequestRetryHandler( 3, false ) )
+                    // Set a user-agent that doesn't contain the word "java", otherwise it will be blocked by the W3C
+                    // The default user-agent is "Apache-HttpClient/4.5.8 (java 7)"
+                    .setUserAgent( "Apache-Doxia/" + doxiaVersion() );
+
+            CloseableHttpResponse response = null;
             try
             {
-                HttpResponse response = client.execute( method );
+                response = httpClientBuilder.build( ).execute( new HttpGet( url.toString( ) ) );
                 int statusCode = response.getStatusLine().getStatusCode();
                 if ( statusCode != HttpStatus.SC_OK )
                 {
@@ -832,8 +827,7 @@ public abstract class AbstractXmlParser
                         + response.getStatusLine().getReasonPhrase() + "'." );
                 }
 
-                entity = response.getEntity();
-                return EntityUtils.toByteArray( entity );
+                return EntityUtils.toByteArray( response.getEntity() );
             }
             catch ( ClientProtocolException e )
             {
@@ -845,11 +839,11 @@ public abstract class AbstractXmlParser
             }
             finally
             {
-                if ( entity != null )
+                if ( response != null )
                 {
                     try
                     {
-                        entity.consumeContent();
+                        response.close();
                     }
                     catch ( IOException e )
                     {