hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Francois-Xavier Bonnet (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 Tue, 04 Dec 2012 13:02:58 GMT

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

Francois-Xavier Bonnet commented on HTTPCLIENT-1267:
----------------------------------------------------

I just made a test where I replaced in method org.apache.manifoldcf.crawler.connectors.webcrawler.CookieManager.updateCookies(String,
LoginCookies) the following line:
   map.put(discardField,booleanToString(!c.isPersistent()));
by
   map.put(discardField,booleanToString(false));

And now the cookie is sent correctly:

DEBUG 2012-12-04 13:59:38,689 (Worker thread '0') - WEB: Adding 1 cookies for '/web/loginpage.html'
DEBUG 2012-12-04 13:59:38,689 (Worker thread '0') - WEB:  Cookie '[version: 0][name: JSESSIONID][value:
1fn14sizhjvg47bp9359v4ky2][domain: localhost][path: /web][expiry: null]' added
DEBUG 2012-12-04 13:59:38,690 (Thread-375) - >> GET /web/loginpage.html?user=foo&password=bar
HTTP/1.1
DEBUG 2012-12-04 13:59:38,690 (Thread-375) - >> User-Agent: Mozilla/5.0 (ApacheManifoldCFWebCrawler;
someone@somewhere.com)
DEBUG 2012-12-04 13:59:38,690 (Thread-375) - >> From: someone@somewhere.com
DEBUG 2012-12-04 13:59:38,690 (Thread-375) - >> Host: localhost:8191
DEBUG 2012-12-04 13:59:38,690 (Thread-375) - >> Connection: Keep-Alive
DEBUG 2012-12-04 13:59:38,690 (Thread-375) - >> Cookie: JSESSIONID=1fn14sizhjvg47bp9359v4ky2
DEBUG 2012-12-04 13:59:38,695 (Thread-375) - << HTTP/1.1 302 Found
DEBUG 2012-12-04 13:59:38,695 (Thread-375) - << Location: http://localhost:8191/web/index.html
DEBUG 2012-12-04 13:59:38,695 (Thread-375) - << Content-Length: 0
DEBUG 2012-12-04 13:59:38,695 (Thread-375) - << Server: Jetty(7.5.4.v20111024)
DEBUG 2012-12-04 13:59:38,695 (Worker thread '0') - WEB: Retrieving cookies...
DEBUG 2012-12-04 13:59:38,698 (Worker thread '0') - WEB:   Cookie '[version: 0][name: JSESSIONID][value:
1fn14sizhjvg47bp9359v4ky2][domain: localhost][path: /web][expiry: null]'
 INFO 2012-12-04 13:59:38,701 (Worker thread '0') - WEB: FETCH LOGIN|http://localhost:8191/web/loginpage.html|1354625978688+12|302|0|
DEBUG 2012-12-04 13:59:38,702 (Worker thread '0') - WEB: Tried to match raw url 'http://localhost:8191/web/index.html'
DEBUG 2012-12-04 13:59:38,702 (Worker thread '0') - WEB: Tried to match cooked url 'http://localhost:8191/web/index.html'
DEBUG 2012-12-04 13:59:38,702 (Worker thread '0') - WEB: Redirection link lookup matched 'http://localhost:8191/web/index.html'
DEBUG 2012-12-04 13:59:38,702 (Worker thread '0') - WEB: Document 'http://localhost:8191/web/loginpage.html'
matches preferred redirection, so determined to be login page for sequence '/web/'
DEBUG 2012-12-04 13:59:38,704 (Worker thread '0') - WEB: Waiting to start getting a connection
to http://127.0.0.1:8191
DEBUG 2012-12-04 13:59:38,704 (Worker thread '0') - WEB: Attempting to get connection to http://127.0.0.1:8191
(0 ms)
DEBUG 2012-12-04 13:59:38,704 (Worker thread '0') - WEB: Successfully got connection to http://127.0.0.1:8191
(0 ms)
DEBUG 2012-12-04 13:59:38,704 (Worker thread '0') - WEB: Waiting for an HttpClient object


                
> 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