java.lang.Object
org.shredzone.acme4j.connector.DefaultConnection
- All Implemented Interfaces:
AutoCloseable,Connection
Default implementation of
Connection.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultConnection(HttpConnector httpConnector) Creates a newDefaultConnection. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes theConnection, releasing all resources.Returns the expiration date of the resource, if present.Returns the content of the last-modified header, if present.Gets one or more relation links from the header.Gets a location from theLocationheader.getNonce()Gets the nonce from the nonce header.voidhandleRetryAfter(String message) Throws anAcmeRetryAfterExceptionif the last status was HTTP Accepted and a Retry-After header was received.Reads a certificate and its issuers.Reads a server response as JSON data.voidresetNonce(Session session) Resets the session nonce, by fetching a new one.intsendCertificateRequest(URL url, Login login) Sends a signed POST-as-GET request for a certificate resource.protected intsendRequest(URL url, Session session, String accept, ZonedDateTime ifModifiedSince) Sends an unsigned GET request.intsendRequest(URL url, Session session, ZonedDateTime ifModifiedSince) Sends a simple GET request.intsendSignedPostAsGetRequest(URL url, Login login) Sends a signed POST-as-GET request.intsendSignedRequest(URL url, JSONBuilder claims, Login login) Sends a signed POST request.intsendSignedRequest(URL url, JSONBuilder claims, Session session, KeyPair keypair) Sends a signed POST request.protected intsendSignedRequest(URL url, JSONBuilder claims, Session session, KeyPair keypair, URL accountLocation, String accept) Sends a signed POST request.
-
Field Details
-
httpConnector
-
conn
-
-
Constructor Details
-
DefaultConnection
Creates a newDefaultConnection.- Parameters:
httpConnector-HttpConnectorto be used for HTTP connections
-
-
Method Details
-
resetNonce
Description copied from interface:ConnectionResets the session nonce, by fetching a new one.- Specified by:
resetNoncein interfaceConnection- Parameters:
session-Sessioninstance to fetch a nonce for- Throws:
AcmeException
-
sendRequest
public int sendRequest(URL url, Session session, @Nullable ZonedDateTime ifModifiedSince) throws AcmeException Description copied from interface:ConnectionSends a simple GET request.If the response code was not
HttpURLConnection.HTTP_OK, anAcmeExceptionmatching the error is raised.- Specified by:
sendRequestin interfaceConnection- Parameters:
url-URLto send the request to.session-Sessioninstance to be used for trackingifModifiedSince-ZonedDateTimeto be sent as "If-Modified-Since" header, ornullif this header is not to be used- Returns:
- HTTP status that was returned
- Throws:
AcmeException
-
sendCertificateRequest
Description copied from interface:ConnectionSends a signed POST-as-GET request for a certificate resource. Requires aLoginfor the session andKeyPair. TheLoginaccount location is sent in a "kid" protected header.If the server does not return a 200 class status code, an
AcmeExceptionis raised matching the error.- Specified by:
sendCertificateRequestin interfaceConnection- Parameters:
url-URLto send the request to.login-Logininstance to be used for signing and tracking.- Returns:
- HTTP 200 class status that was returned
- Throws:
AcmeException
-
sendSignedPostAsGetRequest
Description copied from interface:ConnectionSends a signed POST-as-GET request. Requires aLoginfor the session andKeyPair. TheLoginaccount location is sent in a "kid" protected header.If the server does not return a 200 class status code, an
AcmeExceptionis raised matching the error.- Specified by:
sendSignedPostAsGetRequestin interfaceConnection- Parameters:
url-URLto send the request to.login-Logininstance to be used for signing and tracking.- Returns:
- HTTP 200 class status that was returned
- Throws:
AcmeException
-
sendSignedRequest
Description copied from interface:ConnectionSends a signed POST request. Requires aLoginfor the session andKeyPair. TheLoginaccount location is sent in a "kid" protected header.If the server does not return a 200 class status code, an
AcmeExceptionis raised matching the error.- Specified by:
sendSignedRequestin interfaceConnection- Parameters:
url-URLto send the request to.claims-JSONBuildercontaining claims.login-Logininstance to be used for signing and tracking.- Returns:
- HTTP 200 class status that was returned
- Throws:
AcmeException
-
sendSignedRequest
public int sendSignedRequest(URL url, JSONBuilder claims, Session session, KeyPair keypair) throws AcmeException Description copied from interface:ConnectionSends a signed POST request. Only requires aSession. TheKeyPairis sent in a "jwk" protected header field.If the server does not return a 200 class status code, an
AcmeExceptionis raised matching the error.- Specified by:
sendSignedRequestin interfaceConnection- Parameters:
url-URLto send the request to.claims-JSONBuildercontaining claims.session-Sessioninstance to be used for tracking.keypair-KeyPairto be used for signing.- Returns:
- HTTP 200 class status that was returned
- Throws:
AcmeException
-
readJsonResponse
Description copied from interface:ConnectionReads a server response as JSON data.- Specified by:
readJsonResponsein interfaceConnection- Returns:
- The JSON response.
- Throws:
AcmeException
-
readCertificates
Description copied from interface:ConnectionReads a certificate and its issuers.- Specified by:
readCertificatesin interfaceConnection- Returns:
- List of X.509 certificate and chain that was read.
- Throws:
AcmeException
-
handleRetryAfter
Description copied from interface:ConnectionThrows anAcmeRetryAfterExceptionif the last status was HTTP Accepted and a Retry-After header was received.- Specified by:
handleRetryAfterin interfaceConnection- Parameters:
message- Message to be sent along with theAcmeRetryAfterException- Throws:
AcmeException
-
getNonce
Description copied from interface:ConnectionGets the nonce from the nonce header.- Specified by:
getNoncein interfaceConnection- Returns:
- Base64 encoded nonce, or
nullif no nonce header was set
-
getLocation
Description copied from interface:ConnectionGets a location from theLocationheader.Relative links are resolved against the last request's URL.
- Specified by:
getLocationin interfaceConnection- Returns:
- Location
URL, ornullif no Location header was set
-
getLastModified
Description copied from interface:ConnectionReturns the content of the last-modified header, if present.- Specified by:
getLastModifiedin interfaceConnection- Returns:
- Date in the Last-Modified header, or empty if the server did not provide this information.
-
getExpiration
Description copied from interface:ConnectionReturns the expiration date of the resource, if present.- Specified by:
getExpirationin interfaceConnection- Returns:
- Expiration date, either from the Cache-Control or Expires header. If empty, the server did not provide an expiration date, or forbid caching.
-
getLinks
Description copied from interface:ConnectionGets one or more relation links from the header. The result is expected to be an URL.Relative links are resolved against the last request's URL.
- Specified by:
getLinksin interfaceConnection- Parameters:
relation- Link relation- Returns:
- Collection of links. Empty if there was no such relation.
-
close
Description copied from interface:ConnectionCloses theConnection, releasing all resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection
-
sendRequest
protected int sendRequest(URL url, Session session, String accept, @Nullable ZonedDateTime ifModifiedSince) throws AcmeException Sends an unsigned GET request.- Parameters:
url-URLto send the request to.session-Sessioninstance to be used for signing and trackingaccept- Accept headerifModifiedSince- Set an If-Modified-Since header with the given date. If set, an NOT_MODIFIED response is accepted as valid.- Returns:
- HTTP 200 class status that was returned
- Throws:
AcmeException
-
sendSignedRequest
protected int sendSignedRequest(URL url, @Nullable JSONBuilder claims, Session session, KeyPair keypair, @Nullable URL accountLocation, String accept) throws AcmeException Sends a signed POST request.- Parameters:
url-URLto send the request to.claims-JSONBuildercontaining claims.nullfor POST-as-GET request.session-Sessioninstance to be used for signing and trackingkeypair-KeyPairto be used for signingaccountLocation- If set, the account location is set as "kid" header. Ifnull, the public key is set as "jwk" header.accept- Accept header- Returns:
- HTTP 200 class status that was returned
- Throws:
AcmeException
-