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 2021/06/03 09:28:35 UTC

[maven-doxia-linkcheck] 03/03: [DOXIATOOLS-68] update to HttpClient 4.5

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

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

commit b885954dff84cbc19d169f4e3282c154b0dcf670
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Sun Jan 17 11:06:13 2021 -0500

    [DOXIATOOLS-68] update to HttpClient 4.5
    
    Closes #6
---
 pom.xml                                            |  17 +-
 .../maven/doxia/linkcheck/DefaultLinkCheck.java    |  10 +-
 .../apache/maven/doxia/linkcheck/LinkCheck.java    |   8 +-
 .../validation/OnlineHTTPLinkValidator.java        | 354 +++++++++------------
 src/main/mdo/httpbean.mdo                          |   3 +-
 .../validation/HTTPLinkValidatorTest.java          |   4 +-
 6 files changed, 165 insertions(+), 231 deletions(-)

diff --git a/pom.xml b/pom.xml
index 55d4660..9c8fa5a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@ under the License.
     <groupId>org.apache.maven.doxia</groupId>
     <artifactId>doxia-tools</artifactId>
     <version>34</version>
-    <relativePath></relativePath>
+    <relativePath/>
   </parent>
 
   <artifactId>doxia-linkcheck</artifactId>
@@ -64,22 +64,15 @@ under the License.
   <dependencies>
     <!-- compile dependencies -->
     <dependency>
-      <groupId>commons-httpclient</groupId>
-      <artifactId>commons-httpclient</artifactId>
-      <version>3.1</version>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <version>4.5.13</version>
     </dependency>
     <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
       <version>1.2</version>
     </dependency>
-    <!-- Not included in Httpclient -->
-    <dependency>
-      <groupId>log4j</groupId>
-      <artifactId>log4j</artifactId>
-      <version>1.2.17</version>
-      <scope>runtime</scope>
-    </dependency>
 
     <!-- Plexus -->
     <dependency>
@@ -98,7 +91,7 @@ under the License.
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>3.8.2</version>
+      <version>4.13.2</version>
       <scope>test</scope>
     </dependency>
   </dependencies>
diff --git a/src/main/java/org/apache/maven/doxia/linkcheck/DefaultLinkCheck.java b/src/main/java/org/apache/maven/doxia/linkcheck/DefaultLinkCheck.java
index 39a12cd..d9b6713 100644
--- a/src/main/java/org/apache/maven/doxia/linkcheck/DefaultLinkCheck.java
+++ b/src/main/java/org/apache/maven/doxia/linkcheck/DefaultLinkCheck.java
@@ -84,23 +84,19 @@ public final class DefaultLinkCheck
     private String[] excludedPages = null;
 
     /**
-     * Excluded http errors only in on line mode.
-     *
-     * @see {@link HttpStatus} for all defined values.
+     * Excluded http errors only in online mode.
      */
     private int[] excludedHttpStatusErrors = null;
 
     /**
-     * Excluded http warnings only in on line mode.
-     *
-     * @see {@link HttpStatus} for all defined values.
+     * Excluded http warnings only in online mode.
      */
     private int[] excludedHttpStatusWarnings = null;
 
     /** Online mode. */
     private boolean online;
 
-    /** Bean enncapsuling some https parameters */
+    /** Bean enncapsulating some https parameters */
     private HttpBean http;
 
     /** Internal LinkValidatorManager. */
diff --git a/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java b/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java
index af0c4c6..a5ea0f1 100644
--- a/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java
+++ b/src/main/java/org/apache/maven/doxia/linkcheck/LinkCheck.java
@@ -48,16 +48,14 @@ public interface LinkCheck
     void setBaseURL( String url );
 
     /**
-     * Sets the excluded HTTP errors, i.e. <code>404</code>, a int[] with excluded errors.
-     * See {@link org.apache.commons.httpclient.HttpStatus} for all possible values.
+     * Sets the excluded HTTP errors; e.g. <code>404</code>, a int[] with excluded errors.
      *
      * @param excl The excludes to set
      */
     void setExcludedHttpStatusErrors( int[] excl );
 
     /**
-     * Sets the excluded HTTP warnings, i.e. <code>301</code>, a int[] with excluded errors.
-     * See {@link org.apache.commons.httpclient.HttpStatus} for all possible values.
+     * Sets the excluded HTTP warnings, e.g. <code>301</code>, a int[] with excluded errors.
      *
      * @param excl The excludes to set
      */
