From 50628a5416f6f03a2d14893519a3d816e9d41db7 Mon Sep 17 00:00:00 2001 From: Tom Winter Date: Fri, 15 Nov 2024 17:41:35 +0100 Subject: [PATCH] fix: correctly set the request body in webhooks --- .../notification/core/DefaultTriggerWebhookUseCase.kt | 9 +++++++-- .../notification/di/NotificationConfiguration.kt | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/application/aam-backend-service/src/main/kotlin/com/aamdigital/aambackendservice/reporting/notification/core/DefaultTriggerWebhookUseCase.kt b/application/aam-backend-service/src/main/kotlin/com/aamdigital/aambackendservice/reporting/notification/core/DefaultTriggerWebhookUseCase.kt index 0684f7c..a12b164 100644 --- a/application/aam-backend-service/src/main/kotlin/com/aamdigital/aambackendservice/reporting/notification/core/DefaultTriggerWebhookUseCase.kt +++ b/application/aam-backend-service/src/main/kotlin/com/aamdigital/aambackendservice/reporting/notification/core/DefaultTriggerWebhookUseCase.kt @@ -2,6 +2,7 @@ package com.aamdigital.aambackendservice.reporting.notification.core import com.aamdigital.aambackendservice.domain.DomainReference import com.aamdigital.aambackendservice.reporting.domain.event.NotificationEvent +import com.fasterxml.jackson.databind.ObjectMapper import org.slf4j.LoggerFactory import org.springframework.http.HttpHeaders import org.springframework.http.HttpMethod @@ -16,6 +17,7 @@ class DefaultTriggerWebhookUseCase( private val notificationStorage: NotificationStorage, private val httpClient: RestClient, private val uriParser: UriParser, + private val objectMapper: ObjectMapper, ) : TriggerWebhookUseCase { private val logger = LoggerFactory.getLogger(javaClass) @@ -44,9 +46,12 @@ class DefaultTriggerWebhookUseCase( .headers { it.set(HttpHeaders.AUTHORIZATION, "Token ${webhook.authentication.secret}") } + .contentType(MediaType.APPLICATION_JSON) .body( - mapOf( - Pair("calculation_id", notificationEvent.calculationId) + objectMapper.writeValueAsString( + hashMapOf( + "calculation_id" to notificationEvent.calculationId + ) ) ) .accept(MediaType.APPLICATION_JSON) diff --git a/application/aam-backend-service/src/main/kotlin/com/aamdigital/aambackendservice/reporting/notification/di/NotificationConfiguration.kt b/application/aam-backend-service/src/main/kotlin/com/aamdigital/aambackendservice/reporting/notification/di/NotificationConfiguration.kt index 064a955..76ef9b8 100644 --- a/application/aam-backend-service/src/main/kotlin/com/aamdigital/aambackendservice/reporting/notification/di/NotificationConfiguration.kt +++ b/application/aam-backend-service/src/main/kotlin/com/aamdigital/aambackendservice/reporting/notification/di/NotificationConfiguration.kt @@ -13,6 +13,7 @@ import com.aamdigital.aambackendservice.reporting.notification.storage.DefaultNo import com.aamdigital.aambackendservice.reporting.notification.storage.WebhookRepository import com.aamdigital.aambackendservice.reporting.reportcalculation.core.CreateReportCalculationUseCase import com.aamdigital.aambackendservice.reporting.reportcalculation.core.ReportCalculationStorage +import com.fasterxml.jackson.databind.ObjectMapper import org.springframework.beans.factory.annotation.Qualifier import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @@ -43,7 +44,8 @@ class NotificationConfiguration { notificationStorage: NotificationStorage, @Qualifier("webhook-web-client") restClient: RestClient, uriParser: UriParser, - ): TriggerWebhookUseCase = DefaultTriggerWebhookUseCase(notificationStorage, restClient, uriParser) + objectMapper: ObjectMapper + ): TriggerWebhookUseCase = DefaultTriggerWebhookUseCase(notificationStorage, restClient, uriParser, objectMapper) @Bean(name = ["webhook-web-client"]) fun webhookWebClient(): RestClient {