From 3ed32449f4ba016b0f476785e941fc822513be95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Kr=C3=B6ll?= Date: Mon, 18 Oct 2021 18:32:36 +0200 Subject: [PATCH] Fix upstream encoding (#82) * added LOGGING_LEVEL var to docker-compose.yml * Changed encoding once again * Removed encoding from WebClient --- docker-compose.yml | 1 + .../classroom/services/UpstreamBBBService.kt | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 932cf13..ffe640f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,3 +17,4 @@ services: - CLASSROOM_JWT_EXPIRATION - CLASSROOM_KEYSTORE_PATH - CLASSROOM_KEYSTORE_PASS + - CLASSROOM_LOGGING_LEVEL diff --git a/src/main/kotlin/de/thm/mni/ii/classroom/services/UpstreamBBBService.kt b/src/main/kotlin/de/thm/mni/ii/classroom/services/UpstreamBBBService.kt index eb50a58..66aeb7b 100644 --- a/src/main/kotlin/de/thm/mni/ii/classroom/services/UpstreamBBBService.kt +++ b/src/main/kotlin/de/thm/mni/ii/classroom/services/UpstreamBBBService.kt @@ -16,12 +16,14 @@ import org.apache.commons.codec.digest.DigestUtils import org.slf4j.LoggerFactory import org.springframework.stereotype.Component import org.springframework.web.reactive.function.client.WebClient +import org.springframework.web.util.DefaultUriBuilderFactory import org.springframework.web.util.UriComponentsBuilder import reactor.core.publisher.Flux import reactor.core.publisher.Mono import reactor.kotlin.core.publisher.toMono import java.util.UUID + @Component class UpstreamBBBService(private val upstreamBBBProperties: UpstreamBBBProperties) { @@ -39,7 +41,7 @@ class UpstreamBBBService(private val upstreamBBBProperties: UpstreamBBBPropertie visible = conferenceInfo.visible, attendees = LinkedHashSet(), ) - ).flatMap { conference -> + ).zipWhen { conference -> val queryParams = mapOf( Pair("meetingID", conference.conferenceId), Pair("name", conference.conferenceName), @@ -51,7 +53,7 @@ class UpstreamBBBService(private val upstreamBBBProperties: UpstreamBBBPropertie Pair("meta_creatorId", userCredentials.userId) ) val request = buildApiRequest("create", queryParams) - Mono.zip(Mono.just(conference), WebClient.create(request).get().retrieve().toEntity(MessageBBB::class.java)) + buildWebClient(request).get().retrieve().toEntity(MessageBBB::class.java) }.map { (conference, responseEntity) -> if (responseEntity.body!!.returncode == "SUCCESS") conference else error(Exception(responseEntity.body?.message)) @@ -77,7 +79,7 @@ class UpstreamBBBService(private val upstreamBBBProperties: UpstreamBBBPropertie Pair("password", conference.moderatorPassword) ) val request = buildApiRequest("end", queryParams) - return WebClient.create(request).get().retrieve().toEntity(MessageBBB::class.java) + return buildWebClient(request).get().retrieve().toEntity(MessageBBB::class.java) .map { it.body!! } .map { if (it.returncode == "SUCCESS") { @@ -95,7 +97,7 @@ class UpstreamBBBService(private val upstreamBBBProperties: UpstreamBBBPropertie ): Mono> { if (conferences.isEmpty()) return Mono.empty() val request = buildApiRequest("getMeetings", mapOf()) - return WebClient.create(request).get().retrieve() + return buildWebClient(request).get().retrieve() .bodyToMono(GetMeetingsBBBResponse::class.java) .flatMapMany { getMeetings -> Flux.fromIterable(getMeetings.meetings.meetings ?: listOf()) @@ -145,4 +147,14 @@ class UpstreamBBBService(private val upstreamBBBProperties: UpstreamBBBPropertie logger.trace("Checksum calculated from: $method$query$secret") return DigestUtils.sha1Hex("$method$query$secret") } + + private fun buildWebClient(baseUrl: String): WebClient { + val factory = DefaultUriBuilderFactory(baseUrl) + factory.encodingMode = DefaultUriBuilderFactory.EncodingMode.NONE + return WebClient + .builder() + .uriBuilderFactory(factory) + .baseUrl(baseUrl) + .build() + } }