camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-9159: camel-script should only attempt to resolve languages it has script engines that supports.
Date Thu, 24 Sep 2015 11:55:42 GMT
Repository: camel
Updated Branches:
  refs/heads/master d4228467a -> 7228c13b3


CAMEL-9159: camel-script should only attempt to resolve languages it has script engines that
supports.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7228c13b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7228c13b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7228c13b

Branch: refs/heads/master
Commit: 7228c13b30705d4bd6112215c103890b268ad5cc
Parents: d422846
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Sep 24 13:56:53 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Sep 24 13:56:53 2015 +0200

----------------------------------------------------------------------
 .../apache/camel/model/ToDynamicDefinition.java |  7 ++--
 .../apache/camel/processor/WireTapLogTest.java  | 41 ++++++++++++++++++
 .../camel/builder/script/ScriptBuilder.java     | 15 +++++--
 .../builder/script/ScriptLanguageResolver.java  |  7 +++-
 .../camel/builder/script/WireTapLogTest.java    | 44 ++++++++++++++++++++
 5 files changed, 106 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7228c13b/camel-core/src/main/java/org/apache/camel/model/ToDynamicDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ToDynamicDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ToDynamicDefinition.java
index ef6e90d..eb78088 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ToDynamicDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ToDynamicDefinition.java
@@ -92,9 +92,10 @@ public class ToDynamicDefinition extends NoOutputDefinition<ToDynamicDefinition>
                 // maybe its a language
                 try {
                     Language partLanguage = routeContext.getCamelContext().resolveLanguage(before);
-                    Expression exp = partLanguage.createExpression(after);
-                    list.add(exp);
-                    continue;
+                    if (partLanguage != null) {
+                        Expression exp = partLanguage.createExpression(after);
+                        list.add(exp);
+                    }
                 } catch (NoSuchLanguageException e) {
                     // ignore
                 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7228c13b/camel-core/src/test/java/org/apache/camel/processor/WireTapLogTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/WireTapLogTest.java b/camel-core/src/test/java/org/apache/camel/processor/WireTapLogTest.java
new file mode 100644
index 0000000..50d5c1b
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/WireTapLogTest.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class WireTapLogTest extends ContextTestSupport {
+
+    public void testWireTapLog() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+    
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:start")
+                    .wireTap("log:com.foo.MyApp?level=WARN")
+                    .to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/7228c13b/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 36f459c..3ee457c 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
@@ -108,7 +108,7 @@ public class ScriptBuilder implements Expression, Predicate, Processor
{
             this.scriptText = scriptText;
         }
         if (scriptEngineFactory == null) {
-            this.scriptEngine = createScriptEngine(scriptLanguage);
+            this.scriptEngine = createScriptEngine(scriptLanguage, false);
             this.scriptEngineFactory = lookupScriptEngineFactory(scriptLanguage);
         } else {
             this.scriptEngineFactory = scriptEngineFactory;
@@ -261,6 +261,13 @@ public class ScriptBuilder implements Expression, Predicate, Processor
{
         return new ScriptBuilder("jruby", scriptText);
     }
 
+    /**
+     * Whether the given language is a language that is supported by a scripting engine.
+     */
+    public static boolean supportScriptLanguage(String language) {
+        return createScriptEngine(language, true) != null;
+    }
+
     // Properties
     // -------------------------------------------------------------------------
 
@@ -318,19 +325,19 @@ public class ScriptBuilder implements Expression, Predicate, Processor
{
         }
 
         // fallback to get engine by name
-        ScriptEngine engine = createScriptEngine(language);
+        ScriptEngine engine = createScriptEngine(language, true);
         if (engine != null) {
             return engine.getFactory();
         }
         return null;
     }
 
-    protected static ScriptEngine createScriptEngine(String language) {
+    protected static ScriptEngine createScriptEngine(String language, boolean allowNull)
{
         ScriptEngine engine = tryCreateScriptEngine(language, ScriptBuilder.class.getClassLoader());
         if (engine == null) {
             engine = tryCreateScriptEngine(language, Thread.currentThread().getContextClassLoader());
         }
-        if (engine == null) {
+        if (engine == null && !allowNull) {
             throw new IllegalArgumentException("No script engine could be created for: "
+ language);
         }
         return engine;

http://git-wip-us.apache.org/repos/asf/camel/blob/7228c13b/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptLanguageResolver.java
----------------------------------------------------------------------
diff --git a/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptLanguageResolver.java
b/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptLanguageResolver.java
index 8e3a448..a258243 100644
--- a/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptLanguageResolver.java
+++ b/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptLanguageResolver.java
@@ -26,6 +26,11 @@ import org.apache.camel.spi.LanguageResolver;
 public class ScriptLanguageResolver implements LanguageResolver {
 
     public Language resolveLanguage(String name, CamelContext context) {
-        return new ScriptLanguage(name);
+        // only return if we can suppor the language
+        if (ScriptBuilder.supportScriptLanguage(name)) {
+            return new ScriptLanguage(name);
+        } else {
+            return null;
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7228c13b/components/camel-script/src/test/java/org/apache/camel/builder/script/WireTapLogTest.java
----------------------------------------------------------------------
diff --git a/components/camel-script/src/test/java/org/apache/camel/builder/script/WireTapLogTest.java
b/components/camel-script/src/test/java/org/apache/camel/builder/script/WireTapLogTest.java
new file mode 100644
index 0000000..f9cd2e5
--- /dev/null
+++ b/components/camel-script/src/test/java/org/apache/camel/builder/script/WireTapLogTest.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.builder.script;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class WireTapLogTest extends CamelTestSupport {
+
+    @Test
+    public void testWireTapLog() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:start")
+                        .wireTap("log:com.foo.MyApp?level=WARN")
+                        .to("mock:result");
+            }
+        };
+    }
+
+}


Mime
View raw message