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 upstream encoding #82

Merged
merged 3 commits into from
Oct 18, 2021
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
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()
}
}