Skip to content

Commit

Permalink
fix: send webhook body correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwwinter committed Mar 12, 2024
1 parent c561364 commit 68de8dd
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.aamdigital.aambackendservice.notification.core

import com.aamdigital.aambackendservice.couchdb.core.getEmptyQueryParams
import com.aamdigital.aambackendservice.domain.DomainReference
import com.aamdigital.aambackendservice.notification.core.event.NotificationEvent
import org.slf4j.LoggerFactory
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpMethod
import org.springframework.http.MediaType
import org.springframework.web.reactive.function.BodyInserters
import org.springframework.web.reactive.function.client.WebClient
import reactor.core.publisher.Mono
import java.net.URI
Expand All @@ -23,9 +23,6 @@ class DefaultTriggerWebhookUseCase(
webhookRef = DomainReference(notificationEvent.webhookId)
)
.flatMap { webhook ->
val queryParams = getEmptyQueryParams()
queryParams.set("calculation_id", notificationEvent.calculationId)

val uri = URI(
uriParser.replacePlaceholder(
webhook.target.url,
Expand All @@ -41,12 +38,18 @@ class DefaultTriggerWebhookUseCase(
it.scheme(uri.scheme)
it.host(uri.host)
it.path(uri.path)
it.queryParams(queryParams)
it.build()
}
.headers {
it.set(HttpHeaders.AUTHORIZATION, "Token ${webhook.authentication.secret}")
}
.body(
BodyInserters.fromValue(
mapOf(
Pair("calculation_id", notificationEvent.calculationId)
)
)
)
.accept(MediaType.APPLICATION_JSON)
.exchangeToMono { response ->
response.bodyToMono(String::class.java)
Expand Down

0 comments on commit 68de8dd

Please sign in to comment.