Repository: camel Updated Branches: refs/heads/camel-2.15.x b83bda1c0 -> 071be584d refs/heads/master 35b83b1d3 -> 74dc1c2c8
CAMEL-8521: camel-script - Should try all classloaders before throwing IAE Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/74dc1c2c Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/74dc1c2c Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/74dc1c2c Branch: refs/heads/master Commit: 74dc1c2c80f06f45c0810c7d4f43d6c459afac7f Parents: 35b83b1 Author: Claus Ibsen <davscl...@apache.org> Authored: Fri Mar 20 08:03:59 2015 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Mar 20 08:03:59 2015 +0100 ---------------------------------------------------------------------- .../camel/builder/script/ScriptBuilder.java | 27 +++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/74dc1c2c/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java ---------------------------------------------------------------------- diff --git a/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java b/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java index deb5fb4..36f459c 100644 --- a/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java +++ b/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java @@ -326,9 +326,9 @@ public class ScriptBuilder implements Expression, Predicate, Processor { } protected static ScriptEngine createScriptEngine(String language) { - ScriptEngine engine = createScriptEngine(language, ScriptBuilder.class.getClassLoader()); + ScriptEngine engine = tryCreateScriptEngine(language, ScriptBuilder.class.getClassLoader()); if (engine == null) { - engine = createScriptEngine(language, Thread.currentThread().getContextClassLoader()); + engine = tryCreateScriptEngine(language, Thread.currentThread().getContextClassLoader()); } if (engine == null) { throw new IllegalArgumentException("No script engine could be created for: " + language); @@ -336,7 +336,12 @@ public class ScriptBuilder implements Expression, Predicate, Processor { return engine; } - private static ScriptEngine createScriptEngine(String language, ClassLoader classLoader) { + /** + * Attemps to create the script engine for the given langauge using the classloader + * + * @return the engine, or <tt>null</tt> if not able to create + */ + private static ScriptEngine tryCreateScriptEngine(String language, ClassLoader classLoader) { ScriptEngineManager manager = new ScriptEngineManager(classLoader); ScriptEngine engine = null; @@ -349,17 +354,15 @@ public class ScriptBuilder implements Expression, Predicate, Processor { break; } } catch (NoClassDefFoundError ex) { - LOG.error("Cannot load the scriptEngine for " + name + ", the exception is " + ex - + ", please ensure correct JARs is provided on classpath."); + LOG.warn("Cannot load ScriptEngine for " + name + ". Please ensure correct JARs is provided on classpath (stacktrace in DEBUG logging)."); + // include stacktrace in debug logging + LOG.debug("Cannot load ScriptEngine for " + name + ". Please ensure correct JARs is provided on classpath.", ex); } } if (engine == null) { engine = checkForOSGiEngine(language); } - if (engine == null) { - throw new IllegalArgumentException("No script engine could be created for: " + language); - } - if (isPython(language)) { + if (engine != null && isPython(language)) { ScriptContext context = engine.getContext(); context.setAttribute("com.sun.script.jython.comp.mode", "eval", ScriptContext.ENGINE_SCOPE); } @@ -367,19 +370,19 @@ public class ScriptBuilder implements Expression, Predicate, Processor { } private static ScriptEngine checkForOSGiEngine(String language) { - LOG.debug("No script engine found for " + language + " using standard javax.script auto-registration. Checking OSGi registry..."); + LOG.debug("No script engine found for {} using standard javax.script auto-registration. Checking OSGi registry.", language); try { // Test the OSGi environment with the Activator Class<?> c = Class.forName("org.apache.camel.script.osgi.Activator"); Method mth = c.getDeclaredMethod("getBundleContext"); Object ctx = mth.invoke(null); - LOG.debug("Found OSGi BundleContext " + ctx); + LOG.debug("Found OSGi BundleContext: {}", ctx); if (ctx != null) { Method resolveScriptEngine = c.getDeclaredMethod("resolveScriptEngine", String.class); return (ScriptEngine)resolveScriptEngine.invoke(null, language); } } catch (Throwable t) { - LOG.debug("Unable to load OSGi, script engine cannot be found", t); + LOG.debug("Unable to detect OSGi. ScriptEngine for " + language + " cannot be resolved.", t); } return null; }