@@ -66,7 +64,7 @@ public interface LinkCheck
     /**
      * Sets the excluded links, a String[] with excluded locations.
      * Could contains a link, i.e. <code>http:&#47;&#47;maven.apache.org/</code>,
-     * or pattern links i.e. <code>http:&#47;&#47;maven.apache.org&#47;**&#47;*.html</code>
+     * or pattern links. E.g. <code>http:&#47;&#47;maven.apache.org&#47;**&#47;*.html</code>
      *
      * @param excl The excludes to set
      */
diff --git a/src/main/java/org/apache/maven/doxia/linkcheck/validation/OnlineHTTPLinkValidator.java b/src/main/java/org/apache/maven/doxia/linkcheck/validation/OnlineHTTPLinkValidator.java
index b9c4bfe..44aba60 100644
--- a/src/main/java/org/apache/maven/doxia/linkcheck/validation/OnlineHTTPLinkValidator.java
+++ b/src/main/java/org/apache/maven/doxia/linkcheck/validation/OnlineHTTPLinkValidator.java
@@ -24,32 +24,37 @@ import java.io.IOException;
 import java.net.URL;
 import java.util.Map;
 
-import org.apache.commons.httpclient.Credentials;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.HttpState;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
-import org.apache.commons.httpclient.NTCredentials;
-import org.apache.commons.httpclient.StatusLine;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.commons.httpclient.auth.AuthScope;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.HeadMethod;
-import org.apache.commons.httpclient.params.HttpClientParams;
-import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.http.Header;
+import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.StatusLine;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.NTCredentials;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpHead;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.config.SocketConfig;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.util.EntityUtils;
 import org.apache.maven.doxia.linkcheck.HttpBean;
 import org.apache.maven.doxia.linkcheck.model.LinkcheckFileResult;
 import org.codehaus.plexus.util.StringUtils;
 
 /**
- * Checks links which are normal URLs
+ * Checks links which are normal URLs.
  *
  * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
  * @author <a href="mailto:aheritier@apache.org">Arnaud Heritier</a>
@@ -64,13 +69,7 @@ public final class OnlineHTTPLinkValidator
     /** The maximum number of redirections for a link. */
     private static final int MAX_NB_REDIRECT = 10;
 
-    /** Use the get method to test pages. */
-    private static final String GET_METHOD = "get";
-
-    /** Use the head method to test pages. */
-    private static final String HEAD_METHOD = "head";
-
-    /** The http bean encapsuling all http parameters supported. */
+    /** The http bean encapsulating all http parameters supported. */
     private HttpBean http;
 
     /** The base URL for links that start with '/'. */
