[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-1727?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16877850#comment-16877850
 ] 

ChenKai commented on HTTPCLIENT-1727:
-------------------------------------

In our apache spark applications, we upload files to s3 using jets3t and 
httpclient-4.5.6, and get the errors.
{code:java}
Caused by: org.jets3t.service.ServiceException: Request Error: 
java.lang.ClassCastException: 
org.jets3t.service.utils.RestUtils.ConnManagerFactory cannot be cast to 
org.apache.http.conn.ClientConnectionManagerFactory
        at 
org.jets3t.service.impl.rest.httpclient.RestStorageService.performRequest(RestStorageService.java:574)
        at 
org.jets3t.service.impl.rest.httpclient.RestStorageService.performRequest(RestStorageService.java:281)
        at 
org.jets3t.service.impl.rest.httpclient.RestStorageService.performRestHead(RestStorageService.java:942)
        at 
org.jets3t.service.impl.rest.httpclient.RestStorageService.getObjectImpl(RestStorageService.java:2148)
        at 
org.jets3t.service.impl.rest.httpclient.RestStorageService.getObjectDetailsImpl(RestStorageService.java:2075)
        at 
org.jets3t.service.StorageService.getObjectDetails(StorageService.java:1093)
        at 
org.jets3t.service.StorageService.getObjectDetails(StorageService.java:548)
        at 
org.apache.hadoop.fs.s3native.Jets3tNativeFileSystemStore.retrieveMetadata(Jets3tNativeFileSystemStore.java:174)
        ... 79 more
Caused by: java.lang.ClassCastException: 
org.jets3t.service.utils.RestUtils.ConnManagerFactory cannot be cast to 
org.apache.http.conn.ClientConnectionManagerFactory
        at 
org.apache.http.impl.client.AbstractHttpClient.createClientConnectionManager(AbstractHttpClient.java:284)
        at 
org.apache.http.impl.client.AbstractHttpClient.getConnectionManager(AbstractHttpClient.java:437)
        at 
org.apache.http.impl.client.AbstractHttpClient.createHttpContext(AbstractHttpClient.java:246)
        at 
org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:771)
        at 
org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
        at 
org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
        at 
org.jets3t.service.impl.rest.httpclient.RestStorageService.performRequest(RestStorageService.java:334)
        ... 86 more
{code}

We return back to httpclient-4.5.2, and everything is fine. 
I notice that the this patch's contextLoader is 
`org.apache.spark.sql.hive.client.IsolatedClientLoader#classLoader` in spark, 
so i'm not sure if it's spark's problems. Thanks.

> org.apache.http.impl.client.AbstractHttpClient#createClientConnectionManager 
> Does not account for context class loader
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1727
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1727
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient (classic)
>    Affects Versions: 4.4.1, 4.5, 4.5.1, 4.5.2
>            Reporter: Charles R Allen
>            Priority: Major
>             Fix For: 4.5.3
>
>
> 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:
> {code}
> 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);
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to