Search in sources :

Example 1 with Hook

use of io.gravitee.rest.api.service.notification.Hook in project gravitee-management-rest-api by gravitee-io.

the class MessageServiceImpl method send.

private int send(Api api, MessageEntity message, Set<String> recipientsId) {
    switch(message.getChannel()) {
        case MAIL:
            Set<String> mails = getRecipientsEmails(recipientsId);
            if (!mails.isEmpty()) {
                emailService.sendAsyncEmailNotification(new EmailNotificationBuilder().to(EmailService.DEFAULT_MAIL_TO).bcc(mails.toArray(new String[0])).template(EmailNotificationBuilder.EmailTemplate.TEMPLATES_FOR_ACTION_GENERIC_MESSAGE).param("message", message.getText()).param("messageSubject", message.getTitle()).build(), GraviteeContext.getCurrentContext());
            }
            return mails.size();
        case PORTAL:
            Hook hook = api == null ? PortalHook.MESSAGE : ApiHook.MESSAGE;
            portalNotificationService.create(hook, new ArrayList<>(recipientsId), getPortalParams(api, message));
            return recipientsId.size();
        case HTTP:
            if (!httpEnabled) {
                throw new NotifierDisabledException();
            }
            String url = recipientsId.iterator().next();
            environment.getProperty("notifiers.webhook.whitelist");
            if (httpWhitelist != null && !httpWhitelist.isEmpty()) {
                // Check the provided url is allowed.
                if (httpWhitelist.stream().noneMatch(whitelistUrl -> whitelistUrl.endsWith("/") ? url.startsWith(whitelistUrl) : (url.equals(whitelistUrl) || url.startsWith(whitelistUrl + '/')))) {
                    throw new MessageUrlForbiddenException();
                }
            }
            httpClientService.request(HttpMethod.POST, url, message.getParams(), getPostMessage(api, message), Boolean.valueOf(message.isUseSystemProxy()));
            return 1;
        default:
            return 0;
    }
}
Also used : ApiHook(io.gravitee.rest.api.service.notification.ApiHook) Hook(io.gravitee.rest.api.service.notification.Hook) PortalHook(io.gravitee.rest.api.service.notification.PortalHook) EmailNotificationBuilder(io.gravitee.rest.api.service.builder.EmailNotificationBuilder)

Aggregations

EmailNotificationBuilder (io.gravitee.rest.api.service.builder.EmailNotificationBuilder)1 ApiHook (io.gravitee.rest.api.service.notification.ApiHook)1 Hook (io.gravitee.rest.api.service.notification.Hook)1 PortalHook (io.gravitee.rest.api.service.notification.PortalHook)1