You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Harold Rosenberg <hr...@vmware.com> on 2012/08/07 19:52:40 UTC

Strange ClassCastException

I am using the AsyncClient (4.0-beta1) as part of an HTTP workload driver, along with HttpCore 4.2.1 and HttpClient 4.2.1.  My primary entry-point is through calls to execute(HttpUriRequest<eclipse-javadoc:%E2%98%82=rain-workload-toolkit/%5C/Users%5C/Hal%5C/.m2%5C/repository%5C/org%5C/apache%5C/httpcomponents%5C/httpasyncclient%5C/4.0-beta1%5C/httpasyncclient-4.0-beta1.jar%3Corg.apache.http.nio.client(HttpAsyncClient.class%E2%98%83HttpAsyncClient~execute~Lorg.apache.http.client.methods.HttpUriRequest;~Lorg.apache.http.protocol.HttpContext;~Lorg.apache.http.concurrent.FutureCallback%5C%3CLorg.apache.http.HttpResponse;%3E;%E2%98%82HttpUriRequest> request,HttpContext<eclipse-javadoc:%E2%98%82=rain-workload-toolkit/%5C/Users%5C/Hal%5C/.m2%5C/repository%5C/org%5C/apache%5C/httpcomponents%5C/httpasyncclient%5C/4.0-beta1%5C/httpasyncclient-4.0-beta1.jar%3Corg.apache.http.nio.client(HttpAsyncClient.class%E2%98%83HttpAsyncClient~execute~Lorg.apache.http.client.methods.HttpUriRequest;~Lorg.apache.http.protocol.HttpContext;~Lorg.apache.http.concurrent.FutureCallback%5C%3CLorg.apache.http.HttpResponse;%3E;%E2%98%82HttpContext> context, FutureCallback<eclipse-javadoc:%E2%98%82=rain-workload-toolkit/%5C/Users%5C/Hal%5C/.m2%5C/repository%5C/org%5C/apache%5C/httpcomponents%5C/httpasyncclient%5C/4.0-beta1%5C/httpasyncclient-4.0-beta1.jar%3Corg.apache.http.nio.client(HttpAsyncClient.class%E2%98%83HttpAsyncClient~execute~Lorg.apache.http.client.methods.HttpUriRequest;~Lorg.apache.http.protocol.HttpContext;~Lorg.apache.http.concurrent.FutureCallback%5C%3CLorg.apache.http.HttpResponse;%3E;%E2%98%82FutureCallback><HttpResponse<eclipse-javadoc:%E2%98%82=rain-workload-toolkit/%5C/Users%5C/Hal%5C/.m2%5C/repository%5C/org%5C/apache%5C/httpcomponents%5C/httpasyncclient%5C/4.0-beta1%5C/httpasyncclient-4.0-beta1.jar%3Corg.apache.http.nio.client(HttpAsyncClient.class%E2%98%83HttpAsyncClient~execute~Lorg.apache.http.client.methods.HttpUriRequest;~Lorg.apache.http.protocol.HttpContext;~Lorg.apache.http.concurrent.FutureCallback%5C%3CLorg.apache.http.HttpResponse;%3E;%E2%98%82HttpResponse>> callback) on a DefaultHttpAsyncClient.  I am sporadically getting the following exception:

12/08/06 08:31:21 ERROR protocol.HttpAsyncRequestExecutor: http-outgoing-143466 [ACTIVE] HTTP protocol exception: org.apache.http.impl.nio.conn.DefaultClientAsyncConnection cannot be cast to org.apache.http.conn.HttpRoutedConnection
java.lang.ClassCastException: org.apache.http.impl.nio.conn.DefaultClientAsyncConnection cannot be cast to org.apache.http.conn.HttpRoutedConnection
at org.apache.http.client.protocol.RequestAddCookies.process(RequestAddCookies.java:123)
at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:109)
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.requestReady(HttpAsyncRequestExecutor.java:157)
at org.apache.http.impl.nio.client.LoggingAsyncRequestExecutor.requestReady(LoggingAsyncRequestExecutor.java:89)
at org.apache.http.impl.nio.DefaultNHttpClientConnection.produceOutput(DefaultNHttpClientConnection.java:225)
at org.apache.http.impl.nio.DefaultHttpClientIODispatch.onOutputReady(DefaultHttpClientIODispatch.java:130)
at org.apache.http.impl.nio.DefaultHttpClientIODispatch.onOutputReady(DefaultHttpClientIODispatch.java:50)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.outputReady(AbstractIODispatch.java:141)
at org.apache.http.impl.nio.reactor.BaseIOReactor.writable(BaseIOReactor.java:181)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:346)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:320)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:280)
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:106)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:601)
at java.lang.Thread.run(Thread.java:662)

This shows up in my code as a call to failed(Exception) in my FutureCallback.

This only occurs very rarely (e.g. 7 such exceptions during a run with 1.4 million calls to execute), and I can handle the exception and retry the operation, but I find it very puzzling.  Using a debugger, I have looked at the state of the application on both successful and unsuccessful calls through this code path, and I can't see any difference.

Does anyone have any ideas about what might be causing this?  I have tried with both JDK 1.6.0_33 and 1.7.0_5 and get the same exception on both.

Thanks,

Hal



