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 Guy <gu...@gmail.com> on 2009/06/03 15:00:31 UTC
Retrieving the underlying Socket from HttpClient
Hi all,
I was wondering if there is a way to retrieve the Socket (and therefore the
SSLSession if using SSL) from a connection.
I noticed there is a protected getSocket() method in the HttpConnetion
class, but since this method is protected and not public it is no good for
me (or can I somehow make HttpClient use a custom HttpConnection object).
The reason I ask is I want to monitor X509 Certificates used on the server
side. I know it is much easier to do with a (custom- SSLSocketFactory and
use SSLSockets from the socketfactory, but I need the proxy functionality
build in HttpClient and it is not that easy to connect through a proxy that
uses authentication if you stick with sockets (or at least not easy for me
:-) )
any help would be appreciated.
kind regards
Guy
Re: NullPointerException in AsyncNHttpClientHandler
Posted by Oleg Kalnichevski <ol...@apache.org>.
Yongxing Wang wrote:
> Hi,
>
> We are using HTTP-NIO 4.0 to communicate with our internal http servers, on a very high volume bases (80Mbits/second on both upload and download). We use AsyncNHttpClientHandler and DefaultClientIOEventDispatch.
>
>
> We are seeing some strange behaviors randomly. After putting some debug messages and we finally identify the following exception that causes us great sorrow:
>
>
> java.lang.NullPointerException
> at
> org.apache.http.nio.protocol.AsyncNHttpClientHandler.outputReady(AsyncNHttpClientHandler.java:266)
> at
> org.apache.http.impl.nio.DefaultNHttpClientConnection.produceOutput(DefaultNHttpClientConnection.java:213)
> at
> org.apache.http.impl.nio.DefaultClientIOEventDispatch.outputReady(DefaultClientIOEventDispatch.java:152)
> at
> org.apache.http.impl.nio.reactor.BaseIOReactor.writable(BaseIOReactor.java:177)
> at
> org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:317)
> at
> org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:294)
> at
> org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:256)
> at
> org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:96)
> at
> org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:556)
> at
> java.lang.Thread.run(Thread.java:619)
>
> It happens randomly and happens with HTTP GET. Look at the line 266, it is:
>
> int statusCode = response.getStatusLine().getStatusCode();
>
> It seems that the "response" is returned prematurely.
>
I think the line that causes NPE is this one
http://hc.apache.org/httpcomponents-core/httpcore-nio/xref/org/apache/http/nio/protocol/AsyncNHttpClientHandler.html#266
What seems obviously wrong is that AsyncNHttpClientHandler#outputReady
event gets triggered for a GET request. This is not supposed to happen
at all as GET requests are not supposed to enclose a content body.
However, this _could_ be caused by a race condition if multiple threads
were to access the same connection object simultaneously. HTTP
connections objects are NOT thread-safe. It is _strongly_ recommended
HTTP connections should NEVER be accessed ouside the
AsyncNHttpClientHandler events.
Thread safety issue would be my primary guess here, especially given the
fact the problems seems to happen randomly.
>
> This NullPointerException will propagate all the way up to IOReactorExceptionHandler "handle(RuntimeException ex);", where you only have two options, ignore it or shutdown the whole IoReactor (neither of the two is good for us). I guess the root problem is that we should never see that NPE.
>
>
> Is there any more information I can provide to help address this problem?
>
Yes, a test case reproducing the problem or some contextual information
would be great.
One can add some rudimentary wire / context logging to HttpCore NIO
using these classes:
http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/
Hope this helps somewhat.
Oleg
> thanks,
> Yong
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
NullPointerException in AsyncNHttpClientHandler
Posted by Yongxing Wang <yo...@yahoo.com>.
Hi,
We are using HTTP-NIO 4.0 to communicate with our internal http servers, on a very high volume bases (80Mbits/second on both upload and download). We use AsyncNHttpClientHandler and DefaultClientIOEventDispatch.
We are seeing some strange behaviors randomly. After putting some debug messages and we finally identify the following exception that causes us great sorrow:
java.lang.NullPointerException
at
org.apache.http.nio.protocol.AsyncNHttpClientHandler.outputReady(AsyncNHttpClientHandler.java:266)
at
org.apache.http.impl.nio.DefaultNHttpClientConnection.produceOutput(DefaultNHttpClientConnection.java:213)
at
org.apache.http.impl.nio.DefaultClientIOEventDispatch.outputReady(DefaultClientIOEventDispatch.java:152)
at
org.apache.http.impl.nio.reactor.BaseIOReactor.writable(BaseIOReactor.java:177)
at
org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:317)
at
org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:294)
at
org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:256)
at
org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:96)
at
org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:556)
at
java.lang.Thread.run(Thread.java:619)
It happens randomly and happens with HTTP GET. Look at the line 266, it is:
int statusCode = response.getStatusLine().getStatusCode();
It seems that the "response" is returned prematurely.
This NullPointerException will propagate all the way up to IOReactorExceptionHandler "handle(RuntimeException ex);", where you only have two options, ignore it or shutdown the whole IoReactor (neither of the two is good for us). I guess the root problem is that we should never see that NPE.
Is there any more information I can provide to help address this problem?
thanks,
Yong
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Retrieving the underlying Socket from HttpClient
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, Jun 03, 2009 at 03:00:31PM +0200, Guy wrote:
> Hi all,
>
> I was wondering if there is a way to retrieve the Socket (and therefore the
> SSLSession if using SSL) from a connection.
>
> I noticed there is a protected getSocket() method in the HttpConnetion
> class, but since this method is protected and not public it is no good for
> me (or can I somehow make HttpClient use a custom HttpConnection object).
>
> The reason I ask is I want to monitor X509 Certificates used on the server
> side. I know it is much easier to do with a (custom- SSLSocketFactory and
> use SSLSockets from the socketfactory, but I need the proxy functionality
> build in HttpClient and it is not that easy to connect through a proxy that
> uses authentication if you stick with sockets (or at least not easy for me
> :-) )
>
> any help would be appreciated.
>
> kind regards
>
> Guy
You are out of luck with HttpClient 3.x. If you do not mind upgrading to
HttpClient 4.0 you could have a complete control over the process of socket
initialization by using a custom ClientConnectionOperator implementation.
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org