public class CookieManager extends Object implements Serializable
WebClient
. This class is thread-safe.
You can disable Cookies by calling setCookiesEnabled(false). The
CookieManager itself takes care of this and ignores all cookie request if
disabled. If you override this your methods have to do the same.Constructor and Description |
---|
CookieManager()
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addCookie(Cookie cookie)
Adds the specified cookie.
|
CookieOrigin |
buildCookieOrigin(URL url)
Helper that builds a CookieOrigin.
|
void |
clearCookies()
Removes all cookies.
|
boolean |
clearExpired(Date date)
Clears all cookies that have expired before supplied date.
|
Cookie |
getCookie(String name)
Returns the currently configured cookie with the specified name, or
null if one does not exist. |
Set<Cookie> |
getCookies()
Returns the currently configured cookies, in an unmodifiable set.
|
protected int |
getPort(URL url)
Gets the port of the URL.
|
boolean |
isCookiesEnabled()
Returns
true if cookies are enabled. |
void |
removeCookie(Cookie cookie)
Removes the specified cookie.
|
URL |
replaceForCookieIfNecessary(URL url)
CookieOrigin doesn't like empty hosts and negative ports,
but these things happen if we're dealing with a local file. |
void |
setCookiesEnabled(boolean enabled)
Enables/disables cookie support.
|
public void setCookiesEnabled(boolean enabled)
enabled
- true
to enable cookie support, false
otherwisepublic boolean isCookiesEnabled()
true
if cookies are enabled. Cookies are enabled by default.true
if cookies are enabled, false
otherwisepublic Set<Cookie> getCookies()
public CookieOrigin buildCookieOrigin(URL url)
url
- the url to be usedpublic boolean clearExpired(Date date)
date
- the date to use for comparison when clearing expired cookiesprotected int getPort(URL url)
url
- the URLpublic URL replaceForCookieIfNecessary(URL url)
CookieOrigin
doesn't like empty hosts and negative ports,
but these things happen if we're dealing with a local file.
This method allows us to work around this limitation in HttpClient by feeding it a bogus host and port.url
- the URL to replace if necessarypublic Cookie getCookie(String name)
null
if one does not exist.
If disabled, this returns null.name
- the name of the cookie to returnnull
if one does not existpublic void addCookie(Cookie cookie)
cookie
- the cookie to addpublic void removeCookie(Cookie cookie)
cookie
- the cookie to removepublic void clearCookies()
Copyright © 2002–2020 Gargoyle Software Inc.. All rights reserved.