public interface CookieStore extends ProfileService
Cookies can be stored in the process memory (session cookies) or on the file system (persistent cookies). The service provides access to both the session and persistent cookies.
The persistent cookies are stored in the user data directory. You can configure the user data
directory path via the
EngineOptions.Builder.userDataDir(Path)
method. For example:
Engine engine = Engine.newInstance(EngineOptions.newBuilder(renderingMode) .userDataDir(Paths.get("/Users/MyApp/Data")) .build());
All the changes to the cookie store are made in memory, so when you restart the application
you will not see the changes you made with the persistent cookies if you do not invoke the
persist()
method before application exit.
Modifier and Type | Method and Description |
---|---|
java.util.List<Cookie> |
cookies()
Returns an immutable list of all the cookies available in the cookie store.
|
java.util.List<Cookie> |
cookies(java.lang.String url)
Returns an immutable list of all the cookies available in the cookie store and associated
with the given
url . |
boolean |
delete(Cookie cookie)
Deletes the given
cookie from the cookie store and returns true if the cookie
store contained the given cookie and it was deleted successfully. |
int |
deleteAll()
Deletes all the cookies from the cookie store and returns the number of deleted cookies.
|
void |
persist()
Persists all the changes performed to the cookie store.
|
boolean |
put(java.lang.String url,
Cookie cookie)
Sets the given
cookie and associates it with the given url . |
profile
java.util.List<Cookie> cookies()
The returned cookies are ordered by longest path, then by earliest creation time. Can be empty if there are no cookies in the cookie store.
java.lang.IllegalStateException
- when the profile is deleted or its engine is closedjava.util.List<Cookie> cookies(java.lang.String url)
url
. The list includes both the persistent and session cookies.
The returned cookies are ordered by longest path, then by earliest creation time. Can be empty if there are no cookies associated with the given URL in the cookie store.
url
- the URL of the resource to get cookies fromjava.lang.IllegalArgumentException
- when url
is empty or blankjava.lang.IllegalStateException
- when the profile is deleted or its engine is closedboolean delete(Cookie cookie)
cookie
from the cookie store and returns true
if the cookie
store contained the given cookie
and it was deleted successfully.
Important: this method makes the cookie changes in memory. To keep these changes
for the persistent cookies after application restart you must invoke the persist()
method before application exit.
cookie
- a Cookie
instance to deletejava.lang.IllegalStateException
- when the profile is deleted or its engine is closedint deleteAll()
Important: this method makes the cookie changes in memory. To keep these changes
for persistent cookies after application restart you must invoke the persist()
method before application exit.
java.lang.IllegalStateException
- when the profile is deleted or its engine is closedboolean put(java.lang.String url, Cookie cookie)
cookie
and associates it with the given url
.
This method expects that each cookie attribute in the given cookie
is
well-formed. It will check for disallowed characters (e.g. the ';' character is disallowed
within the cookie value attribute) and return false
without setting the cookie if
such characters are found.
If the given url
and the cookie domain are different, the cookie will not be set
and the method returns false. So, make sure that the given url
and the cookie domain
are the same domains. For example, for the https://www.teamdev.com
address the cookie
domain must be ".teamdev.com"
.
If you set the cookie successfully and the method returns true
and you decide to
find the cookie
in the list of all cookies, please note that the cookie store can
modify some cookie attributes such as domain or expiration time programmatically.
Important: this method makes the cookie changes in memory. To keep these changes
for the persistent cookies after application restart you must invoke the persist()
method before application exit.
url
- a string that represents a valid URL which host will be associated with a new
cookie instance. The url string must be valid and has the following format:
http[https]://host.
For example, http://www.google.com, https://www.gmail.com, etccookie
- a cookie to settrue
when the cookie was inserted successfully. If the passed cookie is
valid, but already expired, the method returns true, but the cookie will not be in
the list of all cookiesjava.lang.IllegalArgumentException
- when url
is empty or blankjava.lang.IllegalStateException
- when the profile is deleted or its engine is closedvoid persist()
By default, all the changes to the cookie store are made in memory, so when you restart the application you will not see the changes you made with persistent cookies if you do not invoke this method before application exit.
This method can be invoked after every change you made to the cookie store.
java.lang.IllegalStateException
- when the profile is deleted or its engine is closed