hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mohit Anchlia <mohitanch...@gmail.com>
Subject Cookies
Date Thu, 11 Aug 2011 00:47:34 GMT
I am setting 2 Cookies in CookieStore using HttpContext. But only one
cookie seems to be going on Http. Can someone please help me as to why
that would be the case?

output shows:

17:30:21,879 INFO  [STDOUT] INFO  ApacheCookieUtils - Domain null
nameqbn.ptc.authId value212163844 pathnull version1
17:30:21,879 INFO  [STDOUT] INFO  ApacheCookieUtils - Domain null
nameqbn.ptc.ticket valueV1-4-KLR_cmMlPijWrrDDINX4kQ pathnull version1


But I only see the first one going out. This util is reasing from
Servlet Cookie Object.

-----
	private HttpContext getHttpClientCookie() {
		CookieStore cookieStore = new BasicCookieStore();
		HttpContext httpContext = new BasicHttpContext();
		if (null != request.getServletCookie()){
			for (Cookie c : request.getServletCookie()){
				   cookieStore.addCookie(ApacheCookieUtils.apacheCookieFromServletCookie(c));
				}
		}
		httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
		return httpContext;
	}

 public static org.apache.http.cookie.Cookie
apacheCookieFromServletCookie(Cookie cookie) {
  if(cookie == null) {
   return null;
  }

     BasicClientCookie apacheCookie = null;

  // get all the relevant parameters
     String domain = cookie.getDomain();
     String name = cookie.getName();
     String value = cookie.getValue();
     String path = cookie.getPath();
     int maxAge = cookie.getMaxAge();
     boolean secure = cookie.getSecure();

     log.info("Domain " + domain + " name" + name + " value" + value +
" path" + path + " version" + cookie.getVersion());

     // create the apache cookie
     apacheCookie = new BasicClientCookie(name, value);

     apacheCookie.setDomain(domain);
     apacheCookie.setPath(path);
     apacheCookie.setSecure(secure);


     // set additional parameters
     apacheCookie.setComment(cookie.getComment());
     apacheCookie.setVersion(cookie.getVersion());

     // return the apache cookie
     return apacheCookie;
 }

--

---------------------------------------------------------------------
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