# CookieHandler

public abstract class **CookieHandler** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  

|---|---|---|
| Known Direct Subclasses [CookieManager](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/CookieManager.html) |---|---| | [CookieManager](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/CookieManager.html) | CookieManager provides a concrete implementation of `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/CookieHandler.html`, which separates the storage of cookies from the policy surrounding accepting and rejecting cookies. | |||

A CookieHandler object provides a callback mechanism to hook up a
HTTP state management policy implementation into the HTTP protocol
handler. The HTTP state management mechanism specifies a way to
create a stateful session with HTTP requests and responses.

A system-wide CookieHandler that to used by the HTTP protocol
handler can be registered by doing a
CookieHandler.setDefault(CookieHandler). The currently registered
CookieHandler can be retrieved by calling
CookieHandler.getDefault().

For more information on HTTP state management, see [*RFC 2965: HTTP State Management Mechanism*](http://www.ietf.org/rfc/rfc2965.txt)

### Public Constructor Summary

|---|---|
|   | [CookieHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/CookieHandler.html#CookieHandler())() |

### Public Method Summary

|---|---|
| abstract [Map](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Map.html)\<[String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html), [List](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/List.html)\<[String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)\>\> | [get](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/CookieHandler.html#get(java.net.URI,%20java.util.Map<java.lang.String,%20java.util.List<java.lang.String>>))([URI](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/URI.html) uri, [Map](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Map.html)\<[String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html), [List](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/List.html)\<[String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)\>\> requestHeaders) Gets all the applicable cookies from a cookie cache for the specified uri in the request header. |
| synchronized static [CookieHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/CookieHandler.html) | [getDefault](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/CookieHandler.html#getDefault())() Gets the system-wide cookie handler. |
| abstract void | [put](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/CookieHandler.html#put(java.net.URI,%20java.util.Map<java.lang.String,%20java.util.List<java.lang.String>>))([URI](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/URI.html) uri, [Map](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Map.html)\<[String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html), [List](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/List.html)\<[String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)\>\> responseHeaders) Sets all the applicable cookies, examples are response header fields that are named Set-Cookie2, present in the response headers into a cookie cache. |
| synchronized static void | [setDefault](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/CookieHandler.html#setDefault(java.net.CookieHandler))([CookieHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/CookieHandler.html) cHandler) Sets (or unsets) the system-wide cookie handler. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

## Public Constructors

#### public
**CookieHandler**
()

<br />

## Public Methods

#### public abstract [Map](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Map.html)\<[String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html), [List](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/List.html)\<[String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)\>\>
**get**
([URI](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/URI.html) uri, [Map](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Map.html)\<[String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html), [List](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/List.html)\<[String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)\>\> requestHeaders)

Gets all the applicable cookies from a cookie cache for the
specified uri in the request header.

The `URI` passed as an argument specifies the intended use for
the cookies. In particular the scheme should reflect whether the cookies
will be sent over http, https or used in another context like javascript.
The host part should reflect either the destination of the cookies or
their origin in the case of javascript.

It is up to the implementation to take into account the `URI` and
the cookies attributes and security settings to determine which ones
should be returned.

HTTP protocol implementers should make sure that this method is
called after all request headers related to choosing cookies
are added, and before the request is sent.

<br />

##### Parameters

| uri | a `URI` representing the intended use for the cookies |
| requestHeaders | - a Map from request header field names to lists of field values representing the current request headers |
|---|---|

##### Returns

- an immutable map from state management headers, with field names "Cookie" or "Cookie2" to a list of cookies containing state information

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if either argument is null |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/CookieHandler.html#put(java.net.URI,%20java.util.Map<java.lang.String,%20java.util.List<java.lang.String>>)`

#### public static synchronized [CookieHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/CookieHandler.html)
**getDefault**
()

Gets the system-wide cookie handler.

##### Returns

- the system-wide cookie handler; A null return means there is no system-wide cookie handler currently set.

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | If a security manager has been installed and it denies `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/NetPermission.html``("getCookieHandler")` |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/CookieHandler.html#setDefault(java.net.CookieHandler)`

#### public abstract void
**put**
([URI](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/URI.html) uri, [Map](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Map.html)\<[String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html), [List](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/List.html)\<[String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)\>\> responseHeaders)

Sets all the applicable cookies, examples are response header
fields that are named Set-Cookie2, present in the response
headers into a cookie cache.

##### Parameters

| uri | a `URI` where the cookies come from |
| responseHeaders | an immutable map from field names to lists of field values representing the response header fields returned |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if either argument is null |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/CookieHandler.html#get(java.net.URI,%20java.util.Map<java.lang.String,%20java.util.List<java.lang.String>>)`

#### public static synchronized void
**setDefault**
([CookieHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/CookieHandler.html) cHandler)

Sets (or unsets) the system-wide cookie handler.

Note: non-standard http protocol handlers may ignore this setting.

##### Parameters

| cHandler | The HTTP cookie handler, or `null` to unset. |
|---|---|

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | If a security manager has been installed and it denies `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/NetPermission.html``("setCookieHandler")` |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/CookieHandler.html#getDefault()`