com.sun.faban.driver.transport.sunhttp
Class ThreadCookieHandler

java.lang.Object
  extended by com.sun.faban.driver.transport.sunhttp.ThreadCookieHandler

public class ThreadCookieHandler
extends Object

ThreadCookieHandler stores cookies from a response and retrieves all applicable cookies for a particular request. On retrieval, the cookies will be formatted as required. If a cookie does not specify a version when it is received - it is non-conformant to IEEE 2965 and 2109 - it is considered a cookie according to Netscape's original proposal. Such cookies will be formatted according to Netscape's proposal. A cookie that specifies a version is considered to follow IEEE2965 and 2109 even if version is 0. Such cookies will be formatted according to IEEE2965. In all cases, the selection rules specified in IEEE2965 applies.

Note that the interface of this cookie handler does not comply with java.net.ThreadCookieHandler.

Author:
Akara Sucharitakul

Method Summary
 void addRequestCookies(HttpURLConnection c)
          Adds the applicable cookies from the cookie handler to the request header of the connection.
 Map<String,List<String>> get(URI request, Map<String,List<String>> requestHeaders)
          Selects the cookies applicable to the request URI from the cookie store and puts them into the request header.
 String[] getCookieValuesByName(String name)
          Obtains the value of all cookies in the cookie store by the name of the cookie.
static ThreadCookieHandler getInstance()
          Obtains the thread cookie handler for this thread.
static void main(String[] args)
          Main method to test cookie handler.
static ThreadCookieHandler newInstance()
          Creates a new instance of the thread cookie handler for this thread.
 void put(URI request, Map<String,List<String>> responseHeaders)
          Puts the cookies from the response headers into the cookie store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newInstance

public static ThreadCookieHandler newInstance()
Creates a new instance of the thread cookie handler for this thread.

Returns:
The thread's cookie handler

getInstance

public static ThreadCookieHandler getInstance()
Obtains the thread cookie handler for this thread.

Returns:
The thread's cookie handler

put

public void put(URI request,
                Map<String,List<String>> responseHeaders)
Puts the cookies from the response headers into the cookie store.

Parameters:
request - The URI of the request
responseHeaders - The response headers.

get

public Map<String,List<String>> get(URI request,
                                    Map<String,List<String>> requestHeaders)
Selects the cookies applicable to the request URI from the cookie store and puts them into the request header. The cookies are ordered as specified in RFE 2965.

Parameters:
request - The request URI
requestHeaders - The request header map
Returns:
The request header map with the cookies put in

addRequestCookies

public void addRequestCookies(HttpURLConnection c)
                       throws URISyntaxException
Adds the applicable cookies from the cookie handler to the request header of the connection.

Parameters:
c - The connection
Throws:
URISyntaxException

getCookieValuesByName

public String[] getCookieValuesByName(String name)
Obtains the value of all cookies in the cookie store by the name of the cookie.

Parameters:
name - The cookie name
Returns:
The values of all cookies matching this name

main

public static void main(String[] args)
                 throws IOException,
                        URISyntaxException
Main method to test cookie handler.

Parameters:
args - Name of each file representing each request header
Throws:
IOException - Cannot find or read file
URISyntaxException