-
Notifications
You must be signed in to change notification settings - Fork 0
Description
In Kafka, AnyCodec requires an explicit class loader to be provided, hence this trick:
pew/pew/src/main/scala/com/workflowfm/pew/mongodb/bson/AnyCodec.scala
Lines 23 to 26 in 4a5bfae
| // Jev, unset the `ClassLoader` to ensure the default is used. | |
| def classForName(name: String): Class[_] = ClassLoaderUtil.withClassLoader(null) { | |
| Class.forName(name) | |
| } |
See also:
- https://stackoverflow.com/questions/37363119/kafka-producer-org-apache-kafka-common-serialization-stringserializer-could-no
- https://stackoverflow.com/questions/57574901/kafka-java-client-classloader-doesnt-find-sasl-scram-login-class
This requires this switch using setContextClassLoader:
pew/pew/src/main/scala/com/workflowfm/pew/util/ClassLoaderUtil.scala
Lines 14 to 20 in 4a5bfae
| val pushedClassLoader = Thread.currentThread().getContextClassLoader | |
| try { | |
| Thread.currentThread().setContextClassLoader(tmpClassLoader) | |
| fnWrapped | |
| } finally { | |
| Thread.currentThread().setContextClassLoader(pushedClassLoader) | |
| } |
This fails in pew-mongo because everything runs on the default ForkJoinPool which produces InnocuousThreads which do not allow you to setContextClassLoader leading to a security exception.
We want an easy way to bypass this loader switch, perhaps as simpke as a flag in AnyCodec and the codec provider.
Perhaps later on after #55 is implemented we will have a more elegant solution available.