java.lang.Object
org.shredzone.acme4j.Session
A
Session tracks the entire communication with a CA.
To create a session instance, use its constructor. It requires the URI of the ACME
server to connect to. This can be the location of the CA's directory (via http
or https protocol), or a special URI (via acme protocol). See the
documentation about valid URIs.
Starting with version 4.0.0, a session instance can be shared between multiple threads. A session won't perform parallel HTTP connections. For high-load scenarios, it is recommended to use multiple sessions.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconnect()Returns a newConnectionto the ACME server.protected final voidfinalize()Returns the date when the current directory records will expire.Returns the date when the directory has been modified the last time.Returns the sharedHttpClientinstance for this session.Gets an Accept-Language header value that matches the current locale.Gets the current locale of this session, ornullif no special language is selected.Gets the metadata of the provider's directory.Gets the ACME serverURIof this session.booleanReturnstrueif a copy of the directory is present in a local cache.Locks the Session for the current thread, and returns aNonceHolder.Logs into an existing account.Returns the currentNetworkSettings.provider()Returns theAcmeProviderthat is used for this session.voidPurges the directory cache.resourceUrl(Resource resource) resourceUrlOptional(Resource resource) voidsetDirectoryExpires(ZonedDateTime directoryExpires) Sets the date when the current directory will expire.voidsetDirectoryLastModified(ZonedDateTime directoryLastModified) Sets the date when the directory has been modified the last time.voidSets the locale used in this session.
-
Field Details
-
directoryLastModified
-
directoryExpires
-
-
Constructor Details
-
Session
Creates a newSession.- Parameters:
serverUri- URI string of the ACME server to connect to. This is either the location of the CA's ACME directory (usinghttporhttpsprotocol), or a special URI (using theacmeprotocol).- Throws:
IllegalArgumentException- if no ACME provider was found for the server URI.
-
Session
Creates a newSession.- Parameters:
serverUri-URIof the ACME server to connect to. This is either the location of the CA's ACME directory (usinghttporhttpsprotocol), or a special URI (using theacmeprotocol).- Throws:
IllegalArgumentException- if no ACME provider was found for the server URI.
-
Session
Creates a newSessionusing the givenAcmeProvider.This constructor is only to be used for testing purposes.
- Parameters:
serverUri-URIof the ACME serverprovider-AcmeProviderto be used- Since:
- 2.8
-
-
Method Details
-
login
Logs into an existing account. -
getServerUri
Gets the ACME serverURIof this session. -
lockNonce
Locks the Session for the current thread, and returns aNonceHolder.The current thread can lock the nonce multiple times. Other threads have to wait until the current thread unlocks the nonce.
- Since:
- 4.0.0
-
getLocale
Gets the current locale of this session, ornullif no special language is selected. -
setLocale
Sets the locale used in this session. The locale is passed to the server as Accept-Language header. The server may respond with localized messages. The default is the system's language. If set tonull, any language will be accepted. -
getLanguageHeader
Gets an Accept-Language header value that matches the current locale. This method is mainly for internal use.- Since:
- 3.0.0
-
networkSettings
Returns the currentNetworkSettings.- Returns:
NetworkSettings- Since:
- 2.8
-
provider
Returns theAcmeProviderthat is used for this session.- Returns:
AcmeProvider
-
connect
Returns a newConnectionto the ACME server.- Returns:
Connection
-
getHttpClient
Returns the sharedHttpClientinstance for this session. The instance is created lazily on first access and then cached for reuse. This allows multiple connections to share the same HTTP client, improving resource utilization and connection pooling.- Returns:
- Shared
HttpClientinstance - Since:
- 4.0.0
-
resourceUrl
Gets theURLof the givenResource. This may involve connecting to the server and fetching the directory. The result is cached.- Parameters:
resource-Resourceto get theURLof- Returns:
URLof the resource- Throws:
AcmeException- if the server does not offer theResource
-
resourceUrlOptional
Gets theURLof the givenResource. This may involve connecting to the server and fetching the directory. The result is cached.- Parameters:
resource-Resourceto get theURLof- Returns:
URLof the resource, or empty if the resource is not available.- Throws:
AcmeException- Since:
- 3.0.0
-
getMetadata
Gets the metadata of the provider's directory. This may involve connecting to the server and fetching the directory. The result is cached.- Returns:
Metadata. May contain no data, but is nevernull.- Throws:
AcmeException
-
getDirectoryLastModified
Returns the date when the directory has been modified the last time.- Returns:
- The last modification date of the directory, or
nullif unknown (directory has not been read yet or did not provide this information). - Since:
- 2.10
-
setDirectoryLastModified
Sets the date when the directory has been modified the last time. Should only be invoked byAcmeProviderimplementations.- Parameters:
directoryLastModified- The last modification date of the directory, ornullif unknown (directory has not been read yet or did not provide this information).- Since:
- 2.10
-
getDirectoryExpires
Returns the date when the current directory records will expire. A fresh copy of the directory will be fetched automatically after that instant.- Returns:
- The expiration date, or
nullif the server did not provide this information. - Since:
- 2.10
-
setDirectoryExpires
Sets the date when the current directory will expire. Should only be invoked byAcmeProviderimplementations.- Parameters:
directoryExpires- Expiration date, ornullif the server did not provide this information.- Since:
- 2.10
-
hasDirectory
Returnstrueif a copy of the directory is present in a local cache. It is not evaluated if the cached copy has expired though.- Returns:
trueif a directory is available.- Since:
- 2.10
-
purgeDirectoryCache
Purges the directory cache. Makes sure that a fresh copy of the directory will be read from the CA on the next time the directory is accessed.- Since:
- 3.0.0
-
finalize
-