Skip to content

Commit

Permalink
Merge pull request #17601 from geoand/#17597
Browse files Browse the repository at this point in the history
Preserve TCCL when using coroutines in RESTEasy Reactive
  • Loading branch information
stuartwdouglas authored Jun 2, 2021
2 parents f648d2f + 1c1177a commit 27ba1cb
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import io.vertx.core.Vertx
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.eclipse.microprofile.context.ManagedExecutor
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext
import org.jboss.resteasy.reactive.server.spi.EndpointInvoker
import org.jboss.resteasy.reactive.server.spi.ServerRestHandler
Expand All @@ -15,6 +14,9 @@ private val logger = LoggerFactory.getLogger(CoroutineInvocationHandler::class.j
class CoroutineInvocationHandler(private val invoker: EndpointInvoker,
private val coroutineScope: CoroutineScope) : ServerRestHandler {

private val originalTCCL: ClassLoader = Thread.currentThread().contextClassLoader


override fun handle(requestContext: ResteasyReactiveRequestContext) {
if (requestContext.result != null) {
return
Expand All @@ -32,6 +34,8 @@ class CoroutineInvocationHandler(private val invoker: EndpointInvoker,

requestContext.suspend()
coroutineScope.launch(context = dispatcher) {
// ensure the proper CL is not lost in dev-mode
Thread.currentThread().contextClassLoader = originalTCCL
try {
requestContext.result = invoker.invokeCoroutine(requestContext.endpointInstance, requestContext.parameters)
} catch (t: Throwable) {
Expand Down

0 comments on commit 27ba1cb

Please sign in to comment.