@@ -80,7 +79,7 @@ public final class OnlineHTTPLinkValidator
     private transient HttpClient cl;
 
     /**
-     * Constructor: initialize settings, use "head" method.
+     * Constructor: initialize settings, use HEAD method.
      */
     public OnlineHTTPLinkValidator()
     {
@@ -90,7 +89,7 @@ public final class OnlineHTTPLinkValidator
     /**
      * Constructor: initialize settings.
      *
-     * @param bean The http bean encapsuling all HTTP parameters supported.
+     * @param bean the http bean encapsulating all HTTP parameters supported
      */
     public OnlineHTTPLinkValidator( HttpBean bean )
     {
@@ -99,10 +98,7 @@ public final class OnlineHTTPLinkValidator
             bean = new HttpBean();
         }
 
-        if ( LOG.isDebugEnabled() )
-        {
-            LOG.debug( "Will use method : [" + bean.getMethod() + "]" );
-        }
+        LOG.debug( "Using method : [" + bean.getMethod() + "]" );
 
         this.http = bean;
 
@@ -112,7 +108,7 @@ public final class OnlineHTTPLinkValidator
     /**
      * The base URL.
      *
-     * @return the base URL.
+     * @return the base URL
      */
     public String getBaseURL()
     {
@@ -122,7 +118,7 @@ public final class OnlineHTTPLinkValidator
     /**
      * Sets the base URL. This is pre-pended to links that start with '/'.
      *
-     * @param url the base URL.
+     * @param url the base URL
      */
     public void setBaseURL( String url )
     {
@@ -149,11 +145,6 @@ public final class OnlineHTTPLinkValidator
             }
         }
 
-        // Some web servers don't allow the default user-agent sent by httpClient
-        System.setProperty( HttpMethodParams.USER_AGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" );
-        this.cl.getParams().setParameter( HttpMethodParams.USER_AGENT,
-                                          "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" );
-
         String link = lvi.getLink();
         String anchor = "";
         int idx = link.indexOf( '#' );
@@ -169,11 +160,8 @@ public final class OnlineHTTPLinkValidator
             {
                 if ( getBaseURL() == null )
                 {
-                    if ( LOG.isWarnEnabled() )
-                    {
-                        LOG.warn( "Cannot check link [" + link + "] in page [" + lvi.getSource()
+                    LOG.warn( "Cannot check link [" + link + "] in page [" + lvi.getSource()
                             + "], as no base URL has been set!" );
-                    }
 
                     return new LinkValidationResult( LinkcheckFileResult.WARNING_LEVEL, false,
                                                      "No base URL specified" );
@@ -182,34 +170,32 @@ public final class OnlineHTTPLinkValidator
                 link = getBaseURL() + link;
             }
 
-            HttpMethod hm = null;
+            HttpResponse response = null;
             try
             {
-                hm = checkLink( link, 0 );
+                response = checkLink( link, 0 );
             }
-            catch ( Throwable t )
+            catch ( IOException | HttpException ex )
             {
-                if ( LOG.isDebugEnabled() )
-                {
-                    LOG.debug( "Received: [" + t + "] for [" + link + "] in page [" + lvi.getSource() + "]", t );
-                }
+                LOG.debug( "Received: [" + ex + "] for [" + link + "] in page [" + lvi.getSource() + "]", ex );
 
-                return new LinkValidationResult( LinkcheckFileResult.ERROR_LEVEL, false, t.getClass().getName()
-                    + " : " + t.getMessage() );
+                return new LinkValidationResult( LinkcheckFileResult.ERROR_LEVEL, false, ex.getClass().getName()
+                    + " : " + ex.getMessage() );
             }
 
-            if ( hm == null )
+            if ( response == null )
             {
                 return new LinkValidationResult( LinkcheckFileResult.ERROR_LEVEL, false,
-                                                 "Cannot retreive HTTP Status" );
+                                                 "Cannot retrieve HTTP Status" );
             }
 
-            if ( hm.getStatusCode() == HttpStatus.SC_OK )
+            int statusCode = response.getStatusLine().getStatusCode();
+            if ( statusCode == HttpStatus.SC_OK )
             {
-                // lets check if the anchor is present
+                // check if the anchor is present
                 if ( anchor.length() > 0 )
                 {
-                    String content = hm.getResponseBodyAsString();
+                    String content = EntityUtils.toString( response.getEntity() );
 
                     if ( !Anchors.matchesAnchor( content, anchor ) )
                     {
@@ -217,46 +203,37 @@ public final class OnlineHTTPLinkValidator
                             "Missing anchor '" + anchor + "'" );
                     }
                 }
-                return new HTTPLinkValidationResult( LinkcheckFileResult.VALID_LEVEL, true, hm.getStatusCode(),
-                                                     hm.getStatusText() );
+                return new HTTPLinkValidationResult( LinkcheckFileResult.VALID_LEVEL, true,
+                        statusCode, response.getStatusLine().getReasonPhrase() );
             }
 
-            String msg =
-                "Received: [" + hm.getStatusCode() + "] for [" + link + "] in page [" + lvi.getSource() + "]";
-            // If there's a redirection ... add a warning
-            if ( hm.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY
-                || hm.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY
-                || hm.getStatusCode() == HttpStatus.SC_TEMPORARY_REDIRECT )
+            String msg = "Received: [" + statusCode + "] for [" + link + "] in page ["
+                    + lvi.getSource() + "]";
+            // If there's a redirection, add a warning
+            if ( statusCode == HttpStatus.SC_MOVED_PERMANENTLY
+                || statusCode == HttpStatus.SC_MOVED_TEMPORARILY
+                || statusCode == HttpStatus.SC_TEMPORARY_REDIRECT )
             {
                 LOG.warn( msg );
 
-                return new HTTPLinkValidationResult( LinkcheckFileResult.WARNING_LEVEL, true, hm.getStatusCode(),
-                                                     hm.getStatusText() );
+                return new HTTPLinkValidationResult( LinkcheckFileResult.WARNING_LEVEL, true, statusCode,
+                        response.getStatusLine().getReasonPhrase() );
             }
 
             LOG.debug( msg );
 
-            return new HTTPLinkValidationResult( LinkcheckFileResult.ERROR_LEVEL, false, hm.getStatusCode(),
-                                                 hm.getStatusText() );
+            return new HTTPLinkValidationResult( LinkcheckFileResult.ERROR_LEVEL, false, statusCode,
+                    response.getStatusLine().getReasonPhrase() );
         }
-        catch ( Throwable t )
+        catch ( IOException ex )
         {
-            String msg = "Received: [" + t + "] for [" + link + "] in page [" + lvi.getSource() + "]";
-            if ( LOG.isDebugEnabled() )
-            {
-                LOG.debug( msg, t );
-            }
-            else
-            {
-                LOG.error( msg );
-            }
+            String msg = "Received: [" + ex + "] for [" + link + "] in page [" + lvi.getSource() + "]";
+            LOG.error( msg, ex );
 
-            return new LinkValidationResult( LinkcheckFileResult.ERROR_LEVEL, false, t.getMessage() );
+            return new LinkValidationResult( LinkcheckFileResult.ERROR_LEVEL, false, ex.getMessage() );
         }
         finally
         {
-            System.getProperties().remove( HttpMethodParams.USER_AGENT );
-
             if ( this.http.getHttpClientParameters() != null )
             {
                 for ( Map.Entry<Object, Object> entry : this.http.getHttpClientParameters().entrySet() )
@@ -273,61 +250,62 @@ public final class OnlineHTTPLinkValidator
     /** Initialize the HttpClient. */
     private void initHttpClient()
     {
-        LOG.debug( "A new HttpClient instance is needed ..." );
+        LOG.debug( "Creating a new HttpClient instance." );
+
+        HttpClientBuilder builder = HttpClients.custom();
 
-        this.cl = new HttpClient( new MultiThreadedHttpConnectionManager() );
+        // connection manager
+        PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
+        connectionManager.setMaxTotal( 100 );
+        connectionManager.setDefaultMaxPerRoute( 10 );
+        builder.setConnectionManager( connectionManager );
 
-        // Default params
+        RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
+        // redirects
+        requestConfigBuilder.setRedirectsEnabled( this.http.isFollowRedirects() );
+
+        // timeouts
+        SocketConfig.Builder socketConfigBuilder = SocketConfig.custom();
         if ( this.http.getTimeout() != 0 )
         {
-            this.cl.getHttpConnectionManager().getParams().setConnectionTimeout( this.http.getTimeout() );
-            this.cl.getHttpConnectionManager().getParams().setSoTimeout( this.http.getTimeout() );
+            requestConfigBuilder.setConnectTimeout( this.http.getTimeout() );
+            requestConfigBuilder.setSocketTimeout( this.http.getTimeout() );
+            socketConfigBuilder.setSoTimeout( this.http.getTimeout() );
         }
-        this.cl.getParams().setBooleanParameter( HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true );
 
-        HostConfiguration hc = new HostConfiguration();
+        builder.setDefaultRequestConfig( requestConfigBuilder.build() );
+        builder.setDefaultSocketConfig( socketConfigBuilder.build() );
 
-        HttpState state = new HttpState();
-        if ( StringUtils.isNotEmpty( this.http.getProxyHost() ) )
+        // proxy
+        if ( StringUtils.isNotBlank( this.http.getProxyHost() ) )
         {
-            hc.setProxy( this.http.getProxyHost(), this.http.getProxyPort() );
-
-            if ( LOG.isDebugEnabled() )
-            {
-                LOG.debug( "Proxy Host:" + this.http.getProxyHost() );
-                LOG.debug( "Proxy Port:" + this.http.getProxyPort() );
-            }
+            HttpHost proxy = new HttpHost( this.http.getProxyHost(), this.http.getProxyPort() );
+            requestConfigBuilder.setProxy( proxy );
+            LOG.debug( "Proxy Host:" + this.http.getProxyHost() );
+            LOG.debug( "Proxy Port:" + this.http.getProxyPort() );
 
             if ( StringUtils.isNotEmpty( this.http.getProxyUser() ) && this.http.getProxyPassword() != null )
             {
-                if ( LOG.isDebugEnabled() )
-                {
-                    LOG.debug( "Proxy User:" + this.http.getProxyUser() );
-                }
+                LOG.debug( "Proxy User:" + this.http.getProxyUser() );
 
                 Credentials credentials;
                 if ( StringUtils.isNotEmpty( this.http.getProxyNtlmHost() ) )
                 {
-                    credentials =
-                        new NTCredentials( this.http.getProxyUser(), this.http.getProxyPassword(),
-                                           this.http.getProxyNtlmHost(), this.http.getProxyNtlmDomain() );
+                    credentials = new NTCredentials( this.http.getProxyUser(), this.http.getProxyPassword(),
+                            this.http.getProxyNtlmHost(), this.http.getProxyNtlmDomain() );
                 }
                 else
                 {
                     credentials =
                         new UsernamePasswordCredentials( this.http.getProxyUser(), this.http.getProxyPassword() );
                 }
-
-                state.setProxyCredentials( AuthScope.ANY, credentials );
+                CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+                credentialsProvider.setCredentials( AuthScope.ANY, credentials );
+                builder.setDefaultCredentialsProvider( credentialsProvider );
             }
         }
-        else
-        {
-            LOG.debug( "Not using a proxy" );
-        }
 
-        this.cl.setHostConfiguration( hc );
-        this.cl.setState( state );
+        this.cl = builder.build();
 
         LOG.debug( "New HttpClient instance created." );
     }
@@ -335,32 +313,28 @@ public final class OnlineHTTPLinkValidator
     /**
      * Checks the given link.
      *
-     * @param link the link to check.
-     * @param nbRedirect the number of current redirects.
-     * @return HttpMethod
-     * @throws IOException if something goes wrong.
+     * @param url the link to check
+     * @param nbRedirect the number of current redirects
+     * @throws IOException if something goes wrong
      */
-    private HttpMethod checkLink( String link, int nbRedirect )
-        throws IOException
+    private HttpResponse checkLink( String url, int nbRedirect )
+            throws IOException, HttpException
     {
+
+        // check if we've redirected too many times
         int max = MAX_NB_REDIRECT;
         if ( this.http.getHttpClientParameters() != null
-            && this.http.getHttpClientParameters().get( HttpClientParams.MAX_REDIRECTS ) != null )
+            && this.http.getHttpClientParameters().get( "http.protocol.max-redirects" ) != null )
         {
             try
             {
-                max =
-                    Integer.valueOf(
-                                     this.http.getHttpClientParameters().get( HttpClientParams.MAX_REDIRECTS )
-                                              .toString() ).intValue();
+                max = Integer.parseInt(
+                        this.http.getHttpClientParameters().get( "http.protocol.max-redirects" ).toString() );
             }
             catch ( NumberFormatException e )
             {
-                if ( LOG.isWarnEnabled() )
-                {
-                    LOG.warn( "HttpClient parameter '" + HttpClientParams.MAX_REDIRECTS
+                LOG.warn( "HttpClient parameter '" + "http.protocol.max-redirects"
                         + "' is not a number. Ignoring!" );
-                }
             }
         }
         if ( nbRedirect > max )
@@ -368,103 +342,79 @@ public final class OnlineHTTPLinkValidator
             throw new HttpException( "Maximum number of redirections (" + max + ") exceeded" );
         }
 
-        HttpMethod hm;
-        if ( HEAD_METHOD.equalsIgnoreCase( this.http.getMethod() ) )
-        {
-            hm = new HeadMethod( link );
-        }
-        else if ( GET_METHOD.equalsIgnoreCase( this.http.getMethod() ) )
-        {
-            hm = new GetMethod( link );
-        }
-        else
+        HttpUriRequest request;
+        try
         {
-            if ( LOG.isErrorEnabled() )
+            if ( "HEAD".equalsIgnoreCase( this.http.getMethod() ) )
+            {
+                request = new HttpHead( url );
+            }
+            else if ( "GET".equalsIgnoreCase( this.http.getMethod() ) )
+            {
+                request = new HttpGet( url );
+            }
+            else
             {
                 LOG.error( "Unsupported method: " + this.http.getMethod() + ", using 'get'." );
+                request = new HttpGet( url );
             }
-            hm = new GetMethod( link );
+        }
+        catch ( IllegalArgumentException ex )
+        {
+            throw new HttpException( "Invalid URL " + url, ex );
         }
 
-        // Default
-        hm.setFollowRedirects( this.http.isFollowRedirects() );
+        HttpResponse response = cl.execute( request );
 
-        try
+        StatusLine statusLine = response.getStatusLine();
+        if ( statusLine == null )
         {
-            URL url = new URL( link );
-
-            cl.getHostConfiguration().setHost( url.getHost(), url.getPort(), url.getProtocol() );
+            LOG.error( "Unknown error validating link : " + url );
+            return null;
+        }
 
-            cl.executeMethod( hm );
+        int statusCode = response.getStatusLine().getStatusCode();
+        if ( statusCode == HttpStatus.SC_MOVED_PERMANENTLY
+                || statusCode == HttpStatus.SC_MOVED_TEMPORARILY
+                || statusCode == HttpStatus.SC_TEMPORARY_REDIRECT )
+        {
+            Header[] locationHeader = response.getHeaders( "location" );
 
-            StatusLine sl = hm.getStatusLine();
-            if ( sl == null )
+            if ( locationHeader.length == 0 )
             {
-                if ( LOG.isErrorEnabled() )
-                {
-                    LOG.error( "Unknown error validating link : " + link );
-                }
-
-                return null;
+                LOG.error( "Site sent redirect, but did not set Location header" );
+                return response;
             }
 
-            if ( hm.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY
-                || hm.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY
-                || hm.getStatusCode() == HttpStatus.SC_TEMPORARY_REDIRECT )
-            {
-                Header locationHeader = hm.getResponseHeader( "location" );
-
-                if ( locationHeader == null )
-                {
-                    LOG.error( "Site sent redirect, but did not set Location header" );
-
-                    return hm;
-                }
-
-                String newLink = locationHeader.getValue();
+            String newLink = locationHeader[0].getValue();
 
-                // Be careful to absolute/relative links
-                if ( !newLink.startsWith( "http://" ) && !newLink.startsWith( "https://" ) )
+            // Be careful to absolute/relative links
+            if ( !newLink.startsWith( "http://" ) && !newLink.startsWith( "https://" ) )
+            {
+                if ( newLink.startsWith( "/" ) )
                 {
-                    if ( newLink.startsWith( "/" ) )
-                    {
-                        URL oldUrl = new URL( link );
-
-                        newLink =
-                            oldUrl.getProtocol() + "://" + oldUrl.getHost()
-                                + ( oldUrl.getPort() > 0 ? ":" + oldUrl.getPort() : "" ) + newLink;
-                    }
-                    else
-                    {
-                        newLink = link + newLink;
-                    }
+                    URL oldUrl = new URL( url );
+                    newLink = oldUrl.getProtocol() + "://" + oldUrl.getHost()
+                            + ( oldUrl.getPort() > 0 ? ":" + oldUrl.getPort() : "" ) + newLink;
                 }
-
-                HttpMethod oldHm = hm;
-
-                if ( LOG.isDebugEnabled() )
+                else
                 {
-                    LOG.debug( "[" + link + "] is redirected to [" + newLink + "]" );
+                    newLink = url + newLink;
                 }
+            }
 
-                oldHm.releaseConnection();
+            LOG.debug( "[" + url + "] is redirected to [" + newLink + "]" );
 
-                hm = checkLink( newLink, nbRedirect + 1 );
+            HttpResponse oldResponse = response;
+            response = checkLink( newLink, nbRedirect + 1 );
 
-                // Restore the hm to "Moved permanently" | "Moved temporarily" | "Temporary redirect"
-                // if the new location is found to allow us to report it
-                if ( hm.getStatusCode() == HttpStatus.SC_OK && nbRedirect == 0 )
-                {
-                    return oldHm;
-                }
+            // Restore the status to "Moved permanently" | "Moved temporarily" | "Temporary redirect"
+            // if the new location is found to allow us to report it
+            if ( statusCode == HttpStatus.SC_OK && nbRedirect == 0 )
+            {
+                return oldResponse;
             }
-
         }
-        finally
-        {
-            hm.releaseConnection();
-        }
-
-        return hm;
+        return response;
     }
 }
diff --git a/src/main/mdo/httpbean.mdo b/src/main/mdo/httpbean.mdo
index dc9fcb0..934bb5d 100644
--- a/src/main/mdo/httpbean.mdo
+++ b/src/main/mdo/httpbean.mdo
@@ -32,8 +32,7 @@ under the License.
   <classes>
     <class>
       <name>HttpBean</name>
-      <description>Http bean to encapsulate the supported HTTP parameters.
-         @see org.apache.commons.httpclient.HttpMethod</description>
+      <description>Http bean to encapsulate the supported HTTP parameters.</description>
       <version>1.0.0</version>
       <fields>
         <field>
diff --git a/src/test/java/org/apache/maven/doxia/linkcheck/validation/HTTPLinkValidatorTest.java b/src/test/java/org/apache/maven/doxia/linkcheck/validation/HTTPLinkValidatorTest.java
index 0d6f67f..e7447c7 100644
--- a/src/test/java/org/apache/maven/doxia/linkcheck/validation/HTTPLinkValidatorTest.java
+++ b/src/test/java/org/apache/maven/doxia/linkcheck/validation/HTTPLinkValidatorTest.java
@@ -53,9 +53,7 @@ public class HTTPLinkValidatorTest extends TestCase
 
             this.hlv = new OnlineHTTPLinkValidator();
 
-            // http://www.apache.org is being redirected to https://www.apache.org
-            assertEquals( LinkcheckFileResult.WARNING_LEVEL, checkLink( "http://www.apache.org" ).getStatus() );
-            assertEquals( LinkcheckFileResult.VALID_LEVEL, checkLink( "https://www.apache.org" ).getStatus() );
+            assertEquals( LinkcheckFileResult.VALID_LEVEL, checkLink( "http://www.apache.org" ).getStatus() );
             assertEquals( LinkcheckFileResult.ERROR_LEVEL, checkLink( "http://www.example.com>);" ).getStatus() );
         }
         else