Hi,
I am working on an asynchronous HTTP client using the httpcore-nio library.
I need to do session management with cookies. I tried to do it like this:
// Make a request/response handler hooked to the executor
BasicHttpProcessor httpproc = new BasicHttpProcessor();
httpproc.addInterceptor(new RequestContent());
httpproc.addInterceptor(new RequestTargetHost());
httpproc.addInterceptor(new RequestConnControl());
httpproc.addInterceptor(new RequestUserAgent());
httpproc.addInterceptor(new RequestExpectContinue());
httpproc.addInterceptor(new RequestAddCookies()); // ADD COOKIES TO
REQUEST
httpproc.addInterceptor(new ResponseProcessCookies()); // PROCESS
COOKIES FROM RESPONSE
NHttpRequestExecutionHandler execHandler = new
NHttpRequestExecutionHandler(endpointUri, _cookies);
ThrottlingHttpClientHandler handler = new ThrottlingHttpClientHandler(
httpproc, //HOOK PROCESSOR TO HANDLER
execHandler,
new DefaultConnectionReuseStrategy(),
executor,
params);
To my distaste I discovered that ReequestAddCookies and
ResponseProcessCookies are coded agsinst the blocking HTTP API and
RequestAddCookies crashes with a ClassCastExceptions when it tries retrieve
a ManagedClientConnection from the HttpContext (and we have an
NHttpClientConnection there instead). The connection seems to be needed for
some trivial stuff: the remote port, and a http/https test.
My questions are:
1) Is there a ready-made way to do cookies with the asynchronous HTTP
client? Is there an async HTTP client library for example - couldn't find
one.
2) If I copy/paste RequestAddCookies and ResponseProcessCookies into my
classes and fix the trivial problems will I get a significatn performance
hit?
Cheers,
Todor
--
Go on! Destroy the fabric of the universe! See if I care!