org.apache.commons.httpclient
Class HttpState

java.lang.Object
  |
  +--org.apache.commons.httpclient.HttpState

public class HttpState
extends Object

A container for HTTP attributes that may persist from request to request, such as Cookies and authentication Credentials.

Version:
$Revision: 1.17 $ $Date: 2003/01/28 22:25:21 $
Author:
Remy Maucherat, Rodney Waldhoff, Jeff Dever, Sean C. Sullivan, Michael Becke, Oleg Kalnichevski, Mike Bowler

Constructor Summary
HttpState()
          Constructor for HttpState.
 
Method Summary
 void addCookie(Cookie cookie)
          Add a cookie.
 void addCookies(Cookie[] newcookies)
          Add zero or more cookies If any given cookie has already expired, deletes the corresponding existing cookie (if any).
 int getCookiePolicy()
          Return the current CookiePolicy
 Cookie[] getCookies()
          Obtain an array of my Cookies.
 Cookie[] getCookies(String domain, int port, String path, boolean secure)
          Obtain an array of my Cookies that match the given request parameters.
 Cookie[] getCookies(String domain, int port, String path, boolean secure, Date now)
          Deprecated. use HttpState.getCookies(String, int, String, boolean)
 Credentials getCredentials(String realm)
          Get the Credentials for the given authentication realm.
 HttpConnectionManager getHttpConnectionManager()
          Returns the httpConnectionManager.
 Credentials getProxyCredentials(String realm)
          Get the Credentials for the proxy with the given authentication realm.
 boolean purgeExpiredCookies()
          Remove all of my Cookies that have expired according to the current system time.
 boolean purgeExpiredCookies(Date date)
          Remove all of my Cookies that have expired by the specified date.
 void setCookiePolicy(int policy)
          Set the CookiePolicy to one of CookiePolicy.COMPATIBILITY, CookiePolicy.NETSCAPE_DRAFT or CookiePolicy.RFC2109
 void setCredentials(String realm, Credentials credentials)
          Set the Credentials for the given authentication realm.
 void setHttpConnectionManager(HttpConnectionManager httpConnectionManager)
          Sets the httpConnectionManager.
 void setProxyCredentials(String realm, Credentials credentials)
          Set the for the proxy with the given authentication realm.
 String toString()
          Return a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HttpState

public HttpState()
Constructor for HttpState.

Method Detail

addCookie

public void addCookie(Cookie cookie)
Add a cookie. If the given cookie has already expired, deletes the corresponding existing cookie (if any).

Parameters:
cookie - the Cookie to add
See Also:
addCookies(Cookie[])

addCookies

public void addCookies(Cookie[] newcookies)
Add zero or more cookies If any given cookie has already expired, deletes the corresponding existing cookie (if any).

Parameters:
newcookies - the Cookies to add
See Also:
addCookie(Cookie)

getCookies

public Cookie[] getCookies()
Obtain an array of my Cookies.

Returns:
an array of my Cookies.
See Also:
getCookies(String, int, String, boolean, java.util.Date)

getCookies

public Cookie[] getCookies(String domain,
                           int port,
                           String path,
                           boolean secure,
                           Date now)
Deprecated. use HttpState.getCookies(String, int, String, boolean)

Obtain an array of my Cookies that match the given request parameters.

Parameters:
domain - the request domain
port - the request port
path - the request path
secure - true when using HTTPS
now - the Date by which expiration is determined
Returns:
an array of my Cookies.
See Also:
Cookie.matches(java.lang.String, int, java.lang.String, boolean, java.util.Date), getCookies()

getCookies

public Cookie[] getCookies(String domain,
                           int port,
                           String path,
                           boolean secure)
Obtain an array of my Cookies that match the given request parameters.

Parameters:
domain - the request domain
port - the request port
path - the request path
secure - true when using HTTPS
Returns:
an array of my Cookies.
See Also:
Cookie.matches(java.lang.String, int, java.lang.String, boolean, java.util.Date), getCookies()

purgeExpiredCookies

public boolean purgeExpiredCookies()
Remove all of my Cookies that have expired according to the current system time.

See Also:
purgeExpiredCookies(java.util.Date)

purgeExpiredCookies

public boolean purgeExpiredCookies(Date date)
Remove all of my Cookies that have expired by the specified date.

Parameters:
date - The date to compare against.
Returns:
true if any cookies were purged.
See Also:
Cookie.isExpired(java.util.Date), purgeExpiredCookies()

getCookiePolicy

public int getCookiePolicy()
Return the current CookiePolicy

Returns:
The cookie policy.

setCookiePolicy

public void setCookiePolicy(int policy)
Set the CookiePolicy to one of CookiePolicy.COMPATIBILITY, CookiePolicy.NETSCAPE_DRAFT or CookiePolicy.RFC2109

Parameters:
policy - new cookie policy

setCredentials

public void setCredentials(String realm,
                           Credentials credentials)
Set the Credentials for the given authentication realm. When realm is null, I'll use the given credentials when no other Credentials have been supplied for the given challenging realm. (I.e., use a null realm to set the "default" credentials.)

Any previous credentials for this realm will be overwritten.

Parameters:
realm - the authentication realm
credentials - the authentication credentials for the given realm
See Also:
getCredentials(String), setProxyCredentials(String, Credentials)

getCredentials

public Credentials getCredentials(String realm)
Get the Credentials for the given authentication realm. If the realm exists, return the coresponding credentials. If the realm does not exist, return the default Credentials. If there is no default credentials, return null.

Parameters:
realm - the authentication realm
Returns:
the credentials
See Also:
setCredentials(String, Credentials)

setProxyCredentials

public void setProxyCredentials(String realm,
                                Credentials credentials)
Set the for the proxy with the given authentication realm. When realm is null, I'll use the given credentials when no other Credentials have been supplied for the given challenging realm. (I.e., use a null realm to set the "default" credentials.) Realms rarely make much sense with proxies, so null is normally a good choice here.

Any previous credentials for this realm will be overwritten.

Parameters:
realm - the authentication realm
credentials - the authentication credentials for the given realm
See Also:
getProxyCredentials(String), setCredentials(String, Credentials)

getProxyCredentials

public Credentials getProxyCredentials(String realm)
Get the Credentials for the proxy with the given authentication realm. If the realm exists, return the coresponding credentials. If the realm does not exist, return the default Credentials. If there is no default credentials, return null.

Parameters:
realm - the authentication realm
Returns:
the credentials
See Also:
setProxyCredentials(java.lang.String, org.apache.commons.httpclient.Credentials)

toString

public String toString()
Return a string representation of this object.

Overrides:
toString in class Object
Returns:
The string representation.
See Also:
Object.toString()

getHttpConnectionManager

public HttpConnectionManager getHttpConnectionManager()
Returns the httpConnectionManager.

Returns:
HttpConnectionManager
Since:
2.0

setHttpConnectionManager

public void setHttpConnectionManager(HttpConnectionManager httpConnectionManager)
Sets the httpConnectionManager.

Parameters:
httpConnectionManager - The httpConnectionManager to set
Since:
2.0


Copyright (c) 1999-2002 - Apache Software Foundation