camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r703787 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/language/simple/FileExpressionBuilder.java test/java/org/apache/camel/language/FileLanguageTest.java test/java/org/apache/camel/language/SimpleTest.java
Date Sun, 12 Oct 2008 11:08:12 GMT
Author: davsclaus
Date: Sun Oct 12 04:08:11 2008
New Revision: 703787

URL: http://svn.apache.org/viewvc?rev=703787&view=rev
Log:
CAMEL-979: File language supports constant expressions so you can enter fixed filename

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/FileExpressionBuilder.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/FileExpressionBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/FileExpressionBuilder.java?rev=703787&r1=703786&r2=703787&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/FileExpressionBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/FileExpressionBuilder.java
Sun Oct 12 04:08:11 2008
@@ -23,6 +23,8 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.builder.ExpressionBuilder;
+import org.apache.camel.language.IllegalSyntaxException;
+import org.apache.camel.language.constant.ConstantLanguage;
 
 /**
  * A helper class for working with <a href="http://activemq.apache.org/camel/expression.html">expressions</a>
based
@@ -163,7 +165,12 @@
             public Object evaluate(E exchange) {
                 // must call evaluate to return the nested language evaluate when evaluating
                 // stacked expressions
-                return SimpleLanguage.simple(simple).evaluate(exchange);
+                try {
+                    return SimpleLanguage.simple(simple).evaluate(exchange);
+                } catch (IllegalSyntaxException e) {
+                    // fallback to constant so end users can enter a fixed filename
+                    return ConstantLanguage.constant(simple).evaluate(exchange);
+                }
             }
 
             @Override

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java?rev=703787&r1=703786&r2=703787&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
Sun Oct 12 04:08:11 2008
@@ -47,6 +47,10 @@
         return "file";
     }
 
+    public void testConstantExpression() throws Exception {
+        assertExpression("MyBigFile.txt", "MyBigFile.txt");
+    }
+
     public void testMessageId() throws Exception {
         assertExpression("${id}", exchange.getIn().getMessageId());
         assertExpression("${id}.bak", exchange.getIn().getMessageId() + ".bak");

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java?rev=703787&r1=703786&r2=703787&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java
Sun Oct 12 04:08:11 2008
@@ -23,6 +23,15 @@
  */
 public class SimpleTest extends LanguageTestSupport {
 
+    public void testConstantExpression() throws Exception {
+        try {
+            assertExpression("Hello World", "Hello World");
+            fail("Should have thrown an Exception");
+        } catch (IllegalSyntaxException e) {
+            // constants is not supported
+        }
+    }
+
     public void testSimpleExpressions() throws Exception {
         assertExpression("id", exchange.getIn().getMessageId());
         assertExpression("body", "<hello id='m123'>world!</hello>");



Mime
View raw message