This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit b5833d531e55eb627f88a4b0edeecc15b19e7126 Author: Peter Palaga <[email protected]> AuthorDate: Thu Jun 3 21:29:17 2021 +0200 Workaround #2718 Use com.schibsted.spt.data.jslt.FunctionUtils with an explicit class loader or let it fall back to TCCL --- .../component/jslt/it/JsltConfiguration.java | 31 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/integration-tests/jslt/src/main/java/org/apache/camel/quarkus/component/jslt/it/JsltConfiguration.java b/integration-tests/jslt/src/main/java/org/apache/camel/quarkus/component/jslt/it/JsltConfiguration.java index b678030..bbfcb34 100644 --- a/integration-tests/jslt/src/main/java/org/apache/camel/quarkus/component/jslt/it/JsltConfiguration.java +++ b/integration-tests/jslt/src/main/java/org/apache/camel/quarkus/component/jslt/it/JsltConfiguration.java @@ -16,17 +16,20 @@ */ package org.apache.camel.quarkus.component.jslt.it; +import java.lang.reflect.Method; + import javax.inject.Named; import com.schibsted.spt.data.jslt.Expression; +import com.schibsted.spt.data.jslt.Function; +import com.schibsted.spt.data.jslt.JsltException; import com.schibsted.spt.data.jslt.Parser; import com.schibsted.spt.data.jslt.filters.JsltJsonFilter; +import com.schibsted.spt.data.jslt.impl.FunctionWrapper; import org.apache.camel.component.jslt.JsltComponent; import static java.util.Collections.singleton; -import static com.schibsted.spt.data.jslt.FunctionUtils.wrapStaticMethod; - public class JsltConfiguration { @Named @@ -50,6 +53,30 @@ public class JsltConfiguration { return component; } + /* A variant of com.schibsted.spt.data.jslt.FunctionUtils.wrapStaticMethod() using TCCL + * Otherwise the class is not found on Quarkus Platform where the class loading setup is a bit different. + * Workaround for https://github.com/schibsted/jslt/issues/197 */ + static public Function wrapStaticMethod(String functionName, + String className, + String methodName) + throws LinkageError, ExceptionInInitializerError, ClassNotFoundException { + Class klass = Class.forName(className, true, Thread.currentThread().getContextClassLoader()); + Method[] methods = klass.getMethods(); + Method method = null; + for (int ix = 0; ix < methods.length; ix++) { + if (methods[ix].getName().equals(methodName)) { + if (method == null) + method = methods[ix]; + else + throw new JsltException("More than one method named '" + methodName + "'"); + } + } + if (method == null) + throw new JsltException("No such method: '" + methodName + "'"); + + return new FunctionWrapper(functionName, method); + } + public static Ping createInfiniteRecursionObject() { Ping ping = new Ping(); Pong pong = new Pong();
