From 1c1177ae8ae0ce7f3197691b183f97e5ef674623 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 1 Jun 2021 16:26:54 +0300 Subject: [PATCH] Preserve TCCL when using coroutines in RESTEasy Reactive Fixes: #17597 --- .../server/runtime/kotlin/CoroutineInvocationHandler.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/kotlin/src/main/kotlin/org/jboss/resteasy/reactive/server/runtime/kotlin/CoroutineInvocationHandler.kt b/extensions/resteasy-reactive/quarkus-resteasy-reactive/kotlin/src/main/kotlin/org/jboss/resteasy/reactive/server/runtime/kotlin/CoroutineInvocationHandler.kt index b68f2dde588c6..4cf40d8098dae 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/kotlin/src/main/kotlin/org/jboss/resteasy/reactive/server/runtime/kotlin/CoroutineInvocationHandler.kt +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/kotlin/src/main/kotlin/org/jboss/resteasy/reactive/server/runtime/kotlin/CoroutineInvocationHandler.kt @@ -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 @@ -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 @@ -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) {