Class WebhookHandlerUtility


  • public class WebhookHandlerUtility
    extends Object
    Class which provides various utilities to assist in handling webhook payloads received from Terra.
    • Constructor Detail

      • WebhookHandlerUtility

        public WebhookHandlerUtility​(String secret)
        Constructor for this class
        Parameters:
        secret - the value of your webhook signing secret - found on the developer dashboard
    • Method Detail

      • verifySignature

        public boolean verifySignature​(String signatureHeader,
                                       String requestBody)
        Verify the signature of the incoming webhook to ensure that it was sent by Terra.
        Parameters:
        signatureHeader - the value of the terra-signature header sent with the webhook request
        requestBody - the raw string request body sent with the webhook request
        Returns:
        boolean indicating whether the signature could be verified successfully
        Throws:
        IllegalStateException - if your jdk installation is missing the HmacSHA256 algorithm
        IllegalStateException - if your secret key is invalid
      • parseAndDispatchWebhookPayload

        public void parseAndDispatchWebhookPayload​(String rawPayload)
        Parses the raw payload sent with a webhook request into a TerraWebhookPayload and then dispatches it to the correct handler method for its event type. If no handler exists for the event type then it will be dispatched to the default handler, or discarded if no default handler exists.
        Parameters:
        rawPayload - the raw string payload to parse and dispatch to a handler
        See Also:
        addEventHandler(String, Consumer), addDefaultEventHandler(Consumer)
      • addDefaultEventHandler

        public WebhookHandlerUtility addDefaultEventHandler​(Consumer<TerraWebhookPayload> consumer)
        Registers a handler method that will be called if no other handler method can be resolved for a received event type.
        Parameters:
        consumer - the handler method to call with previously unhandled events
        Returns:
        this instance, for method chaining