Ken Krugler wrote:
> 
> On Mar 12, 2010, at 8:30am, Todor Boev wrote:
> 
>> Did that...works just fine. 10x
> 
> 10x what?

10x for pointing me to the low-level cookies stuff in HttpClient. I copied the
code that sets up a CookieSpecRegistry from there. Than I made my version of
RequestAddCookies that only use stuff from the blocking API. I reused the
original RequestProcessCookies. Than all I had to do to get cookies to work is
to place a CookieStore and a CookieSpecRegistry on the HttpContext as soon as a
non-blocking http connection opens. Hope that answers your question.

-- Todor
> 
> -- Ken
> 
>> On Thu, Mar 11, 2010 at 9:06 PM, Oleg Kalnichevski <[email protected]>
>> wrote:
>>
>>> 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
>>>
> 
> --------------------------------------------
> Ken Krugler
> +1 530-210-6378
> http://bixolabs.com
> e l a s t i c   w e b   m i n i n g
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
> 


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

Reply via email to