hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Session handling in HttpClient
Date Sun, 23 Nov 2008 13:48:45 GMT
Al Byers wrote:
> In working with this problem I am seeing a difference in what the
> BasicCookieStore stores and what is in the headers. Here is my code:
> 
>             BasicHttpContext localContext = new BasicHttpContext();
>             // Create a local instance of cookie store
>             CookieStore cookieStore = new BasicCookieStore();
>             localContext.setAttribute(ClientContext.COOKIE_STORE,
> cookieStore);
>             //this.login(client, localContext);
>             String paramString2 = "USERNAME=" + this.parent.getUserName()
>                                + "&PASSWORD=" + this.parent.getPassword();
>             String thisUri2 = this.host + "/eng/control/login?" +
> paramString2;
>             HttpGet req2 = new HttpGet ( thisUri2 );
>             req2.setHeader("Connection","Keep-Alive");
>             HttpResponse rsp = client.execute(req2, localContext);
> 
>             Header[] headers = rsp.getAllHeaders();
>             for (int i=0; i<headers.length; i++) {
>                 System.out.println(headers[i]);
>             }
> The above code prints out:
> Server: Apache-Coyote/1.1
> Set-Cookie: JSESSIONID=073AF3D9B37540588F86BAF974B4BFB6.jvm1; Path=/eng
> Set-Cookie: OFBiz.Visitor=10224; Expires=Sat, 21-Nov-2009 07:54:27 GMT;
> Path=/
> Set-Cookie: eng.autoUserLoginId=admin; Domain=""; Expires=Sat, 21-Nov-2009
> 07:54:27 GMT; Path=/
> Content-Type: text/html;charset=UTF-8
> Transfer-Encoding: chunked
> Date: Fri, 21 Nov 2008 07:54:27 GMT
> 
> 
>             List<Cookie> cookies = cookieStore.getCookies();
>             System.out.println("cookies.size(): " + cookies.size());
>             for (int i = 0; i < cookies.size(); i++) {
>                 System.out.println("Local cookie(0): " + cookies.get(i));
>             }
> The above code prints:
> cookies.size(): 1
> Local cookie(0): [version: 0][name: OFBiz.Visitor][value: 10224][domain:
> localhost][path: /][expiry: Sat Nov 21 00:54:27 MST 2009]
> 
> How can I have 3 'Set-Cookie' headers but cookieStore only shows 1?
>

Apparently 2 cookies got rejected as invalid. Please examine the log to 
see if there have been any warnings about rejected cookies.

Anyways you can get detailed info about HTTP session and the exact 
content of HTTP packets transferred across the wire by setting 
'org.apache.http' logging category to DEBUG priority.

Hope this helps

Oleg



> Thanks,
> -Al
> 


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


Mime
View raw message