Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly set the request body in webhooks #51

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading