CookieStore interface in Java

java.net.CookieStore

A CookieStore object represents a storage for cookie. Can store and retrieve cookies.

CookieManager will call CookieStore.add to save cookies for every incoming HTTP response, and call CookieStore.get to retrieve cookie for every outgoing HTTP request. A CookieStoreis responsible for removing HttpCookie instances which have expired.

Declaration

public interface CookieStore {

    public void add(URI uri, HttpCookie cookie);

    public List<HttpCookie> get(URI uri);

    public List<HttpCookie> getCookies();

    public List<URI> getURIs();

    public boolean remove(URI uri, HttpCookie cookie);

    public boolean removeAll();
}

Methods

1. add(URI uri, HttpCookie cookie)

void java.net.CookieStore.add(URI uri, HttpCookie cookie)

Adds one HTTP cookie to the store. This is called for everyincoming HTTP response.

A cookie to store may or may not be associated with an URI. If itis not associated with an URI, the cookie's domain and path attributewill indicate where it comes from. If it is associated with an URI andits domain and path attribute are not specified, given URI will indicatewhere this cookie comes from.

If a cookie corresponding to the given URI already exists,then it is replaced with the new one.

Parameters: Two parameters are required for this method.

uri: the uri this cookie associated with.if null, this cookie will not be associated with an URI.

cookie: the cookie to store.

Throws:

1. NullPointerException - if cookie is null.

2. get(URI uri)

List<HttpCookie> java.net.CookieStore.get(URI uri)

Retrieve cookies associated with given URI, or whose domain matches thegiven URI. Only cookies that have not expired are returned.This is called for every outgoing HTTP request.

Parameters: One parameter is required for this method.

uri: the uri associated with the cookies to be returned.

Returns: an immutable list of HttpCookie,return empty list if no cookies match the given URI.

Throws:

1. NullPointerException - if uri is null.

3. getCookies()

List<HttpCookie> java.net.CookieStore.getCookies()

Get all not-expired cookies in cookie store.

Returns: an immutable list of http cookies;return empty list if there's no http cookie in store.

4. getURIs()

List<URI> java.net.CookieStore.getURIs()

Get all URIs which identify the cookies in this cookie store.

Returns: an immutable list of URIs;return empty list if no cookie in this cookie stories associated with an URI.

5. remove(URI uri, HttpCookie cookie)

boolean java.net.CookieStore.remove(URI uri, HttpCookie cookie)

Remove a cookie from store.

Parameters: Two parameters are required for this method.

uri: the uri this cookie associated with.if null, the cookie to be removed is not associated with an URI when added; if not null, the cookie to be removed is associated with the given URI when added.

cookie: the cookie to remove.

Returns: true if this store contained the specified cookie.

Throws:

1. NullPointerException - if cookie is null.

6. removeAll()

boolean java.net.CookieStore.removeAll()

Remove all cookies in this cookie store.

Returns: true if this store changed as a result of the call.


Some other classes/interfaces of java.net

AuthenticatorThe class Authenticator represents an object that knows how to obtain authentication for a network connection.

BindExceptionSignals that an error occurred while attempting to bind a socket to a local address and port. 

CacheRequestRepresents channels for storing resources in the ResponseCache.

CacheResponseRepresent channels for retrieving resources from the ResponseCache.

ConnectExceptionSignals that an error occurred while attempting to connect a socket to a remote address and port.

ContentHandlerThe abstract class ContentHandler is the superclass of all classes that read an Object from a URLConnection.

ContentHandlerFactoryThis interface defines a factory for content handlers. Implementing this interface should map a MIME type into an instance of ContentHandler.

CookieHandlerA CookieHandler object provides a callback mechanism to hook up an HTTP state management policy implementation into the HTTP protocol handler.

CookieManagerCookieManager provides a concrete implementation of CookieHandler, which separates the storage of cookies from the policy surrounding accepting and rejecting cookies. 

CookiePolicyCookiePolicy implementations decide which cookies should be accepted and which should be rejected.

CookieStoreA CookieStore object represents storage for cookies. Can store and retrieve cookies.

DatagramPacketThis class represents a datagram packet.

No comments:

Post a Comment