Author: ningjiang
Date: Tue Jul 8 18:20:22 2008
New Revision: 675076
URL: http://svn.apache.org/viewvc?rev=675076&view=rev
Log:
CAMEL-655 Applied the patch with thanks to Don. Also Removed the
System.out.println from Jsr223Test
Modified:
activemq/camel/trunk/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java
activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/Jsr223Test.java
activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/PythonExpressionTest.java
activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/language/script/PythonLanguageTest.java
Modified:
activemq/camel/trunk/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java?rev=675076&r1=675075&r2=675076&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java
(original)
+++
activemq/camel/trunk/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java
Tue Jul 8 18:20:22 2008
@@ -458,7 +458,12 @@
protected ScriptEngine createScriptEngine() {
ScriptEngineManager manager = new ScriptEngineManager();
- return manager.getEngineByName(scriptEngineName);
+ ScriptEngine engine = manager.getEngineByName(scriptEngineName);
+ if (isPython()) {
+ ScriptContext context = engine.getContext();
+ context.setAttribute("com.sun.script.jython.comp.mode", "eval",
ScriptContext.ENGINE_SCOPE);
+ }
+ return engine;
}
protected void compileScript(Compilable compilable) {
@@ -502,22 +507,12 @@
Object result = null;
if (compiledScript != null) {
result = compiledScript.eval();
- if (scriptEngineName.equals("python") ||
scriptEngineName.equals("jython")) {
- // Retrieve the evaluation result for Python script
- // Python script should store the evaluation result into
result variable
- result = compiledScript.getEngine().get("result");
- }
} else {
if (scriptText != null) {
result = getEngine().eval(scriptText);
} else {
result = getEngine().eval(createScriptReader());
}
- if (scriptEngineName.equals("python") ||
scriptEngineName.equals("jython")) {
- // Retrieve the evaluation result for python script
- // Python script should store the evaluation result into
result variable
- result = getEngine().get("result");
- }
}
return result;
}
@@ -553,4 +548,8 @@
return new ScriptEvaluationException("Failed to evaluate: " +
getScriptDescription() + ". Cause: " + e, e);
}
+ protected boolean isPython() {
+ return "python".equals(scriptEngineName) ||
"jython".equals(scriptEngineName);
+ }
+
}
Modified:
activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/Jsr223Test.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/Jsr223Test.java?rev=675076&r1=675075&r2=675076&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/Jsr223Test.java
(original)
+++
activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/Jsr223Test.java
Tue Jul 8 18:20:22 2008
@@ -16,6 +16,7 @@
*/
package org.apache.camel.builder.script;
+import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
@@ -25,10 +26,12 @@
* @version $Revision$
*/
public class Jsr223Test extends TestCase {
+ private static String [] scriptNames = {"groovy", "js", "python", "ruby",
"javascript"};
public void testLanguageNames() throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();
- for (ScriptEngineFactory factory : manager.getEngineFactories()) {
- System.out.println("Factory: " + factory.getNames() + " " +
factory.getEngineName());
+ for (String scriptName : scriptNames) {
+ ScriptEngine engine = manager.getEngineByName(scriptName);
+ assertNotNull("We should get the scrpte engine for " + scriptName
, engine);
}
}
}
Modified:
activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/PythonExpressionTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/PythonExpressionTest.java?rev=675076&r1=675075&r2=675076&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/PythonExpressionTest.java
(original)
+++
activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/PythonExpressionTest.java
Tue Jul 8 18:20:22 2008
@@ -27,10 +27,6 @@
*/
public class PythonExpressionTest extends ContextTestSupport {
public void testSendMatchingMessage() throws Exception {
- // Currently, this test fails because the Python expression in
createRouteBuilder
- // below returns null and that is treated as 'false', therefore it's
as if the
- // message didn't match the expression
- // To fix that, we need to figure out how to get the expression to
return a boolean
getMockEndpoint("mock:result").expectedMessageCount(1);
getMockEndpoint("mock:unmatched").expectedMessageCount(0);
@@ -56,8 +52,7 @@
return new RouteBuilder() {
public void configure() throws Exception {
from("direct:start").choice().
- // The result variable is used to retrieve the python
script evaluation result
- when().python("result =
request.headers['foo']=='bar'").to("mock:result")
+
when().python("request.headers['foo']=='bar'").to("mock:result")
.otherwise().to("mock:unmatched");
}
};
Modified:
activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/language/script/PythonLanguageTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/language/script/PythonLanguageTest.java?rev=675076&r1=675075&r2=675076&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/language/script/PythonLanguageTest.java
(original)
+++
activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/language/script/PythonLanguageTest.java
Tue Jul 8 18:20:22 2008
@@ -23,13 +23,13 @@
*/
public class PythonLanguageTest extends LanguageTestSupport {
public void testLanguageExpressions() throws Exception {
- assertExpression("result=exchange.in.headers", "{foo=abc, bar=123}");
- assertExpression("result=exchange.in", "Message: <hello
id='m123'>world!</hello>");
- assertExpression("result=exchange.in.headers.get('foo')", "abc");
- assertExpression("result=request.headers.get('foo')", "abc");
+ assertExpression("exchange.in.headers", "{foo=abc, bar=123}");
+ assertExpression("exchange.in", "Message: <hello
id='m123'>world!</hello>");
+ assertExpression("exchange.in.headers.get('foo')", "abc");
+ assertExpression("request.headers['foo']", "abc");
}
protected String getLanguageName() {
return "jython";
}
-}
\ No newline at end of file
+}