Skip to content

Commit

Permalink
fix: correctly set the request body in webhooks (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwwinter authored Nov 15, 2024
1 parent e644e2a commit 7d21b6c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7d21b6c

Please sign in to comment.