Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-1727

org.apache.http.impl.client.AbstractHttpClient#createClientConnectionManager Does not account for context class loader

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.4.1, 4.5, 4.5.1, 4.5.2
    • 4.5.3
    • HttpClient (classic)
    • None
    • Patch

    Description

      org.apache.http.impl.client.AbstractHttpClient#createClientConnectionManager Does not account for context class loader.

      This means that only ClientConnectionManager factories visible in AbstractHttpClient's classloader are loadable by AbstractHttpClient

      An example of a failure here is if httpclient and jets3t are loaded in different classloaders, where jets3t is in a child classloader of httpclient's classloader. In such a case httpclient classes will be visible to jets3t, but jets3t's classes will not be visible to httpclient so org.jets3t.service.utils.RestUtils$ConnManagerFactory will not be found.

      The proposed fix against the 4.5.x branch is as follows:

      diff --git a/httpclient/src/main/java-deprecated/org/apache/http/impl/client/AbstractHttpClient.java b/httpclient/src/main/java-deprecated/org/apache/http/impl/client/AbstractHttpClient.java
      index 18a42d7..34c6e0f 100644
      --- a/httpclient/src/main/java-deprecated/org/apache/http/impl/client/AbstractHttpClient.java
      +++ b/httpclient/src/main/java-deprecated/org/apache/http/impl/client/AbstractHttpClient.java
      @@ -327,9 +327,15 @@ public abstract class AbstractHttpClient extends CloseableHttpClient {
      
               final String className = (String) params.getParameter(
                       ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME);
      +        final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
               if (className != null) {
                   try {
      -                final Class<?> clazz = Class.forName(className);
      +                final Class<?> clazz;
      +                if(contextLoader != null) {
      +                    clazz = Class.forName(className, true, contextLoader);
      +                } else {
      +                    clazz = Class.forName(className);
      +                }
                       factory = (ClientConnectionManagerFactory) clazz.newInstance();
                   } catch (final ClassNotFoundException ex) {
                       throw new IllegalStateException("Invalid class name: " + className);
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            drcrallen Charles R Allen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment