CORDA-2344 Set contextClassloader on the flow threads. (#4437)

* CORDA-2344 Set contextClassloader on the flow threads.

* CORDA-2344 Set contextClassloader on the flow threads.
This commit is contained in:
Tudor Malene 2018-12-20 15:04:16 +00:00 committed by GitHub
parent 3efbad34cc
commit 3c13c07c09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -22,7 +22,7 @@ import java.util.concurrent.ConcurrentHashMap
/**
* Cordapp provider and store. For querying CorDapps for their attachment and vice versa.
*/
open class CordappProviderImpl(private val cordappLoader: CordappLoader,
open class CordappProviderImpl(val cordappLoader: CordappLoader,
private val cordappConfigProvider: CordappConfigProvider,
private val attachmentStorage: AttachmentStorage) : SingletonSerializeAsToken(), CordappProviderInternal {
companion object {

View File

@ -18,6 +18,7 @@ import net.corda.core.utilities.ProgressTracker
import net.corda.core.utilities.Try
import net.corda.core.utilities.debug
import net.corda.core.utilities.trace
import net.corda.node.internal.cordapp.CordappProviderImpl
import net.corda.node.services.api.FlowAppAuditEvent
import net.corda.node.services.api.FlowPermissionAuditEvent
import net.corda.node.services.api.ServiceHubInternal
@ -219,6 +220,11 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
logger.debug { "Calling flow: $logic" }
val startTime = System.nanoTime()
val resultOrError = try {
// This sets the Cordapp classloader on the contextClassLoader of the current thread.
// Needed because in previous versions of the finance app we used Thread.contextClassLoader to resolve services defined in cordapps.
Thread.currentThread().contextClassLoader = (serviceHub.cordappProvider as CordappProviderImpl).cordappLoader.appClassLoader
val result = logic.call()
suspend(FlowIORequest.WaitForSessionConfirmations, maySkipCheckpoint = true)
Try.Success(result)