COCOON-1579 describes a continuation issue when using rhino 1.6 in cocoon 2.1.10+. The workaround is to replace rhino 1.6 with the previous version. Before compiling cocoon, please follow this steps:

For Cocoon 2.1:

  1. Download rhino1.5r4-continuations-R26.jar and locate it on "$COCOON/lib/core" folder. 2. Delete js-1.6R5.jar from "$COCOON/lib/core". 3. Change the jar location (<lib/>) for rhino on $COCOON/lib/jars.xml from
  <file>
    <title>Continuations-based JavaScript engine</title>
    <description>Rhino is an implementation of JavaScript in Java.</description>
    <used-by>Control flow</used-by>
    <lib>core/js-1.6R5.jar</lib>
    <homepage>http://svn.cocoondev.org/repos/rhino+cont/</homepage>    
  </file>

to

  <file>
    <title>Continuations-based JavaScript engine</title>
    <description>Rhino is an implementation of JavaScript in Java.</description>
    <used-by>Control flow</used-by>
    <lib>core/rhino1.5r4-continuations-R26.jar</lib>
    <homepage>http://svn.cocoondev.org/repos/rhino+cont/</homepage>    
  </file>

4. Revert the code changes for rhino1.6 which are 2 and are commented in the code base:
4.a. src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java, line:331

public Object jsFunction_getComponent(String id)
    throws Exception {
    // To use rhino1.5r4-continuations-R26.jar as a workaround for COCOON-1579: Uncomment the next line and comment the original return.
    // return getServiceManager().lookup(id);
    return org.mozilla.javascript.Context.javaToJS(getServiceManager().lookup(id), getParentScope());
}

4.b. src/blocks/forms/java/org/apache/cocoon/forms/util/JavaScriptHelper.java, line:64

script = ctx.compileReader(
    // To use rhino1.5r4-continuations-R26.jar as a workaround for COCOON-1579: Uncomment the next line.
    // getRootScope(null), //scope
    new StringReader(jsText), // in
    sourceName == null ? "<unknown>" : sourceName, // sourceName
    DomHelper.getLineLocation(element), // lineNo
    null // securityDomain
);

5. Then you can build cocoon by running the script (build.bat or build.sh)


For Cocoon 2.2:

1.Download rhino1.5r4-continuations-R26.jar and deploy it in your local maven repo with the next command

 mvn deploy:deploy-file -Durl=file:///m2-repo -DrepositoryId=some.id -Dfile=/path-to-rhino-jar/rhino1.5r4-continuations-R26.jar -DgroupId=rhino -DartifactId=js -Dversion=1.5r4-continuations  -Dpackaging=jar

2. Change the rhino's dependency to one recently created, in "$COCOON/parent/pom.xml"
From

<dependency>
 <groupId>rhino</groupId>
 <artifactId>js</artifactId>
 <version>1.6R7</version>
</dependency>

to

<dependency>
 <groupId>rhino</groupId>
 <artifactId>js</artifactId>
 <version>1.5r4-continuations</version>
</dependency>

3. Change the code to use rhino 1.5r4-continuations api. These are the changes:

3.1.$COCOON/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/
cocoon/components/flow/javascript/LocationTrackingDebugger.java
3.1.1. Add the following import:

import org.mozilla.javascript.NativeFunction;

3.1.2.Change line 54

