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 2022/01/08 15:58:37 UTC

[maven-doxia] 01/01: [DOXIA-633] Drop and replace usage of HttpComponents in Core

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

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

commit 8bdca3bb60cb11176244995b540ef49d428e8967
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sat Jan 8 16:57:44 2022 +0100

    [DOXIA-633] Drop and replace usage of HttpComponents in Core
    
    This closes #84
---
 doxia-core/pom.xml                                 | 10 ----
 .../maven/doxia/parser/AbstractXmlParser.java      | 65 ++++------------------
 2 files changed, 10 insertions(+), 65 deletions(-)

diff --git a/doxia-core/pom.xml b/doxia-core/pom.xml
index bfe68b3..ef1686f 100644
--- a/doxia-core/pom.xml
+++ b/doxia-core/pom.xml
@@ -64,16 +64,6 @@ under the License.
       <artifactId>commons-text</artifactId>
       <version>1.3</version>
     </dependency>
-    <dependency>
-      <groupId>org.apache.httpcomponents</groupId>
-      <artifactId>httpclient</artifactId>
-      <version>4.5.13</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.httpcomponents</groupId>
-      <artifactId>httpcore</artifactId>
-      <version>4.4.14</version>
-    </dependency>
 
     <!-- test -->
     <dependency>
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 7a1b581..10fd1d5 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,13 +36,6 @@ import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.http.HttpStatus;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-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;
@@ -758,11 +751,6 @@ public abstract class AbstractXmlParser
         }
 
         /**
-         * If url is not an http/https urls, call {@link IOUtil#toByteArray(java.io.InputStream)} to get the url
-         * content.
-         * Otherwise, use HttpClient to get the http content.
-         * Wrap all internal exceptions to throw SAXException.
-         *
          * @param url not null
          * @return return an array of byte
          * @throws SAXException if any
@@ -770,56 +758,23 @@ public abstract class AbstractXmlParser
         private static byte[] toByteArray( URL url )
             throws SAXException
         {
-            if ( !( url.getProtocol().equalsIgnoreCase( "http" ) || url.getProtocol().equalsIgnoreCase( "https" ) ) )
-            {
-                InputStream is = null;
-                try
-                {
-                    is = url.openStream();
-                    if ( is == null )
-                    {
-                        throw new SAXException( "Cannot open stream from the url: " + url.toString() );
-                    }
-                    return IOUtil.toByteArray( is );
-                }
-                catch ( IOException e )
-                {
-                    throw new SAXException( "IOException: " + e.getMessage(), e );
-                }
-                finally
-                {
-                    IOUtil.close( is );
-                }
-            }
-
-            // it is an HTTP url, using HttpClient...
-            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() );
-
-            try ( CloseableHttpResponse response = httpClientBuilder.build().execute( new HttpGet( url.toString() ) ) )
+            InputStream is = null;
+            try
             {
-                int statusCode = response.getStatusLine().getStatusCode();
-                if ( statusCode != HttpStatus.SC_OK )
+                is = url.openStream();
+                if ( is == null )
                 {
-                    throw new IOException(
-                            "The status code when accessing the URL '" + url.toString() + "' was " + statusCode
-                                    + ", which is not allowed. The server gave this reason for the failure '"
-                                    + response.getStatusLine().getReasonPhrase() + "'." );
+                    throw new SAXException( "Cannot open stream from the url: " + url );
                 }
-
-                return EntityUtils.toByteArray( response.getEntity() );
+                return IOUtil.toByteArray( is );
             }
-            catch ( ClientProtocolException e )
+            catch ( IOException e )
             {
-                throw new SAXException( "ClientProtocolException: Fatal protocol violation: " + e.getMessage(), e );
+                throw new SAXException( "IOException: " + e.getMessage(), e );
             }
-            catch ( IOException e )
+            finally
             {
-                throw new SAXException( "IOException: Fatal transport error: " + e.getMessage(), e );
+                IOUtil.close( is );
             }
         }