hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Karl Wright (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HTTPCLIENT-1267) There seems to be no way to get HttpClient to include cookies from a custom store
Date Mon, 03 Dec 2012 22:39:58 GMT

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1267?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13509274#comment-13509274
] 

Karl Wright commented on HTTPCLIENT-1267:
-----------------------------------------

I built both httpcore.jar and httpclient.jar from their respective trunk areas, and put them
into place in ManifoldCF.  Now I'm getting the following exception, with the same code that
runs without outputting any cookies:

>>>>>>
java.lang.ClassCastException
        at java.lang.Class.cast(Class.java:2990)
        at org.apache.http.protocol.HttpCoreContext.getAttribute(HttpCoreContext.java:89)
        at org.apache.http.client.protocol.HttpClientContext.getLookup(HttpClientContext.java:99)
        at org.apache.http.client.protocol.HttpClientContext.getCookieSpecRegistry(HttpClientContext.java:103)
        at org.apache.http.client.protocol.RequestAddCookies.process(RequestAddCookies.java:98)
        at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:131)
        at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:166)
        at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:515)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:857)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:70)
        at org.apache.manifoldcf.crawler.connectors.webcrawler.ThrottledFetcher$ExecuteMethodThread.run(ThrottledFetcher.java:2436)
<<<<<<

It seems like it is clearly looking for the cookie policy and finding something it doesn't
like.  Hard to see how I could have caused this either, since my code only sets the cookie
store in the context:

>>>>>>
                HttpContext context = new BasicHttpContext();
                context.setAttribute(ClientContext.COOKIE_STORE,cookieStore);

                response = httpClient.execute(executeMethod, context);
<<<<<<

There are too many changes between 4.2.2 and trunk for me to get sensible results; I think
I'm going to work off the 4.2.x branch in hopes of getting something more stable.

                
> There seems to be no way to get HttpClient to include cookies from a custom store
> ---------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1267
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1267
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpCookie
>    Affects Versions: 4.2.2
>            Reporter: Karl Wright
>
> In the port of ManifoldCF from commons-httpclient to httpcomponents, we discovered a
problem or maybe a design flaw with how cookies are handled.
> What we're trying to do is to follow a certain series of html pages, and record the cookies
after that is done, and use exactly those cookies for a subsequent series of pages.  So I
have code that looks something like this:
> {code}
> DefaultHttpClient httpClient = new DefaultHttpClient();
> ...
> CookieStore cs = new BasicCookieStore();
> cs.addCookie(...);  // for each saved cookie
> httpClient.setCookieStore(cs);
> HttpGet httpget = new HttpGet(...);
> HttpResponse response = httpClient.execute(httpget);
> Cookie[] cookiesToSave = httpClient.getCookieStore().getCookies();
> [save the cookies aside]
> {code}
> What happens when I do this against a page that sets a cookie, is I get a perfectly reasonable
cookie, and save it.  For the next page, the code to add the cookie to the custom store then
seems to work fine as well.  But when I watch what is transmitted for the request (via header
logging) I see no Cookie header being sent, and indeed the cookie seems to be lost.
> Similar logic was done with HttpState in commons-httpclient, and worked perfectly there
against the same website.
> I have not yet tried the HttpContext approach for implementing this - I may try that
while awaiting an answer to this ticket, but the above seems like it ought to work, according
to the documentation.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

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


Mime
View raw message