camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aaron Mulder (JIRA)" <>
Subject [jira] Commented: (CAMEL-655) Jython Expressions always return null/false
Date Tue, 01 Jul 2008 20:06:00 GMT


Aaron Mulder commented on CAMEL-655:

I asked a Jython guy and here's what I got:


The Python syntax is correct, but the Jython script engine does not return the value of the
expression from engine.eval.  I think you need to put the value into the context.  This is
how it used to work pre-JSR, and a quick test show this still works.  

In the following quick and dirty example, the output is always null, but the result.flag is
getting set correctly.

import java.util.HashMap;
import java.util.Map;

import javax.script.ScriptEngine;
import javax.script.ScriptException;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;

public class ScriptEval {
    public static void main(String[] args) throws Exception {
        final ScriptEngineManager manager = new ScriptEngineManager();
        final ScriptEngine engine = manager.getEngineByName("jython");

        final MyRequest request = new MyRequest(args[0]);
        engine.put("request", request);
        final EvalResult result = new EvalResult();
        engine.put("result", result);
        final Reader script = new FileReader(args[1]);
        System.out.printf("Output: %s\n", engine.eval(script));
        System.out.printf("Result value: %s\n", result.getFlag());

class MyRequest {
    private Map<String, String> headers;

    public MyRequest(final String value) {
        headers = new HashMap<String, String>();
        headers.put("console", value);
        headers.put("other_key", "other_value");

    public Map<String, String> getHeaders() {
        return headers;

class EvalResult {
    private boolean flag;

    public void setFlag(final boolean flag) {
        this.flag = flag;

    public boolean getFlag() {
        return flag;

> Jython Expressions always return null/false
> -------------------------------------------
>                 Key: CAMEL-655
>                 URL:
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-script
>    Affects Versions: 1.3.0, 1.4.0
>         Environment: Jython 2.2.1, camel-script 1.3.0/1.4.0-SNAPSHOT, jython integration
lib from or repo
>            Reporter: Aaron Mulder
> A Jython expression used for example like this always returns null, which is now translated
to false:
> from("...").choice().when().jython("some expression").to(...)
> For example, here's an expression that always evaluates to null/false:
> request.headers['foo'] == 'bar'
> To see this, look at the test PythonExpressionTest in the camel-script module.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message