-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Currently, although coroutines are used in our microservices, HTTP requests are still handled in a blocking manner. This prevents us from fully leveraging asynchronous processing capabilities.
We can improve this by enabling proper asynchronous request handling using Jersey features such as [@Suspended](https://eclipse-ee4j.github.io/jersey.github.io/documentation/latest/async.html). However, there are some challenges with this approach.
For example, we are currently extracting tokens directly from request headers like this:
private fun extractToken(httpHeaders: HttpHeaders): String? {
val authHeader = httpHeaders.getRequestHeader(HttpHeaders.AUTHORIZATION)?.firstOrNull()
return if (authHeader != null && authHeader.startsWith("Bearer ")) {
authHeader.substring(7)
} else {
null
}
}By using the above approach, there is a possibility of inconsistent tokens when there are a lot of async requests. It may provide the token of cureent async request instead of the request we need tokens for.
Solution
Integrate Radar Jersey to enable coroutine-based asynchronous request handling. By binding the Jersey request scope to the coroutine scope, we can ensure proper request isolation, safe per-request token extraction, and truly non-blocking HTTP processing, while keeping the architecture consistent with our coroutine-based design.