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/04 09:59:58 UTC

[maven-doxia] 02/02: [DOXIA-576] Move to non-deprecated methods (as of 4.3)

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 3ae7294b2cd2e0af3359eeabeef95759220eff4e
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Thu May 2 14:37:03 2019 +0200

    [DOXIA-576] Move to non-deprecated methods (as of 4.3)
---
 .../maven/doxia/parser/AbstractXmlParser.java      | 34 +++++++++-------------
 1 file changed, 14 insertions(+), 20 deletions(-)

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 ec25f19..0480d47 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;
@@ -816,19 +813,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 )
                 {
@@ -837,8 +832,7 @@ public abstract class AbstractXmlParser
                         + response.getStatusLine().getReasonPhrase() + "'." );
                 }
 
-                entity = response.getEntity();
-                return EntityUtils.toByteArray( entity );
+                return EntityUtils.toByteArray( response.getEntity() );
             }
             catch ( ClientProtocolException e )
             {
@@ -850,11 +844,11 @@ public abstract class AbstractXmlParser
             }
             finally
             {
-                if ( entity != null )
+                if ( response != null )
                 {
                     try
                     {
-                        entity.consumeContent();
+                        response.close();
                     }
                     catch ( IOException e )
                     {