Class AcmeJsonResource

java.lang.Object
org.shredzone.acme4j.AcmeResource
org.shredzone.acme4j.AcmeJsonResource
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Account, Authorization, Challenge, Order, RenewalInfo

public abstract class AcmeJsonResource extends AcmeResource
An extension of AcmeResource that also contains the current state of a resource as JSON document. If the current state is not present, this class takes care of fetching it from the server if necessary.
See Also:
  • Constructor Details

  • Method Details

    • getJSON

      public JSON getJSON()
      Returns the JSON representation of the resource data.

      If there is no data, update() is invoked to fetch it from the server.

      This method can be used to read proprietary data from the resources.

      Returns:
      Resource data, as JSON.
      Throws:
      AcmeLazyLoadingException - if an AcmeException occured while fetching the current state from the server.
    • setJSON

      protected void setJSON(JSON data)
      Sets the JSON representation of the resource data.
      Parameters:
      data - New JSON data, must not be null.
    • isValid

      protected boolean isValid()
      Checks if this resource is valid.
      Returns:
      true if the resource state has been loaded from the server. If false, getJSON() would implicitly call fetch() to fetch the current state from the server.
    • invalidate

      protected void invalidate()
      Invalidates the state of this resource. Enforces a fetch() when getJSON() is invoked.

      Subclasses can override this method to purge internal caches that are based on the JSON structure. Remember to invoke super.invalidate()!

    • update

      public void update() throws AcmeException
      Updates this resource, by fetching the current resource data from the server.

      Note: Prefer to use fetch() instead. It is working the same way, but returns the Retry-After instant instead of throwing an exception. This method will become deprecated in a future release.

      Throws:
      AcmeException - if the resource could not be fetched.
      AcmeRetryAfterException - the resource is still being processed, and the server returned an estimated date when the process will be completed. If you are polling for the resource to complete, you should wait for the date given in AcmeRetryAfterException.getRetryAfter(). Note that the status of the resource is updated even if this exception was thrown.
      See Also:
    • fetch

      public Optional<Instant> fetch() throws AcmeException
      Updates this resource, by fetching the current resource data from the server.
      Returns:
      An Optional estimation when the resource status will change. If you are polling for the resource to complete, you should wait for the given instant before trying again. Empty if the server did not return a "Retry-After" header.
      Throws:
      AcmeException - if the resource could not be fetched.
      Since:
      3.2.0
      See Also:
    • setRetryAfter

      protected void setRetryAfter(@Nullable Instant retryAfter)
      Sets a Retry-After instant.
      Since:
      3.2.0
    • getRetryAfter

      Gets an estimation when the resource status will change. If you are polling for the resource to complete, you should wait for the given instant before trying a status refresh.

      This instant was sent with the Retry-After header at the last update.

      Returns:
      Retry-after Instant, or empty if there was no such header.
      Since:
      3.2.0