Class WebhookSender
java.lang.Object
org.craftercms.commons.notification.NotificationSender<NotificationSender<?>.NotificationMessage>
org.craftercms.commons.notification.impl.WebhookSender
- All Implemented Interfaces:
AutoCloseable
NotificationSender implementation that sends a webhook notification.
The payload is available to the template as an object with the key "payload", and serialized as JSON with the key "payloadJson".
A WebhookSender instance can be configured with the following Configuration properties:
- url: The URL to send the webhook notification to.
- method: The HTTP method to use. Default is
post. - contentType: The content type of the request body. Default is
application/json
NotificationSender for the common properties available to all notification senders.-
Nested Class Summary
Nested classes/interfaces inherited from class org.craftercms.commons.notification.NotificationSender
NotificationSender.NotificationMessage -
Field Summary
Fields inherited from class org.craftercms.commons.notification.NotificationSender
DATETIME_FORMATTER_MODEL_KEY, DATETIME_PATTERN_CONFIG_KEY, dateTimeFormatter, DURATION_FORMATTER_MODEL_KEY, DURATION_PATTERN_CONFIG_KEY, durationFormatter, freeMarkerConfig, objectMapper, PAYLOAD_MODEL_KEY, templateEncoding, templatePrefix, templateSuffix -
Constructor Summary
ConstructorsConstructorDescriptionWebhookSender(freemarker.template.Configuration freeMarkerConfig, com.fasterxml.jackson.databind.ObjectMapper objectMapper, String dateTimePattern, String durationPattern) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()doCreateMessage(String templateName, Object payload) Creates the notification message to send.protected voiddoNotify(NotificationSender<?>.NotificationMessage message) Sends the notification message.voidinit(org.apache.commons.configuration2.Configuration config) voidsetContentType(String contentType) voidvoidsetTimeout(int timeout) voidprotected voidprotected voidMethods inherited from class org.craftercms.commons.notification.NotificationSender
createMessage, initProperties, processTemplate, sendMessage, setTemplateEncoding, setTemplatePrefix, setTemplateSuffix
-
Constructor Details
-
WebhookSender
@ConstructorProperties({"freeMarkerConfig","objectMapper","dateTimePattern","durationPattern"}) public WebhookSender(freemarker.template.Configuration freeMarkerConfig, com.fasterxml.jackson.databind.ObjectMapper objectMapper, String dateTimePattern, String durationPattern)
-
-
Method Details
-
init
public void init(org.apache.commons.configuration2.Configuration config) throws ConfigurationException - Overrides:
initin classNotificationSender<NotificationSender<?>.NotificationMessage>- Throws:
ConfigurationException
-
validateUrl
- Throws:
ConfigurationException
-
validateMethod
- Throws:
ConfigurationException
-
close
- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classNotificationSender<NotificationSender<?>.NotificationMessage>- Throws:
IOException
-
doCreateMessage
protected NotificationSender<NotificationSender<?>.NotificationMessage>.NotificationMessage doCreateMessage(String templateName, Object payload) Description copied from class:NotificationSenderCreates the notification message to send.- Specified by:
doCreateMessagein classNotificationSender<NotificationSender<?>.NotificationMessage>- Parameters:
templateName- the name of the template to use for the notificationpayload- the payload to include in the notification- Returns:
- the notification message
-
doNotify
protected void doNotify(NotificationSender<?>.NotificationMessage message) throws NotificationException Description copied from class:NotificationSenderSends the notification message.- Specified by:
doNotifyin classNotificationSender<NotificationSender<?>.NotificationMessage>- Parameters:
message- the notification message- Throws:
NotificationException- if an error occurs while sending the notification
-
setContentType
-
setMethod
- Throws:
ConfigurationException
-
setUrl
- Throws:
ConfigurationException
-
setTimeout
public void setTimeout(int timeout)
-