Interface CookieStore
- All Superinterfaces:
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.
-
Method Summary
Modifier and TypeMethodDescriptioncookies()
Returns an immutable list of all the cookies available in the cookie store.Returns an immutable list of cookies for the givenurl
.void
Deletes the givencookie
from the cookie store.int
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.void
Sets thecookie
.Methods inherited from interface com.teamdev.jxbrowser.profile.ProfileService
profile
-
Method Details
-
cookies
Returns an immutable list of all the cookies available in the cookie store. 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 in the cookie store.
- Throws:
ObjectClosedException
- when the profile is deleted or its engine is closed
-
cookies
Returns an immutable list of cookies for the givenurl
.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.
- Parameters:
url
- the URL of the resource to get cookies from- Throws:
IllegalArgumentException
- whenurl
is empty or blankObjectClosedException
- when the profile is deleted or its engine is closed
-
delete
Deletes the givencookie
from the cookie store.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.- Parameters:
cookie
- aCookie
instance to delete- Throws:
ObjectClosedException
- when the profile is deleted or its engine is closed
-
deleteAll
int deleteAll()Deletes all the cookies from the cookie store and returns the number of deleted cookies.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.- Throws:
ObjectClosedException
- when the profile is deleted or its engine is closed
-
set
Sets thecookie
.This method expects that each cookie attribute in the given
cookie
is well-formed.Please note that Chromium may modify some of the cookie attributes (such as domain or expiration time).
Important: this method makes the cookie changes in memory. To keep these changes for the persistent cookies after the application restart invoke the
persist()
method before the application exit.- Parameters:
cookie
- a cookie to set- Throws:
IllegalArgumentException
- when the cookie can't be setObjectClosedException
- when the profile is deleted or its engine is closed
-
persist
void persist()Persists all the changes performed to the cookie store.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.
- Throws:
ObjectClosedException
- when the profile is deleted or its engine is closed
-