org.apache.commons.httpclient
Class HttpState

java.lang.Object
  extended by 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: 155418 $ $Date: 2005-02-26 14:01:52 +0100 (Sa, 26 Feb 2005) $
Author:
Remy Maucherat, Rodney Waldhoff, Jeff Dever, Sean C. Sullivan, Michael Becke, Oleg Kalnichevski, Mike Bowler, Adrian Sutton

Constructor Summary
HttpState()
          Default constructor.
 
Method Summary
 void addCookie(Cookie cookie)
          Adds an HTTP cookie, replacing any existing equivalent cookies.
 void addCookies(List<Cookie> cookies)
          Adds an array of HTTP cookies.
 void clear()
          Clears the state information (all cookies, credentials and proxy credentials).
 void clearCookies()
          Clears all cookies.
 void clearCredentials()
          Clears all credentials.
 void clearProxyCredentials()
          Clears all proxy credentials.
 List<Cookie> getCookies()
          Returns an array of cookies that this HTTP state currently contains.
 Credentials getCredentials(AuthScope authscope)
          Get the credentials for the given authentication scope.
 Credentials getProxyCredentials(AuthScope authscope)
          Get the proxy credentials for the given authentication scope.
 boolean purgeExpiredCookies()
          Removes all of cookies in this HTTP state that have expired according to the current system time.
 boolean purgeExpiredCookies(Date date)
          Removes all of cookies in this HTTP state that have expired by the specified date.
 void setCredentials(AuthScope authscope, Credentials credentials)
          Sets the credentials for the given authentication scope.
 void setProxyCredentials(AuthScope authscope, Credentials credentials)
          Sets the proxy credentials for the given authentication realm.
 String toString()
          Returns a string representation of this HTTP state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HttpState

public HttpState()
Default constructor.

Method Detail

addCookie

public void addCookie(Cookie cookie)
Adds an HTTP cookie, replacing any existing equivalent cookies. If the given cookie has already expired it will not be added, but existing values will still be removed.

Parameters:
cookie - the cookie to be added
See Also:
addCookies(List)

addCookies

public void addCookies(List<Cookie> cookies)
Adds an array of HTTP cookies. Cookies are added individually and in the given array order. If any of the given cookies has already expired it will not be added, but existing values will still be removed.

Parameters:
cookies - the cookies to be added
See Also:
addCookie(Cookie)

getCookies

public List<Cookie> getCookies()
Returns an array of cookies that this HTTP state currently contains.

Returns:
an array of cookies.

purgeExpiredCookies

public boolean purgeExpiredCookies()
Removes all of cookies in this HTTP state that have expired according to the current system time.

Returns:
true on success
See Also:
purgeExpiredCookies(java.util.Date)

purgeExpiredCookies

public boolean purgeExpiredCookies(Date date)
Removes all of cookies in this HTTP state 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()

setCredentials

public void setCredentials(AuthScope authscope,
                           Credentials credentials)
Sets the credentials for the given authentication scope. Any previous credentials for the given scope will be overwritten.

Parameters:
authscope - the authentication scope
credentials - the authentication credentials for the given scope.
Since:
3.0
See Also:
getCredentials(AuthScope), setProxyCredentials(AuthScope, Credentials)

getCredentials

public Credentials getCredentials(AuthScope authscope)
Get the credentials for the given authentication scope.

Parameters:
authscope - the authentication scope
Returns:
the credentials
Since:
3.0
See Also:
setCredentials(AuthScope, Credentials)

setProxyCredentials

public void setProxyCredentials(AuthScope authscope,
                                Credentials credentials)
Sets the proxy credentials for the given authentication realm. Any previous credentials for the given realm will be overwritten.

Parameters:
authscope - the authentication scope
credentials - the authentication credentials for the given realm.
Since:
3.0
See Also:
getProxyCredentials(AuthScope), setCredentials(AuthScope, Credentials)

getProxyCredentials

public Credentials getProxyCredentials(AuthScope authscope)
Get the proxy credentials for the given authentication scope.

Parameters:
authscope - the authentication scope
Returns:
the credentials
Since:
3.0
See Also:
setProxyCredentials(AuthScope, Credentials)

toString

public String toString()
Returns a string representation of this HTTP state.

Overrides:
toString in class Object
Returns:
The string representation of the HTTP state.
See Also:
Object.toString()

clearCredentials

public void clearCredentials()
Clears all credentials.


clearProxyCredentials

public void clearProxyCredentials()
Clears all proxy credentials.


clearCookies

public void clearCookies()
Clears all cookies.


clear

public void clear()
Clears the state information (all cookies, credentials and proxy credentials).



Copyright (c) 1999-2005 - Apache Software Foundation