org.apache.commons.httpclient

Class HttpState

public class HttpState extends Object

A container for HTTP attributes that may persist from request to request, such as {@link Cookie cookies} and authentication {@link Credentials credentials}.

Version: $Revision: 377704 $ $Date: 2006-02-14 06:48:29 -0500 (Tue, 14 Feb 2006) $

Author: Remy Maucherat Rodney Waldhoff Jeff Dever Sean C. Sullivan Michael Becke Oleg Kalnichevski Mike Bowler Adrian Sutton

Field Summary
static StringPREEMPTIVE_DEFAULT
The default value for {@link #PREEMPTIVE_PROPERTY}.
static StringPREEMPTIVE_PROPERTY
The boolean system property name to turn on preemptive authentication.
Constructor Summary
HttpState()
Default constructor.
Method Summary
voidaddCookie(Cookie cookie)
Adds an {@link Cookie HTTP cookie}, replacing any existing equivalent cookies.
voidaddCookies(Cookie[] cookies)
Adds an array of {@link Cookie HTTP cookies}.
voidclear()
Clears the state information (all cookies, credentials and proxy credentials).
voidclearCookies()
Clears all cookies.
voidclearCredentials()
Clears all credentials.
voidclearProxyCredentials()
Clears all proxy credentials.
intgetCookiePolicy()
Returns the current {@link CookiePolicy cookie policy} for this HTTP state.
Cookie[]getCookies()
Returns an array of {@link Cookie cookies} that this HTTP state currently contains.
Cookie[]getCookies(String domain, int port, String path, boolean secure)
Returns an array of {@link Cookie cookies} in this HTTP state that match the given request parameters.
CredentialsgetCredentials(String realm, String host)
Get the {@link Credentials credentials} for the given authentication scope on the given host.
CredentialsgetCredentials(AuthScope authscope)
Get the {@link Credentials credentials} for the given authentication scope.
CredentialsgetProxyCredentials(String realm, String proxyHost)
Get the {@link Credentials credentials} for the proxy host with the given authentication scope.
CredentialsgetProxyCredentials(AuthScope authscope)
Get the {@link Credentials proxy credentials} for the given authentication scope.
booleanisAuthenticationPreemptive()
Returns true if preemptive authentication should be attempted, false otherwise.
booleanpurgeExpiredCookies()
Removes all of {@link Cookie cookies} in this HTTP state that have expired according to the current system time.
booleanpurgeExpiredCookies(Date date)
Removes all of {@link Cookie cookies} in this HTTP state that have expired by the specified {@link java.util.Date date}.
voidsetAuthenticationPreemptive(boolean value)
Defines whether preemptive authentication should be attempted.
voidsetCookiePolicy(int policy)
Sets the current {@link CookiePolicy cookie policy} for this HTTP state to one of the following supported policies: {@link CookiePolicy#COMPATIBILITY}, {@link CookiePolicy#NETSCAPE_DRAFT} or {@link CookiePolicy#RFC2109}.
voidsetCredentials(String realm, String host, Credentials credentials)
Sets the {@link Credentials credentials} for the given authentication realm on the given host.
voidsetCredentials(AuthScope authscope, Credentials credentials)
Sets the {@link Credentials credentials} for the given authentication scope.
voidsetProxyCredentials(String realm, String proxyHost, Credentials credentials)
Sets the {@link Credentials credentials} for the given proxy authentication realm on the given proxy host.
voidsetProxyCredentials(AuthScope authscope, Credentials credentials)
Sets the {@link Credentials proxy credentials} for the given authentication realm.
StringtoString()
Returns a string representation of this HTTP state.

Field Detail

PREEMPTIVE_DEFAULT

public static final String PREEMPTIVE_DEFAULT

Deprecated: This field and feature will be removed following HttpClient 3.0.

The default value for {@link #PREEMPTIVE_PROPERTY}.

PREEMPTIVE_PROPERTY

public static final String PREEMPTIVE_PROPERTY

Deprecated: This field and feature will be removed following HttpClient 3.0.

The boolean system property name to turn on preemptive authentication.

Constructor Detail

HttpState

public HttpState()
Default constructor.

Method Detail

addCookie

public void addCookie(Cookie cookie)
Adds an {@link Cookie 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 {@link Cookie cookie} to be added

See Also: (Cookie[])

addCookies

public void addCookies(Cookie[] cookies)
Adds an array of {@link Cookie 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 {@link Cookie cookies} to be added

See Also:

clear

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

clearCookies

public void clearCookies()
Clears all cookies.

clearCredentials

public void clearCredentials()
Clears all credentials.

clearProxyCredentials

public void clearProxyCredentials()
Clears all proxy credentials.

getCookiePolicy

public int getCookiePolicy()

Deprecated: Use {@link org.apache.commons.httpclient.params.HttpMethodParams#getCookiePolicy()}, {@link HttpMethod#getParams()}.

Returns the current {@link CookiePolicy cookie policy} for this HTTP state.

Returns: The {@link CookiePolicy cookie policy}.

getCookies

public Cookie[] getCookies()
Returns an array of {@link Cookie cookies} that this HTTP state currently contains.

Returns: an array of {@link Cookie cookies}.

See Also:

getCookies

public Cookie[] getCookies(String domain, int port, String path, boolean secure)

Deprecated: use CookieSpec#match(String, int, String, boolean, Cookie)

Returns an array of {@link Cookie cookies} in this HTTP state 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 {@link Cookie cookies}.

See Also:

getCredentials

public Credentials getCredentials(String realm, String host)

Deprecated: use #getCredentials(AuthScope)

Get the {@link Credentials credentials} for the given authentication scope on the given host. If the realm exists on host, return the coresponding credentials. If the host exists with a null realm, return the corresponding credentials. If the realm exists with a null host, return the corresponding credentials. If the realm does not exist, return the default Credentials. If there are no default credentials, return null.

Parameters: realm the authentication realm host the host the realm is on

Returns: the credentials

See Also:

getCredentials

public Credentials getCredentials(AuthScope authscope)
Get the {@link Credentials credentials} for the given authentication scope.

Parameters: authscope the {@link AuthScope authentication scope}

Returns: the credentials

Since: 3.0

See Also:

getProxyCredentials

public Credentials getProxyCredentials(String realm, String proxyHost)

Deprecated: use #getProxyCredentials(AuthScope)

Get the {@link Credentials credentials} for the proxy host with the given authentication scope. If the realm exists on host, return the coresponding credentials. If the host exists with a null realm, return the corresponding credentials. If the realm exists with a null host, return the corresponding credentials. If the realm does not exist, return the default Credentials. If there are no default credentials, return null.

Parameters: realm the authentication realm proxyHost the proxy host the realm is on

Returns: the credentials

See Also:

getProxyCredentials

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

Parameters: authscope the {@link AuthScope authentication scope}

Returns: the credentials

Since: 3.0

See Also:

isAuthenticationPreemptive

public boolean isAuthenticationPreemptive()

Deprecated: Use {@link org.apache.commons.httpclient.params.HttpClientParams#isAuthenticationPreemptive()}, {@link HttpClient#getParams()}.

Returns true if preemptive authentication should be attempted, false otherwise.

Returns: boolean flag.

purgeExpiredCookies

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

See Also:

purgeExpiredCookies

public boolean purgeExpiredCookies(Date date)
Removes all of {@link Cookie cookies} in this HTTP state that have expired by the specified {@link java.util.Date date}.

Parameters: date The {@link java.util.Date date} to compare against.

Returns: true if any cookies were purged.

See Also: purgeExpiredCookies

setAuthenticationPreemptive

public void setAuthenticationPreemptive(boolean value)

Deprecated: Use {@link org.apache.commons.httpclient.params.HttpClientParams#setAuthenticationPreemptive(boolean)}, {@link HttpClient#getParams()}.

Defines whether preemptive authentication should be attempted.

Parameters: value true if preemptive authentication should be attempted, false otherwise.

setCookiePolicy

public void setCookiePolicy(int policy)

Deprecated: Use {@link org.apache.commons.httpclient.params.HttpMethodParams#setCookiePolicy(String)}, {@link HttpMethod#getParams()}.

Sets the current {@link CookiePolicy cookie policy} for this HTTP state to one of the following supported policies: {@link CookiePolicy#COMPATIBILITY}, {@link CookiePolicy#NETSCAPE_DRAFT} or {@link CookiePolicy#RFC2109}.

Parameters: policy new {@link CookiePolicy cookie policy}

setCredentials

public void setCredentials(String realm, String host, Credentials credentials)

Deprecated: use #setCredentials(AuthScope, Credentials)

Sets the {@link Credentials credentials} for the given authentication realm on the given host. The null realm signifies default credentials for the given host, which should be used when no {@link Credentials credentials} have been explictly supplied for the challenging realm. The null host signifies default credentials, which should be used when no {@link Credentials credentials} have been explictly supplied for the challenging host. Any previous credentials for the given realm on the given host will be overwritten.

Parameters: realm the authentication realm host the host the realm belongs to credentials the authentication {@link Credentials credentials} for the given realm.

See Also: HttpState

setCredentials

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

Parameters: authscope the {@link AuthScope authentication scope} credentials the authentication {@link Credentials credentials} for the given scope.

Since: 3.0

See Also: getCredentials

setProxyCredentials

public void setProxyCredentials(String realm, String proxyHost, Credentials credentials)

Deprecated: use #setProxyCredentials(AuthScope, Credentials)

Sets the {@link Credentials credentials} for the given proxy authentication realm on the given proxy host. The null proxy realm signifies default credentials for the given proxy host, which should be used when no {@link Credentials credentials} have been explictly supplied for the challenging proxy realm. The null proxy host signifies default credentials, which should be used when no {@link Credentials credentials} have been explictly supplied for the challenging proxy host. Any previous credentials for the given proxy realm on the given proxy host will be overwritten.

Parameters: realm the authentication realm proxyHost the proxy host credentials the authentication credentials for the given realm

See Also: getProxyCredentials

setProxyCredentials

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

Parameters: authscope the {@link AuthScope authentication scope} credentials the authentication {@link Credentials credentials} for the given realm.

Since: 3.0

See Also: getProxyCredentials

toString

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

Returns: The string representation of the HTTP state.

See Also: java.lang.Object#toString()

Copyright (c) 1999-2005 - Apache Software Foundation