Re: Strange ClassCastException

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2012-08-07 at 10:52 -0700, Harold Rosenberg wrote:
> I am using the AsyncClient (4.0-beta1) as part of an HTTP workload driver, along with HttpCore 4.2.1 and HttpClient 4.2.1.  My primary entry-point is through calls to execute(HttpUriRequest<eclipse-javadoc:%E2%98%82=rain-workload-toolkit/%5C/Users%5C/Hal%5C/.m2%5C/repository%5C/org%5C/apache%5C/httpcomponents%5C/httpasyncclient%5C/4.0-beta1%5C/httpasyncclient-4.0-beta1.jar%3Corg.apache.http.nio.client(HttpAsyncClient.class%E2%98%83HttpAsyncClient~execute~Lorg.apache.http.client.methods.HttpUriRequest;~Lorg.apache.http.protocol.HttpContext;~Lorg.apache.http.concurrent.FutureCallback%5C%3CLorg.apache.http.HttpResponse;%3E;%E2%98%82HttpUriRequest> request,HttpContext<eclipse-javadoc:%E2%98%82=rain-workload-toolkit/%5C/Users%5C/Hal%5C/.m2%5C/repository%5C/org%5C/apache%5C/httpcomponents%5C/httpasyncclient%5C/4.0-beta1%5C/httpasyncclient-4.0-beta1.jar%3Corg.apache.http.nio.client(HttpAsyncClient.class%E2%98%83HttpAsyncClient~execute~Lorg.apache.http.client.methods.HttpUriRequest;~Lorg.apache.http.protocol.HttpContext;~Lorg.apache.http.concurrent.FutureCallback%5C%3CLorg.apache.http.HttpResponse;%3E;%E2%98%82HttpContext> context, FutureCallback<eclipse-javadoc:%E2%98%82=rain-workload-toolkit/%5C/Users%5C/Hal%5C/.m2%5C/repository%5C/org%5C/apache%5C/httpcomponents%5C/httpasyncclient%5C/4.0-beta1%5C/httpasyncclient-4.0-beta1.jar%3Corg.apache.http.nio.client(HttpAsyncClient.class%E2%98%83HttpAsyncClient~execute~Lorg.apache.http.client.methods.HttpUriRequest;~Lorg.apache.http.protocol.HttpContext;~Lorg.apache.http.concurrent.FutureCallback%5C%3CLorg.apache.http.HttpResponse;%3E;%E2%98%82FutureCallback><HttpResponse<eclipse-javadoc:%E2%98%82=rain-workload-toolkit/%5C/Users%5C/Hal%5C/.m2%5C/repository%5C/org%5C/apache%5C/httpcomponents%5C/httpasyncclient%5C/4.0-beta1%5C/httpasyncclient-4.0-beta1.jar%3Corg.apache.http.nio.client(HttpAsyncClient.class%E2%98%83HttpAsyncClient~execute~Lorg.apache.http.client.methods.HttpUriRequest;~Lorg.apache.http.protocol.HttpContext;~Lorg.apache.http.concurrent.FutureCallback%5C%3CLorg.apache.http.HttpResponse;%3E;%E2%98%82HttpResponse>> callback) on a DefaultHttpAsyncClient.  I am sporadically getting the following exception:
> 
> 12/08/06 08:31:21 ERROR protocol.HttpAsyncRequestExecutor: http-outgoing-143466 [ACTIVE] HTTP protocol exception: org.apache.http.impl.nio.conn.DefaultClientAsyncConnection cannot be cast to org.apache.http.conn.HttpRoutedConnection
> java.lang.ClassCastException: org.apache.http.impl.nio.conn.DefaultClientAsyncConnection cannot be cast to org.apache.http.conn.HttpRoutedConnection
> at org.apache.http.client.protocol.RequestAddCookies.process(RequestAddCookies.java:123)
> at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:109)
> at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.requestReady(HttpAsyncRequestExecutor.java:157)
> at org.apache.http.impl.nio.client.LoggingAsyncRequestExecutor.requestReady(LoggingAsyncRequestExecutor.java:89)
> at org.apache.http.impl.nio.DefaultNHttpClientConnection.produceOutput(DefaultNHttpClientConnection.java:225)
> at org.apache.http.impl.nio.DefaultHttpClientIODispatch.onOutputReady(DefaultHttpClientIODispatch.java:130)
> at org.apache.http.impl.nio.DefaultHttpClientIODispatch.onOutputReady(DefaultHttpClientIODispatch.java:50)
> at org.apache.http.impl.nio.reactor.AbstractIODispatch.outputReady(AbstractIODispatch.java:141)
> at org.apache.http.impl.nio.reactor.BaseIOReactor.writable(BaseIOReactor.java:181)
> at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:346)
> at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:320)
> at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:280)
> at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:106)
> at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:601)
> at java.lang.Thread.run(Thread.java:662)
> 
> This shows up in my code as a call to failed(Exception) in my FutureCallback.
> 
> This only occurs very rarely (e.g. 7 such exceptions during a run with 1.4 million calls to execute), and I can handle the exception and retry the operation, but I find it very puzzling.  Using a debugger, I have looked at the state of the application on both successful and unsuccessful calls through this code path, and I can't see any difference.
> 
> Does anyone have any ideas about what might be causing this?  I have tried with both JDK 1.6.0_33 and 1.7.0_5 and get the same exception on both.
> 
> Thanks,
> 
> Hal
> 

Hi Hal

This looks like a bug in HttpAsyncClient. Please raise a JIRA for this
defect. It is a shame this report did not come a little earlier. We just
released 4.0-beta2.

Oleg 



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org