Skip to content

Commit

Permalink
Fix upstream encoding (#82)
Browse files Browse the repository at this point in the history
* added LOGGING_LEVEL var to docker-compose.yml

* Changed encoding once again

* Removed encoding from WebClient
  • Loading branch information
snicki13 authored Oct 18, 2021
1 parent 585d2de commit 3ed3244
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ services:
- CLASSROOM_JWT_EXPIRATION
- CLASSROOM_KEYSTORE_PATH
- CLASSROOM_KEYSTORE_PASS
- CLASSROOM_LOGGING_LEVEL
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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),
Expand All @@ -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))
Expand All @@ -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") {
Expand All @@ -95,7 +97,7 @@ class UpstreamBBBService(private val upstreamBBBProperties: UpstreamBBBPropertie
): Mono<List<Conference>> {
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())
Expand Down Expand Up @@ -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()
}
}

0 comments on commit 3ed3244

Please sign in to comment.