org.apache.commons.httpclient

Class Cookie

Implemented Interfaces:
Comparator<T>, Serializable
Known Direct Subclasses:
Cookie2

public class Cookie
extends NameValuePair
implements Serializable, Comparator<T>

HTTP "magic-cookie" represents a piece of state information that the HTTP agent and the target server can exchange to maintain a session.
See Also:
Serialized Form

Constructor Summary

Cookie()
Default constructor.
Cookie(String domain, String name, String value)
Creates a cookie with the given name, value and domain attribute.
Cookie(String domain, String name, String value, String path, int maxAge, boolean secure)
Creates a cookie with the given name, value, domain attribute, path attribute, maximum age attribute, and secure attribute
Cookie(String domain, String name, String value, String path, Date expires, boolean secure)
Creates a cookie with the given name, value, domain attribute, path attribute, expiration attribute, and secure attribute

Method Summary

int
compare(Object o1, Object o2)
Compares two cookies to determine order for cookie header.
boolean
equals(Object obj)
Two cookies are equal if the name, path and domain match.
String
getComment()
Returns the comment describing the purpose of this cookie, or null if no such comment has been defined.
String
getDomain()
Returns domain attribute of the cookie.
Date
getExpiryDate()
Returns the expiration Date of the cookie, or null if none exists.
String
getPath()
Returns the path attribute of the cookie
boolean
getSecure()
int
getVersion()
Returns the version of the cookie specification to which this cookie conforms.
int
hashCode()
Returns a hash code in keeping with the Object.hashCode() general hashCode contract.
boolean
isDomainAttributeSpecified()
Returns true if cookie's domain was set via a domain attribute in the Set-Cookie header.
boolean
isExpired()
Returns true if this cookie has expired.
boolean
isExpired(Date now)
Returns true if this cookie has expired according to the time passed in.
boolean
isPathAttributeSpecified()
Returns true if cookie's path was set via a path attribute in the Set-Cookie header.
boolean
isPersistent()
Returns false if the cookie should be discarded at the end of the "session"; true otherwise.
void
setComment(String comment)
If a user agent (web browser) presents this cookie to a user, the cookie's purpose will be described using this comment.
void
setDomain(String domain)
Sets the domain attribute.
void
setDomainAttributeSpecified(boolean value)
Indicates whether the cookie had a domain specified in a domain attribute of the Set-Cookie header.
void
setExpiryDate(Date expiryDate)
Sets expiration date.
void
setPath(String path)
Sets the path attribute.
void
setPathAttributeSpecified(boolean value)
Indicates whether the cookie had a path specified in a path attribute of the Set-Cookie header.
void
setSecure(boolean secure)
Sets the secure attribute of the cookie.
void
setVersion(int version)
Sets the version of the cookie specification to which this cookie conforms.
String
toExternalForm()
Return a textual representation of the cookie.
String
toString()
Return a textual representation of the cookie.

Methods inherited from class org.apache.commons.httpclient.NameValuePair

equals, getName, getValue, hashCode, setName, setValue, toString

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

Cookie

public Cookie()
Default constructor. Creates a blank cookie
Usages and Demos :

View More Examples of Cookie()
   1:     public void testDefaultConstuctor() {
   2:         Cookie dummy = new Cookie();
   3:         assertEquals( "noname=", dummy.toExternalForm() );
   4:     }