if (ex.sourceName() != null) {
    return new LocationImpl(ex.getName(), ex.sourceName(), ex.lineNumber(), ex.columnNumber());

to

if (ex.getSourceName() != null) {
    return new LocationImpl(ex.getName(), ex.getSourceName(), ex.getLineNumber(), ex.getColumnNumber());

3.1.3. Change line 82

public void handleCompilationDone(Context cx, DebuggableScript fnOrScript, String source)

to

public void handleCompilationDone(Context cx, DebuggableScript fnOrScript, StringBuffer source)

3.1.4. Change line 86

public DebugFrame getFrame(Context cx, DebuggableScript fnOrScript)

to

public DebugFrame enterFrame(Context cx, Scriptable scope, Scriptable thisObj, Object[] args, DebuggableScript fnOrScript)

3.1.5. Change line 127

public void onLineChange(Context cx, int lineNumber)

to

public void onLineChange(Context cx, int lineNumber, boolean breakpoint)

3.1.6. Change in line 138

if (script.isFunction()) {
    name = script.getFunctionName();
} else {
    name = "[script]";
}

to

Scriptable obj = script.getScriptable();
name = obj instanceof NativeFunction ? ((NativeFunction)obj).getFunctionName() : "Top-level script";
if (name == null || name.length() == 0) {
    name = "[unnamed]";
}

3.2.$COCOON/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/
cocoon/components/flow/javascript/fom/FOM_Cocoon.java:
3.2.1. Change line 324

return org.mozilla.javascript.Context.javaToJS(currentCall.webAppContext.getBean(id),                                                       getParentScope());

to

return currentCall.webAppContext.getBean(id);

3.2.2.Change line 375

return org.mozilla.javascript.Context.javaToJS(obj, getParentScope());

to

return obj;

3.2.3. Change line 489

result = org.mozilla.javascript.Context.javaToJS(result, start);

to

result = wrap(start, result, null);

3.3.$COCOON/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/
cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java:

3.3.1.Add the import:

import java.io.StringReader;

3.3.2. Change line 500

Script compiledScript = cx.compileReader(reader, src.getURI(), 1, null);

to

Script compiledScript = cx.compileReader(scope, reader, src.getURI(), 1, null);

3.3.3. Change line 593

fun = context.compileString(funName, null, 1, null).exec (context, thrScope);

to

fun = context.compileReader (thrScope, new StringReader(funName), null, 1, null).exec (context, thrScope);

3.4.$COCOON/blocks/cocoon-flowscript/cocoon-flowscript-impl/src/main/java/org/apache/
cocoon/components/flow/javascript/fom/FOM_WebContinuation.java
3.4.1. Change in line 104

return org.mozilla.javascript.Context.javaToJS(
                wk.getAttribute(name),
                getParentScope());

to

return org.mozilla.javascript.Context.toObject(
                wk.getAttribute(name),
                getParentScope());

3.4.2. Change in line 118

return org.mozilla.javascript.Context.javaToJS(
                wk.getAttributeNames(),
                getParentScope());

to

return org.mozilla.javascript.Context.toObject(
                wk.getAttributeNames(),
                getParentScope());

3.5.$COCOON/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/
forms/util/JavaScriptHelper.java, Uncomment line 65

// To use rhino1.5r4-continuations-R26.jar as a workaround for COCOON-1579: Uncomment the next line.
// getRootScope(null), //scope

It should look like this:

// To use rhino1.5r4-continuations-R26.jar as a workaround for COCOON-1579: Uncomment the next line.
getRootScope(null), //scope

3.6.$COCOON/blocks/cocoon-scratchpad/cocoon-scraptchpad-impl/src/main/java/org/apache/
cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java
3.6.1. Change in line 554

compiledScript = cx.compileReader(reader, src.getURI(), 1, null );
   to
{{{
compiledScript = cx.compileReader(scope, reader, src.getURI(), 1, null);

3.6.2. Change in line 561

compiledScript = cx.compileReader(reader, src.getURI() + INTERCEPTION_POSTFIX, 1, null );

to

compiledScript = cx.compileReader(scope, reader, src.getURI()  + INTERCEPTION_POSTFIX, 1, null);

3.6.3. Change in line 628

if (ee.sourceName() != null) {
    Context.reportRuntimeError(msg,
                               ee.sourceName(),
                               ee.lineNumber(),
                               ee.lineSource(),
                               ee.columnNumber());

to

if (ee.getSourceName() != null) {
    Context.reportRuntimeError(msg,
                               ee.getSourceName(),
                               ee.getLineNumber(),
                               ee.getLineSource(),
                               ee.getColumnNumber());

3.6.4. Change line 710

if (ee.sourceName() != null) {
    Context.reportRuntimeError(msg,
                               ee.sourceName(),
                               ee.lineNumber(),
                               ee.lineSource(),
                               ee.columnNumber());

to

if (ee.getSourceName() != null) {
    Context.reportRuntimeError(msg,
                               ee.getSourceName(),
                               ee.getLineNumber(),
                               ee.getLineSource(),
                               ee.getColumnNumber());

3.7.$COCOON/block/cocoon-xsp/cocoon-xsp-impl/src/main/java/org/apache/cocoon/
components/language/markup/xsp/JSGenerator.java, change in line 111

script = context.compileReader(new FileReader(file), file.toString(), 1, null);

to

script = context.compileReader(global, new FileReader(file), file.toString(), 1, null);

3.8.$COCOON/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/
java/org/apache/cocoon/el/impl/javascript/JavaScriptExpression.java
3.8.1. Add the following import

import java.io.StringReader;

3.8.2. Change in line 48

this.script = ctx.compileString(getExpression(), "", 1, null);

to

this.script = ctx.compileReader(getScope(rootScope), new StringReader(getExpression()), "", 1, null);
} catch (Exception e) {
   if (e instanceof RuntimeException) {
        throw (RuntimeException)e;
   } else{
        throw new RuntimeException("Runtime exception.", e);
   }

3.9. $COCOON/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/
java/org/apache/cocoon/el/impl/javascript/JavaScriptTestCase.java change line 40,

assertEquals(new Integer(3), result);

to

assertEquals(new Double(3), result);

4. Build cocoon with maven ( mvn -P allblocks clean install )

  • No labels