Hello,

Here the attach with the trace. It's a post request from my local app to my
servlet.

In all tests I've always used:
bcc.setVersion(1);
bcc.setAttribute(ClientCookie.VERSION_ATTR, "1");


Thanks,

Joan.

-----Mensaje original-----
De: Oleg Kalnichevski [mailto:ol...@apache.org] 
Enviado el: martes, 07 de julio de 2009 17:18
Para: HttpClient User Discussion
Asunto: Re: QUESTION ABOUT COOKIES

On Tue, Jul 07, 2009 at 05:04:59PM +0200, Joan Balaguer? Valls wrote:
> Hello Oleg,
> 
> Thanks, after some tests this is exactly what it happens.
> 
> When I send this cookie to my servlet, I receive all its data correctly
> except the "max-age" attribute, which is always -1.
> 
> I'm trying to set MAX_AGE with your API, and I'm getting crazy...
> 
> I've tried "stdCookie.setExpiryDate(new
> java.util.Date(System.currentTimeMillis() + 60000));  // Expires after 60
> seconds
> 
> But my servlet gets -1 (when I get cookies from HttpServletRequest with
> request.getCookies()).
> 
> I supposed that I had to set the same value for MAX_AGE attribute. Then I
> tried:
> 
> stdCookie.setExpiryDate(new java.util.Date(System.currentTimeMillis() +
> 60000));
> stdCookie.setAttribute(ClientCookie.MAX_AGE_ATTR, "60");  // 60 seconds
> 
> But my servlet still receives -1 in MAX_AGE.
> 
> Finally, I'm trying to set the "ClientCookie.EXPIRES_ATTR" with the value
of
> java.util.Date(System.currentTimeMillis() + 60000)), but the value passed
to
> setAttribute is expected to be a String, and I have a java.util.Date. How
> can I make this conversion?
> 
> Thanks in advance,
> 

Post a wire log of the session:

http://hc.apache.org/httpcomponents-client/logging.html

Also, try setting cookie version to version 1 to force the use of a RFC
compliant cookie spec and see if that makes any difference.

Oleg

> Joan. 
> 
> 
> 
> 
> -----Mensaje original-----
> De: Oleg Kalnichevski [mailto:ol...@apache.org] 
> Enviado el: martes, 07 de julio de 2009 16:18
> Para: HttpClient User Discussion
> Asunto: Re: QUESTION ABOUT COOKIES
> 
> On Mon, Jul 06, 2009 at 08:14:48PM +0200, Joan Balaguer? Valls wrote:
> > Hello Oleg,
> > 
> >  
> > 
> > I?m trying to send cookies to a servlet with a simple app. Following the
> > tutorial:
> > 
> >  
> > 
> > HttpContext localContext = new BasicHttpContext();
> > 
> > CookieStore cookieStore  = new BasicCookieStore();
> > 
> >  
> > BasicClientCookie stdCookie = new BasicClientCookie("name", "value");
> > stdCookie.setVersion(1);
> > stdCookie.setDomain(".mycompany.com");
> > stdCookie.setPath("/");
> > stdCookie.setSecure(true);
> >  
> > // Set attributes EXACTLY as sent by the server 
> > stdCookie.setAttribute(ClientCookie.VERSION_ATTR, "1");
> > stdCookie.setAttribute(ClientCookie.DOMAIN_ATTR, ".mycompany.com");
> > 
> >  
> > 
> >  cookieStore.addCookie(stdCookie);
> > 
> >  localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
> > 
> >  
> > 
> >  HttpEntity entity = objHttp.execute(objPost, localContext).getEntity();
> > 
> >  
> > 
> >  
> > 
> > This does not work (at least for me). To work, you need to add:
> > 
> >  
> > 
> > stdCookie.setAttribute(ClientCookie.PATH, "/");
> >  
> > If I forget any of the ?set? statement, or any of the ?setAttribute?
> > statement, it does not work.
> >  
> >  
> > The question is: Why have we to set twice the components of the
> > ?BasicClientCookie?, the first using ?stdCookie.set? and the second
using
> > ?stdCookie.setAttribute??
> >  
> > And should I set ?ClientCookie.SECURE_ATTR? and
> ?ClientCookie.MAX_AGE_ATTR?
> > ?
> > 
> 
> 
> Joan
> 
> This is because some cookies set domain / path / port attributes
explicitly,
> while some do not, in which case values of those attributes are derived
from
> the properties of the origin server.
> 
> Consider the following example:
> 
> Set-Cookie: 
>   stuff="very important"; path="/"; domain="myhost.mydomain.com";
version=1
> Set-Cookie: 
>   stuff="very important"; version=1
> 
> These two cookies are obviously different but they essentially represent
the
> same piece of state information if sent in response to a request for
> "http://myhost.mydomain.com/index.html";
> 
>  
> >  
> > And the second part: when the servlet receives this cookie, it is resent
> to
> > another servlet using the same sequence of operations. But debugging,
one
> > can see that the cookie is not added to the cookieStore (the sentence
> > ?cookieStore.addCookie(stdCookie);? does not add anything to
> ?cookieStore?).
> > 
> 
> A cookie does not get added to the cookie store only if it has expired.
> 
> Hope this helps
> 
> Oleg
> 
>  
> > Can you help me?
> >  
> >  
> > Thanks in advance,
> >  
> > Joan.
> > 
> >  
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
> For additional commands, e-mail: httpclient-users-h...@hc.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
> For additional commands, e-mail: httpclient-users-h...@hc.apache.org
> 

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


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

Reply via email to