Todor Boev wrote:
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?

No, currently there is not


 Is there an async HTTP client library for example - couldn't find
one.

There is one, which is still in a very early stage of development

http://svn.apache.org/repos/asf/httpcomponents/asynchttpclient/trunk/


2) If I copy/paste RequestAddCookies and ResponseProcessCookies into my
classes and fix the trivial problems will I get a significatn performance
hit?


No, you will not. Just use low level cookie management code from HttpClient on top of HttpCore NIO and you will be just fine

Oleg

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

Reply via email to