View Full Code Here
   1:         CookieSpec cookiespec = new NetscapeDraftSpec();
   2:         Cookie cookie = new Cookie();
   3:         try {
   4:             cookiespec.parseAttribute(new NameValuePair("expires", null), cookie);
   5:             fail("MalformedCookieException must have been thrown");

View Full Code Here
   1:         try {
   2:             Cookie cookie = new Cookie();
   3:             cookiespec.parseAttribute(new NameValuePair("path", null), cookie);
   4:         ...
   5:         try {
   6:             Cookie cookie = new Cookie();
   7:             cookiespec.parseAttribute(new NameValuePair("path", "   "), cookie);
   8:         ...
   9:         try {
  10:             Cookie cookie = new Cookie();
  11:             cookiespec.parseAttribute(new NameValuePair("version", null), cookie);

View Full Code Here
   1:         CookieSpec cookiespec = new CookieSpecBase();
   2:         Cookie cookie = new Cookie();
   3:         cookiespec.parseAttribute(new NameValuePair("path", null), cookie);
   4:         ...
   5:         CookieSpec cookiespec = new CookieSpecBase();
   6:         Cookie cookie = new Cookie();
   7:         cookiespec.parseAttribute(new NameValuePair("path", "   "), cookie);
   8:         ...
   9:         CookieSpec cookiespec = new CookieSpecBase();
  10:         Cookie cookie = new Cookie();
  11:         try {

View Full Code Here

Cookie

public Cookie(String domain,
              String name,
              String value)
Creates a cookie with the given name, value and domain attribute.
Parameters:
domain - the domain this cookie can be sent to
name - the cookie name
value - the cookie value

Cookie

public Cookie(String domain,
              String name,
              String value,
              String path,
              int maxAge,
              boolean secure)
Creates a cookie with the given name, value, domain attribute, path attribute, maximum age attribute, and secure attribute
Parameters:
domain - the domain this cookie can be sent to
name - the cookie name
value - the cookie value
path - the path prefix for which this cookie can be sent
maxAge - the number of seconds for which this cookie is valid. maxAge is expected to be a non-negative number. -1 signifies that the cookie should never expire.
secure - if true this cookie can only be sent over secure connections
Usages and Demos :

View More Examples of Cookie(String domain,String name,String value,String path,int maxAge,boolean secure)
   1:         System.out.println( "Making Request with Cookie: " );
   2:         Cookie cookie = new Cookie(".discursive.com", "test_cookie", "hello", "/", null, false );
   3:         client.getState().addCookie( cookie );
   4:         makeRequest(client);
   5:     }

View Full Code Here
   1:     public void testUnequality1() {
   2:         Cookie cookie1 = new Cookie(".whatever.com", "name1", "value", "/a/b/", null, false); 
   3:         ...
   4:         Cookie cookie2 = new Cookie(".whatever.com", "name1", "value", "/a/", null, false);
   5:         Comparator comparator = new CookiePathComparator();
   6:         ...
   7:     public void testUnequality2() {
   8:         Cookie cookie1 = new Cookie(".whatever.com", "name1", "value", "/a/b", null, false); 
   9:         Cookie cookie2 = new Cookie(".whatever.com", "name1", "value", "/a", null, false);

View Full Code Here
   1:         HttpState initialState = new HttpState();
   2:         Cookie mycookie = new Cookie(".foobar.com", "mycookie", "stuff", "/", null, false);
   3:         initialState.addCookie(mycookie);
   4: 
   5:         HttpClient httpclient = new HttpClient();

View Full Code Here
   1:     public void testSecondDomainLevelCookie() throws Exception {
   2:         Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false); 
   3:         cookie.setDomainAttributeSpecified(true);
   4:         ...
   5:     public void testSecondDomainLevelCookieMatch() throws Exception {
   6:         Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false); 
   7:         cookie.setDomainAttributeSpecified(true);
   8:         ...
   9:     public void testNullCookieValueFormatting() {
  10:         Cookie cookie = new Cookie(".whatever.com", "name", null, "/", null, false); 
  11:         cookie.setDomainAttributeSpecified(true);

View Full Code Here
   1:         CookieSpec cookiespec = new CookieSpecBase();
   2:         Cookie cookie = new Cookie("host", "name", "value", "/", null, false);
   3:         cookiespec.validate("host", 80, "   ", false, cookie);
   4:         ...
   5:     public void testSecondDomainLevelCookie() throws Exception {
   6:         Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false); 
   7:         cookie.setDomainAttributeSpecified(true);
   8:         ...
   9:     public void testSecondDomainLevelCookieMatch1() throws Exception {
  10:         Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false); 
  11:         cookie.setDomainAttributeSpecified(true);

View Full Code Here

Cookie

public Cookie(String domain,
              String name,
              String value,
              String path,
              Date expires,
              boolean secure)
Creates a cookie with the given name, value, domain attribute, path attribute, expiration attribute, and secure attribute
Parameters:
domain - the domain this cookie can be sent to
name - the cookie name
value - the cookie value
path - the path prefix for which this cookie can be sent
expires - the Date at which this cookie expires, or null if the cookie expires at the end of the session
secure - if true this cookie can only be sent over secure connections
Throws:
IllegalArgumentException - If cookie name is null or blank, cookie name contains a blank, or cookie name starts with character $
Usages and Demos :

View More Examples of Cookie(String domain,String name,String value,String path,Date expires,boolean secure)
   1:         System.out.println( "Making Request with Cookie: " );
   2:         Cookie cookie = new Cookie(".discursive.com", "test_cookie", "hello", "/", null, false );
   3:         client.getState().addCookie( cookie );
   4:         makeRequest(client);
   5:     }

View Full Code Here
   1:     public void testUnequality1() {
   2:         Cookie cookie1 = new Cookie(".whatever.com", "name1", "value", "/a/b/", null, false); 
   3:         ...
   4:         Cookie cookie2 = new Cookie(".whatever.com", "name1", "value", "/a/", null, false);
   5:         Comparator comparator = new CookiePathComparator();
   6:         ...
   7:     public void testUnequality2() {
   8:         Cookie cookie1 = new Cookie(".whatever.com", "name1", "value", "/a/b", null, false); 
   9:         Cookie cookie2 = new Cookie(".whatever.com", "name1", "value", "/a", null, false);

View Full Code Here
   1:         HttpState initialState = new HttpState();
   2:         Cookie mycookie = new Cookie(".foobar.com", "mycookie", "stuff", "/", null, false);
   3:         initialState.addCookie(mycookie);
   4: 
   5:         HttpClient httpclient = new HttpClient();

View Full Code Here
   1:     public void testSecondDomainLevelCookie() throws Exception {
   2:         Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false); 
   3:         cookie.setDomainAttributeSpecified(true);
   4:         ...
   5:     public void testSecondDomainLevelCookieMatch() throws Exception {
   6:         Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false); 
   7:         cookie.setDomainAttributeSpecified(true);
   8:         ...
   9:     public void testNullCookieValueFormatting() {
  10:         Cookie cookie = new Cookie(".whatever.com", "name", null, "/", null, false); 
  11:         cookie.setDomainAttributeSpecified(true);

View Full Code Here
   1:         CookieSpec cookiespec = new CookieSpecBase();
   2:         Cookie cookie = new Cookie("host", "name", "value", "/", null, false);
   3:         cookiespec.validate("host", 80, "   ", false, cookie);
   4:         ...
   5:     public void testSecondDomainLevelCookie() throws Exception {
   6:         Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false); 
   7:         cookie.setDomainAttributeSpecified(true);
   8:         ...
   9:     public void testSecondDomainLevelCookieMatch1() throws Exception {
  10:         Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false); 
  11:         cookie.setDomainAttributeSpecified(true);

View Full Code Here

Method Details

compare

public int compare(Object o1,
                   Object o2)
Compares two cookies to determine order for cookie header.

Most specific should be first.

This method is implemented so a cookie can be used as a comparator for a SortedSet of cookies. Specifically it's used above in the createCookieHeader method.

Parameters:
o1 - The first object to be compared
o2 - The second object to be compared
Returns:
See java.util.Comparator.compare(Object,Object)

equals

public boolean equals(Object obj)
Two cookies are equal if the name, path and domain match.
Specified by:
equals in interface Comparator<T>
Overrides:
equals in interface NameValuePair
Parameters:
obj - The object to compare against.
Returns:
true if the two objects are equal.

getComment

public String getComment()
Returns the comment describing the purpose of this cookie, or null if no such comment has been defined.
Returns:
comment

getDomain

public String getDomain()
Returns domain attribute of the cookie.
Returns:
the value of the domain attribute
Usages and Demos :

View More Examples of getDomain()
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: import org.apache.commons.httpclient.NameValuePair;
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.util.ParameterFormatter;
   8:         ...
   9: 
  10:     public final static String SET_COOKIE_KEY = "set-cookie";
  11: 
  12:         ...
  13:         if (cookie.isDomainAttributeSpecified() 
  14:             && (!cookie.getDomain().equals(host))) {

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(String host, int port, String path, 
  11:         boolean secure, final String header) 
  12:         ...
  13: 
  14:             if (!host.endsWith(cookie.getDomain())) {

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(
  11:             String host, int port, String path, boolean secure, final Header header)
  12:         ...
  13:         this.formatter.format(buffer, new NameValuePair(name, value));
  14:         if (cookie.getDomain() != null && cookie.isDomainAttributeSpecified()) {

View Full Code Here

getExpiryDate

public Date getExpiryDate()
Returns the expiration Date of the cookie, or null if none exists.

Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.

Returns:
Expiration Date, or null.
Usages and Demos :

View More Examples of getExpiryDate()
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(String host, int port, String path, 
  11:         boolean secure, final String header) 
  12:         ...
  13:         return
  14:             (cookie.getExpiryDate() == null 

View Full Code Here

getPath

public String getPath()
Returns the path attribute of the cookie
Returns:
The value of the path attribute.
Usages and Demos :

View More Examples of getPath()
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: import org.apache.commons.httpclient.NameValuePair;
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.util.ParameterFormatter;
   8:         ...
   9: 
  10:     public final static String SET_COOKIE_KEY = "set-cookie";
  11: 
  12:         ...
  13:         formatParam(buffer, new NameValuePair(cookie.getName(), value), version);
  14:         if ((cookie.getPath() != null) && cookie.isPathAttributeSpecified()) {

View Full Code Here
   1: 
   2: import org.apache.commons.httpclient.Cookie;
   3: 
   4:         ...
   5:             
   6:             javax.servlet.http.Cookie[] cookiesIn = request.getCookies();
   7:             if(cookiesIn != null)
   8:         ...
   9:             {
  10:                 Cookie[] commonsCookies = new Cookie[cookiesIn.length];
  11:                 for(int i = 0; i < cookiesIn.length; i += 1)
  12:         ...
  13:                     }
  14:                     String path = c.getPath();

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(String host, int port, String path, 
  11:         boolean secure, final String header) 
  12:         ...
  13: 
  14:         if (!path.startsWith(cookie.getPath())) {

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(
  11:             String host, int port, String path, boolean secure, final Header header)
  12:         ...
  13:         }
  14:         if ((cookie.getPath() != null) && (cookie.isPathAttributeSpecified())) {

View Full Code Here

getSecure

public boolean getSecure()
Returns:
true if this cookie should only be sent over secure connections.
Usages and Demos :

View More Examples of getSecure()
   1: 
   2: import org.apache.commons.httpclient.Cookie;
   3: 
   4:         ...
   5:             
   6:             javax.servlet.http.Cookie[] cookiesIn = request.getCookies();
   7:             if(cookiesIn != null)
   8:         ...
   9:             {
  10:                 Cookie[] commonsCookies = new Cookie[cookiesIn.length];
  11:                 for(int i = 0; i < cookiesIn.length; i += 1)
  12:         ...
  13:                     
  14:                     commonsCookies[i] = new Cookie(domain, c.getName(), c.getValue(), path, c.getMaxAge(), c.getSecure());

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(
  11:             String host, int port, String path, boolean secure, final Header header)
  12:         ...
  13:           }
  14:           return cookie.getSecure() == origin.isSecure();

View Full Code Here

getVersion

public int getVersion()
Returns the version of the cookie specification to which this cookie conforms.
Returns:
the version of the cookie.
Usages and Demos :

View More Examples of getVersion()
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: import org.apache.commons.httpclient.NameValuePair;
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.util.ParameterFormatter;
   8:         ...
   9: 
  10:     public final static String SET_COOKIE_KEY = "set-cookie";
  11: 
  12:         ...
  13:         }
  14:         int version = cookie.getVersion();

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(
  11:             String host, int port, String path, boolean secure, final Header header)
  12:         ...
  13:             Cookie2 cookie2 = (Cookie2) cookie;
  14:             int version = cookie2.getVersion();

View Full Code Here

hashCode

public int hashCode()
Returns a hash code in keeping with the Object.hashCode() general hashCode contract.
Overrides:
hashCode in interface NameValuePair
Returns:
A hash code

isDomainAttributeSpecified

public boolean isDomainAttributeSpecified()
Returns true if cookie's domain was set via a domain attribute in the Set-Cookie header.
Returns:
value true if the cookie's domain was explicitly set, false otherwise.

isExpired

public boolean isExpired()
Returns true if this cookie has expired.
Returns:
true if the cookie has expired.

isExpired

public boolean isExpired(Date now)
Returns true if this cookie has expired according to the time passed in.
Parameters:
now - The current time.
Returns:
true if the cookie expired.

isPathAttributeSpecified

public boolean isPathAttributeSpecified()
Returns true if cookie's path was set via a path attribute in the Set-Cookie header.
Returns:
value true if the cookie's path was explicitly set, false otherwise.

isPersistent

public boolean isPersistent()
Returns false if the cookie should be discarded at the end of the "session"; true otherwise.
Returns:
false if the cookie should be discarded at the end of the "session"; true otherwise

setComment

public void setComment(String comment)
If a user agent (web browser) presents this cookie to a user, the cookie's purpose will be described using this comment.
Parameters:
comment -
See Also:
getComment()
Usages and Demos :

View More Examples of setComment(String comment)
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(String host, int port, String path, 
  11:         boolean secure, final String header) 
  12:         ...
  13: 
  14:             cookie.setComment(paramValue);

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(
  11:             String host, int port, String path, boolean secure, final Header header)
  12:         ...
  13:               throws MalformedCookieException {
  14:           cookie.setComment(comment);

View Full Code Here

setDomain

public void setDomain(String domain)
Sets the domain attribute.
Parameters:
domain - The value of the domain attribute
See Also:
getDomain()
Usages and Demos :

View More Examples of setDomain(String domain)
   1: 
   2: import org.apache.commons.httpclient.Cookie;
   3: import org.apache.commons.httpclient.Header;
   4:         ...
   5:       assertTrue("X-AccessCount == 2", count == 2);
   6:       Cookie[] cookies = state.getCookies();
   7:         ...
   8:       Cookie sessionID = null;
   9:       for(int c = 0; c < cookies.length; c ++)
  10:         ...
  11:       log.info("Saw JSESSIONID="+sessionID);
  12:       sessionID.setDomain(servers[1]);

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:             response.setStatusLine(httpversion, HttpStatus.SC_OK);
  10:             response.addHeader(new Header("Set-Cookie", "name1=value1; path=/test"));
  11:             response.setBodyString("whatever");
  12:         ...
  13:                 if ("localhost.local".equals(cookie.getDomain())) {
  14:                     cookie.setDomain("localhost");

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(String host, int port, String path, 
  11:         boolean secure, final String header) 
  12:         ...
  13:             }
  14:             cookie.setDomain(paramValue);

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(
  11:             String host, int port, String path, boolean secure, final Header header)
  12:         ...
  13:             }
  14:             cookie.setDomain(domain);

View Full Code Here

setDomainAttributeSpecified

public void setDomainAttributeSpecified(boolean value)
Indicates whether the cookie had a domain specified in a domain attribute of the Set-Cookie header. This value is important for generating the Cookie header because some cookie specifications require that the Cookie header should only include a domain attribute if the cookie's domain was specified in the Set-Cookie header.
Parameters:
value - true if the cookie's domain was explicitly set, false otherwise.
Usages and Demos :

View More Examples of setDomainAttributeSpecified(boolean value)
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:         try {
  10:             Cookie cookie = new Cookie();
  11:             cookiespec.parseAttribute(new NameValuePair("path", null), cookie);
  12:         ...
  13:         Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false); 
  14:         cookie.setDomainAttributeSpecified(true);

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(String host, int port, String path, 
  11:         boolean secure, final String header) 
  12:         ...
  13:             cookie.setDomain(paramValue);
  14:             cookie.setDomainAttributeSpecified(true);

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(
  11:             String host, int port, String path, boolean secure, final Header header)
  12:         ...
  13:             cookie.setDomain(domain);
  14:             cookie.setDomainAttributeSpecified(true);

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:         CookieSpec cookiespec = new CookieSpecBase();
  10:         Cookie cookie = new Cookie();
  11:         cookiespec.parseAttribute(new NameValuePair("path", null), cookie);
  12:         ...
  13:         Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false); 
  14:         cookie.setDomainAttributeSpecified(true);

View Full Code Here
   1: 
   2: import org.apache.commons.httpclient.Cookie;
   3: import org.apache.commons.httpclient.Header;
   4:         ...
   5: import org.apache.commons.httpclient.auth.MalformedChallengeException;
   6: import org.apache.commons.httpclient.cookie.CookiePolicy;
   7: import org.apache.commons.httpclient.params.HttpClientParams;
   8:         ...
   9:         e = addElementToDefinition(new SimpleType(ATTR_IGNORE_COOKIES,
  10:             "Disable cookie-handling.", DEFAULT_IGNORE_COOKIES));
  11:         e.setOverrideable(true);
  12:         ...
  13:                         if (cookieParts[1].toLowerCase().equals("true")) {
  14:                             cookie.setDomainAttributeSpecified(true);

View Full Code Here

setExpiryDate

public void setExpiryDate(Date expiryDate)
Sets expiration date.

Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.

Parameters:
expiryDate - the Date after which this cookie is no longer valid.
Usages and Demos :

View More Examples of setExpiryDate(Date expiryDate)
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: import org.apache.commons.httpclient.NameValuePair;
   6: import org.apache.commons.httpclient.Cookie;
   7: 
   8:         ...
   9: 
  10:     public Cookie[] parse(String host, int port, String path, 
  11:         boolean secure, final String header) 
  12:         ...
  13:                 Date date = expiryFormat.parse(paramValue);
  14:                 cookie.setExpiryDate(date);

View Full Code Here

setPath

public void setPath(String path)
Sets the path attribute.
Parameters:
path - The value of the path attribute
See Also:
getPath()
Usages and Demos :

View More Examples of setPath(String path)
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: import org.apache.commons.httpclient.NameValuePair;
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.util.ParameterFormatter;
   8:         ...
   9: 
  10:     public final static String SET_COOKIE_KEY = "set-cookie";
  11: 
  12:         ...
  13:             }
  14:             cookie.setPath(paramValue);

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(String host, int port, String path, 
  11:         boolean secure, final String header) 
  12:         ...
  13:             }
  14:             cookie.setPath(paramValue);

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(
  11:             String host, int port, String path, boolean secure, final Header header)
  12:         ...
  13:             }
  14:             cookie.setPath(path);

View Full Code Here

setPathAttributeSpecified

public void setPathAttributeSpecified(boolean value)
Indicates whether the cookie had a path specified in a path attribute of the Set-Cookie header. This value is important for generating the Cookie header because some cookie specifications require that the Cookie header should only include a path attribute if the cookie's path was specified in the Set-Cookie header.
Parameters:
value - true if the cookie's path was explicitly set, false otherwise.
Usages and Demos :

View More Examples of setPathAttributeSpecified(boolean value)
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: import org.apache.commons.httpclient.NameValuePair;
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.util.ParameterFormatter;
   8:         ...
   9: 
  10:     public final static String SET_COOKIE_KEY = "set-cookie";
  11: 
  12:         ...
  13:             cookie.setPath(paramValue);
  14:             cookie.setPathAttributeSpecified(true);

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:         try {
  10:             Cookie cookie = new Cookie();
  11:             cookiespec.parseAttribute(new NameValuePair("path", null), cookie);
  12:         ...
  13:         cookie.setDomainAttributeSpecified(true);
  14:         cookie.setPathAttributeSpecified(true);

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(String host, int port, String path, 
  11:         boolean secure, final String header) 
  12:         ...
  13:             cookie.setPath(paramValue);
  14:             cookie.setPathAttributeSpecified(true);

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(
  11:             String host, int port, String path, boolean secure, final Header header)
  12:         ...
  13:             cookie.setPath(path);
  14:             cookie.setPathAttributeSpecified(true);

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:         CookieSpec cookiespec = new CookieSpecBase();
  10:         Cookie cookie = new Cookie();
  11:         cookiespec.parseAttribute(new NameValuePair("path", null), cookie);
  12:         ...
  13:         cookie.setDomainAttributeSpecified(true);
  14:         cookie.setPathAttributeSpecified(true);

View Full Code Here

setSecure

public void setSecure(boolean secure)
Sets the secure attribute of the cookie.

When true the cookie should only be sent using a secure protocol (https). This should only be set when the cookie's originating server used a secure protocol to set the cookie's value.

Parameters:
secure - The value of the secure attribute
See Also:
getSecure()
Usages and Demos :

View More Examples of setSecure(boolean secure)
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(String host, int port, String path, 
  11:         boolean secure, final String header) 
  12:         ...
  13: 
  14:             cookie.setSecure(true);

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:     
  10:     public Cookie[] parse(
  11:             String host, int port, String path, boolean secure, final Header header)
  12:         ...
  13:               throws MalformedCookieException {
  14:           cookie.setSecure(true);

View Full Code Here

setVersion

public void setVersion(int version)
Sets the version of the cookie specification to which this cookie conforms.
Parameters:
version - the version of the cookie.
See Also:
getVersion()
Usages and Demos :

View More Examples of setVersion(int version)
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: import org.apache.commons.httpclient.NameValuePair;
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.util.ParameterFormatter;
   8:         ...
   9: 
  10:     public final static String SET_COOKIE_KEY = "set-cookie";
  11: 
  12:         ...
  13:             try {
  14:                cookie.setVersion(Integer.parseInt(paramValue));

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:         try {
  10:             Cookie cookie = new Cookie();
  11:             cookiespec.parseAttribute(new NameValuePair("path", null), cookie);
  12:         ...
  13: 
  14:         cookie.setVersion(1);

View Full Code Here
   1: 
   2: package org.apache.commons.httpclient.cookie;
   3: 
   4:         ...
   5: 
   6: import org.apache.commons.httpclient.Cookie;
   7: import org.apache.commons.httpclient.Header;
   8:         ...
   9:         CookieSpec cookiespec = new CookieSpecBase();
  10:         Cookie cookie = new Cookie();
  11:         cookiespec.parseAttribute(new NameValuePair("path", null), cookie);
  12:         ...
  13:         Cookie cookie = new Cookie();
  14:         cookie.setVersion(-1);

View Full Code Here

toExternalForm

public String toExternalForm()
Return a textual representation of the cookie.
Returns:
string.
Usages and Demos :

View More Examples of toExternalForm()
   1: 
   2: import org.apache.commons.httpclient.Cookie;
   3: import org.apache.commons.httpclient.Header;
   4:         ...
   5: import org.apache.commons.httpclient.auth.MalformedChallengeException;
   6: import org.apache.commons.httpclient.cookie.CookiePolicy;
   7: import org.apache.commons.httpclient.params.HttpClientParams;
   8:         ...
   9:         e = addElementToDefinition(new SimpleType(ATTR_IGNORE_COOKIES,
  10:             "Disable cookie-handling.", DEFAULT_IGNORE_COOKIES));
  11:         e.setOverrideable(true);
  12:         ...
  13:                         logger.fine(
  14:                             "Adding cookie: " + cookie.toExternalForm());

View Full Code Here

toString

public String toString()
Return a textual representation of the cookie.
Overrides:
toString in interface NameValuePair
Returns:
string.