Interface Connection

All Superinterfaces:
java.lang.AutoCloseable
All Known Implementing Classes:
DefaultConnection

public interface Connection
extends java.lang.AutoCloseable
Connects to the ACME server and offers different methods for invoking the API.
  • Method Summary

    Modifier and Type Method Description
    void close()
    Closes the Connection, releasing all resources.
    java.util.Optional<java.time.ZonedDateTime> getExpiration()
    Returns the expiration date of the resource, if present.
    java.util.Optional<java.time.ZonedDateTime> getLastModified()
    Returns the content of the last-modified header, if present.
    java.util.Collection<java.net.URL> getLinks​(java.lang.String relation)
    Gets one or more relation links from the header.
    java.net.URL getLocation()
    Gets a location from the Location header.
    java.lang.String getNonce()
    Gets the nonce from the nonce header.
    void handleRetryAfter​(java.lang.String message)
    Throws an AcmeRetryAfterException if the last status was HTTP Accepted and a Retry-After header was received.
    java.util.List<java.security.cert.X509Certificate> readCertificates()
    Reads a certificate and its issuers.
    JSON readJsonResponse()
    Reads a server response as JSON data.
    void resetNonce​(Session session)
    Resets the session nonce, by fetching a new one.
    int sendCertificateRequest​(java.net.URL url, Login login)
    Sends a signed POST-as-GET request for a certificate resource.
    int sendRequest​(java.net.URL url, Session session, java.time.ZonedDateTime ifModifiedSince)
    Sends a simple GET request.
    int sendSignedPostAsGetRequest​(java.net.URL url, Login login)
    Sends a signed POST-as-GET request.
    int sendSignedRequest​(java.net.URL url, JSONBuilder claims, Login login)
    Sends a signed POST request.
    int sendSignedRequest​(java.net.URL url, JSONBuilder claims, Session session, java.security.KeyPair keypair)
    Sends a signed POST request.
  • Method Details

    • resetNonce

      void resetNonce​(Session session) throws AcmeException
      Resets the session nonce, by fetching a new one.
      Parameters:
      session - Session instance to fetch a nonce for
      Throws:
      AcmeException
    • sendRequest

      int sendRequest​(java.net.URL url, Session session, @Nullable java.time.ZonedDateTime ifModifiedSince) throws AcmeException
      Sends a simple GET request.

      If the response code was not HttpURLConnection.HTTP_OK, an AcmeException matching the error is raised.

      Parameters:
      url - URL to send the request to.
      session - Session instance to be used for tracking
      ifModifiedSince - ZonedDateTime to be sent as "If-Modified-Since" header, or null if this header is not to be used
      Returns:
      HTTP status that was returned
      Throws:
      AcmeException
    • sendCertificateRequest

      int sendCertificateRequest​(java.net.URL url, Login login) throws AcmeException
      Sends a signed POST-as-GET request for a certificate resource. Requires a Login for the session and KeyPair. The Login account location is sent in a "kid" protected header.

      If the server does not return a 200 class status code, an AcmeException is raised matching the error.

      Parameters:
      url - URL to send the request to.
      login - Login instance to be used for signing and tracking.
      Returns:
      HTTP 200 class status that was returned
      Throws:
      AcmeException
    • sendSignedPostAsGetRequest

      int sendSignedPostAsGetRequest​(java.net.URL url, Login login) throws AcmeException
      Sends a signed POST-as-GET request. Requires a Login for the session and KeyPair. The Login account location is sent in a "kid" protected header.

      If the server does not return a 200 class status code, an AcmeException is raised matching the error.

      Parameters:
      url - URL to send the request to.
      login - Login instance to be used for signing and tracking.
      Returns:
      HTTP 200 class status that was returned
      Throws:
      AcmeException
    • sendSignedRequest

      int sendSignedRequest​(java.net.URL url, JSONBuilder claims, Login login) throws AcmeException
      Sends a signed POST request. Requires a Login for the session and KeyPair. The Login account location is sent in a "kid" protected header.

      If the server does not return a 200 class status code, an AcmeException is raised matching the error.

      Parameters:
      url - URL to send the request to.
      claims - JSONBuilder containing claims.
      login - Login instance to be used for signing and tracking.
      Returns:
      HTTP 200 class status that was returned
      Throws:
      AcmeException
    • sendSignedRequest

      int sendSignedRequest​(java.net.URL url, JSONBuilder claims, Session session, java.security.KeyPair keypair) throws AcmeException
      Sends a signed POST request. Only requires a Session. The KeyPair is sent in a "jwk" protected header field.

      If the server does not return a 200 class status code, an AcmeException is raised matching the error.

      Parameters:
      url - URL to send the request to.
      claims - JSONBuilder containing claims.
      session - Session instance to be used for tracking.
      keypair - KeyPair to be used for signing.
      Returns:
      HTTP 200 class status that was returned
      Throws:
      AcmeException
    • readJsonResponse

      Reads a server response as JSON data.
      Returns:
      The JSON response.
      Throws:
      AcmeProtocolException - if the JSON response was empty.
      AcmeException
    • readCertificates

      java.util.List<java.security.cert.X509Certificate> readCertificates() throws AcmeException
      Reads a certificate and its issuers.
      Returns:
      List of X.509 certificate and chain that was read.
      Throws:
      AcmeException
    • handleRetryAfter

      void handleRetryAfter​(java.lang.String message) throws AcmeException
      Throws an AcmeRetryAfterException if the last status was HTTP Accepted and a Retry-After header was received.
      Parameters:
      message - Message to be sent along with the AcmeRetryAfterException
      Throws:
      AcmeException
    • getNonce

      @Nullable java.lang.String getNonce()
      Gets the nonce from the nonce header.
      Returns:
      Base64 encoded nonce, or null if no nonce header was set
    • getLocation

      @Nullable java.net.URL getLocation()
      Gets a location from the Location header.

      Relative links are resolved against the last request's URL.

      Returns:
      Location URL, or null if no Location header was set
    • getLastModified

      java.util.Optional<java.time.ZonedDateTime> getLastModified()
      Returns the content of the last-modified header, if present.
      Returns:
      Date in the Last-Modified header, or empty if the server did not provide this information.
      Since:
      2.10
    • getExpiration

      java.util.Optional<java.time.ZonedDateTime> getExpiration()
      Returns the expiration date of the resource, if present.
      Returns:
      Expiration date, either from the Cache-Control or Expires header. If empty, the server did not provide an expiration date, or forbid caching.
      Since:
      2.10
    • getLinks

      java.util.Collection<java.net.URL> getLinks​(java.lang.String relation)
      Gets 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.

      Parameters:
      relation - Link relation
      Returns:
      Collection of links. Empty if there was no such relation.
    • close

      void close()
      Closes the Connection, releasing all resources.
      Specified by:
      close in interface java.lang.AutoCloseable