com.ibm.wbi.protocol.http
Class HttpCookie

java.lang.Object
  |
  +--com.ibm.wbi.protocol.http.HttpCookie

public class HttpCookie
extends java.lang.Object

Represent a cookie according to the Netscape specification (http://home.netscape.com/newsref/std/cookie_spec.html). Example usage in a RequestEditor's handleRequest method for creating a new cookie:

 //...
 HttpCookie cookie = new HttpCookie("mycookie", "foo");
 DocumentInfo di = (DocumentInfo)e.getRequestInfo();
 HttpRequestHeader hqh = di.getHttpRequestHeader();
 addCookie(hqh, scookie);
 //...
 
And for looking at an existing cookie, perhaps set by a server or WBI generator.
 //...
 DocumentInfo di = (DocumentInfo)e.getRequestInfo();
 HttpRequestHeader hqh = di.getHttpRequestHeader();
 HttpCookie cookie = getCookie(hqh, "mycookie");
 if (cookie != null)
   value = cookie.getValue();
 //...
 


Field Summary
protected  java.lang.String name
           
protected  java.lang.String value
           
 
Constructor Summary
HttpCookie(java.lang.String unparsed)
          Creates a new HttpCookie instance based on the unparsed string.
HttpCookie(java.lang.String name, java.lang.String value)
          Creates a new HttpCookie instance.
 
Method Summary
static void addCookie(HttpRequestHeader h, HttpCookie cookie)
          Adds a Cookie to an HTTP header.
static HttpCookie getCookie(HttpRequestHeader h)
          Get the first Cookie header line in an HTTP header.
static HttpCookie getCookie(HttpRequestHeader h, java.lang.String name)
          Get the first cookie in an HTTP header with a specified name.
static java.util.Vector getCookies(HttpRequestHeader h)
          Get all cookie header lines in an HTTP header.
 java.lang.String getName()
          Get the name of the cookie
 java.lang.String getValue()
          Get the value of the cookie
static void setCookie(HttpRequestHeader h, HttpCookie cookie)
          Sets a value for the Cookie header line in an HTTP header, eliminating all previous values for the Cookie header.
 void setName(java.lang.String v)
          Set the name of the cookie
 void setValue(java.lang.String v)
          Set the value of the cookie
 java.lang.String toString()
          Show the string representation of the cookie
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name

value

protected java.lang.String value
Constructor Detail

HttpCookie

public HttpCookie(java.lang.String unparsed)
Creates a new HttpCookie instance based on the unparsed string. Should the parsing fail, then some or all of that string is ignored.
Parameters:
unparsed - a String value

HttpCookie

public HttpCookie(java.lang.String name,
                  java.lang.String value)
Creates a new HttpCookie instance.
Parameters:
name - The name of the cookie
value - The value of the cookie
Method Detail

toString

public java.lang.String toString()
Show the string representation of the cookie
Overrides:
toString in class java.lang.Object
Returns:
The string representation of the cookie

getName

public java.lang.String getName()
Get the name of the cookie
Returns:
The name of the cookie

setName

public void setName(java.lang.String v)
Set the name of the cookie
Parameters:
v - The new name

getValue

public java.lang.String getValue()
Get the value of the cookie
Returns:
The value of the cookie

setValue

public void setValue(java.lang.String v)
Set the value of the cookie
Parameters:
v - The new value for the cookie

getCookie

public static HttpCookie getCookie(HttpRequestHeader h)
Get the first Cookie header line in an HTTP header.
Parameters:
h - The HttpRequestHeader.
Returns:
The first Cookie header line as an HttpCookie, or null if there are none.

getCookie

public static HttpCookie getCookie(HttpRequestHeader h,
                                   java.lang.String name)
Get the first cookie in an HTTP header with a specified name.
Parameters:
h - The HttpRequestHeader.
name - The name to look for (case-sensitive).
Returns:
The cookie as an HttpCookie.

getCookies

public static java.util.Vector getCookies(HttpRequestHeader h)
Get all cookie header lines in an HTTP header.
Parameters:
h - The HttpRequestHeader.
Returns:
All cookie header lines as HttpCookies.

setCookie

public static void setCookie(HttpRequestHeader h,
                             HttpCookie cookie)
Sets a value for the Cookie header line in an HTTP header, eliminating all previous values for the Cookie header.
Parameters:
h - The HttpRequestHeader.
cookie - The value to set.

addCookie

public static void addCookie(HttpRequestHeader h,
                             HttpCookie cookie)
Adds a Cookie to an HTTP header.
Parameters:
h - The HttpRequestHeader.
cookie - The value to add.