Author: lgawron Date: Sun Nov 21 06:20:13 2004 New Revision: 106091 Modified: cocoon/trunk/src/blocks/apples/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java cocoon/trunk/src/blocks/apples/java/org/apache/cocoon/components/flow/apples/StatelessAppleController.java cocoon/trunk/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/JavaInterpreter.java cocoon/trunk/src/blocks/javaflow/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/groovy/GroovyInterpreter.java cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_Cocoon.java cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java cocoon/trunk/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManager.java cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java cocoon/trunk/src/java/org/apache/cocoon/components/flow/Interpreter.java cocoon/trunk/src/java/org/apache/cocoon/components/flow/WebContinuation.java cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_WebContinuation.java cocoon/trunk/status.xml Log: Fix: Continuation can only be invoked for the interpreter it was originally created for - o.a.c.components.flow.ContinuationsManager interface change. Interpreter id has to be passed to create a continuation and lookup one. - o.a.c.components.flow.ContinuationManagerImpl returns null if interpreter does not match during lookup. - o.a.c.components.flow.Interpreter interface extended with setInterpreterID method. - all current interpreters updated to match new contracts
Modified: cocoon/trunk/src/blocks/apples/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java ============================================================================== --- cocoon/trunk/src/blocks/apples/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java (original) +++ cocoon/trunk/src/blocks/apples/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java Sun Nov 21 06:20:13 2004 @@ -52,7 +52,8 @@ WebContinuation wk = null; if (!(app instanceof StatelessAppleController)) { - wk = this.continuationsMgr.createWebContinuation(app, null, 0, this); + wk = this.continuationsMgr.createWebContinuation(app, null, 0, + getInterpreterID(), this); if (getLogger().isDebugEnabled()) getLogger().debug("Instantiated a stateful apple, continuationid = " + wk.getId()); } @@ -79,7 +80,7 @@ throws Exception { WebContinuation wk = - this.continuationsMgr.lookupWebContinuation(continuationId); + this.continuationsMgr.lookupWebContinuation(continuationId, getInterpreterID()); if (wk == null) { // Throw an InvalidContinuationException to be handled inside the // <map:handle-errors> sitemap element. Modified: cocoon/trunk/src/blocks/apples/java/org/apache/cocoon/components/flow/apples/StatelessAppleController.java ============================================================================== --- cocoon/trunk/src/blocks/apples/java/org/apache/cocoon/components/flow/apples/StatelessAppleController.java (original) +++ cocoon/trunk/src/blocks/apples/java/org/apache/cocoon/components/flow/apples/StatelessAppleController.java Sun Nov 21 06:20:13 2004 @@ -1,3 +1,19 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed 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.cocoon.components.flow.apples; /** Modified: cocoon/trunk/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/JavaInterpreter.java ============================================================================== --- cocoon/trunk/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/JavaInterpreter.java (original) +++ cocoon/trunk/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/JavaInterpreter.java Sun Nov 21 06:20:13 2004 @@ -175,7 +175,8 @@ Continuation continuation = new Continuation(context); - WebContinuation wk = continuationsMgr.createWebContinuation(continuation, null, timeToLive, null); + WebContinuation wk = continuationsMgr.createWebContinuation( + continuation, null, timeToLive, getInterpreterID(), null); FlowHelper.setWebContinuation(ContextHelper.getObjectModel(this.avalonContext), wk); continuation.registerThread(); @@ -218,7 +219,7 @@ if (!initialized) initialize(); - WebContinuation parentwk = continuationsMgr.lookupWebContinuation(id); + WebContinuation parentwk = continuationsMgr.lookupWebContinuation(id, getInterpreterID()); if (parentwk == null) { /* @@ -252,7 +253,8 @@ ContinuationCapable flow = (ContinuationCapable) context.getObject(); Method method = context.getMethod(); - WebContinuation wk = continuationsMgr.createWebContinuation(continuation, parentwk, timeToLive, null); + WebContinuation wk = continuationsMgr.createWebContinuation( + continuation, parentwk, timeToLive, getInterpreterID(), null); FlowHelper.setWebContinuation(ContextHelper.getObjectModel(this.avalonContext), wk); continuation.registerThread(); Modified: cocoon/trunk/src/blocks/javaflow/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java ============================================================================== --- cocoon/trunk/src/blocks/javaflow/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java (original) +++ cocoon/trunk/src/blocks/javaflow/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java Sun Nov 21 06:20:13 2004 @@ -127,7 +127,8 @@ Continuation continuation = new Continuation(context); - WebContinuation wk = continuationsMgr.createWebContinuation(continuation, null, timeToLive, null); + WebContinuation wk = continuationsMgr.createWebContinuation(continuation, null, timeToLive, + getInterpreterID(), null); FlowHelper.setWebContinuation(ContextHelper.getObjectModel(this.avalonContext), wk); continuation.registerThread(); @@ -155,7 +156,7 @@ public void handleContinuation(String id, List params, Redirector redirector) throws Exception { - WebContinuation parentwk = continuationsMgr.lookupWebContinuation(id); + WebContinuation parentwk = continuationsMgr.lookupWebContinuation(id, getInterpreterID()); if (parentwk == null) { /* @@ -187,7 +188,8 @@ ScriptHelper flow = (ScriptHelper) context.getObject(); - WebContinuation wk = continuationsMgr.createWebContinuation(continuation, parentwk, timeToLive, null); + WebContinuation wk = continuationsMgr.createWebContinuation(continuation, parentwk, timeToLive, + getInterpreterID(), null); FlowHelper.setWebContinuation(ContextHelper.getObjectModel(this.avalonContext), wk); continuation.registerThread(); Modified: cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/groovy/GroovyInterpreter.java ============================================================================== --- cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/groovy/GroovyInterpreter.java (original) +++ cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/groovy/GroovyInterpreter.java Sun Nov 21 06:20:13 2004 @@ -45,7 +45,7 @@ /** * Implementation of the groovy flow interpreter. * - * @version CVS $Id: GroovyInterpreter.java,v 1.1 2004/06/07 01:04:18 antonio Exp $ + * @version CVS $Id$ */ public class GroovyInterpreter extends AbstractInterpreter implements Configurable { @@ -172,7 +172,8 @@ Continuation continuation = new Continuation(context); - WebContinuation wk = continuationsMgr.createWebContinuation(continuation, null, timeToLive, null); + WebContinuation wk = continuationsMgr.createWebContinuation(continuation, null, timeToLive, + getInterpreterID(), null); FlowHelper.setWebContinuation(ContextHelper.getObjectModel(this.avalonContext), wk); continuation.registerThread(); @@ -215,7 +216,7 @@ if (!initialized) { initialize(); } - WebContinuation parentwk = continuationsMgr.lookupWebContinuation(id); + WebContinuation parentwk = continuationsMgr.lookupWebContinuation(id, getInterpreterID()); if (parentwk == null) { /* * Throw an InvalidContinuationException to be handled inside the @@ -241,7 +242,8 @@ Continuable flow = (Continuable) context.getObject(); Method method = context.getMethod(); - WebContinuation wk = continuationsMgr.createWebContinuation(continuation, parentwk, timeToLive, null); + WebContinuation wk = continuationsMgr.createWebContinuation(continuation, parentwk, timeToLive, + getInterpreterID(), null); FlowHelper.setWebContinuation(ContextHelper.getObjectModel(this.avalonContext), wk); continuation.registerThread(); Modified: cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_Cocoon.java ============================================================================== --- cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_Cocoon.java (original) +++ cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_Cocoon.java Sun Nov 21 06:20:13 2004 @@ -124,6 +124,7 @@ contMgr.createWebContinuation(continuation, lastContinuation, 0, + interpreter.getInterpreterID(), null); } @@ -248,7 +249,7 @@ public FOM_Request(Object request) { this.request = (Request)unwrap(request); } - + public String getClassName() { return "FOM_Request"; } @@ -675,7 +676,7 @@ /* TODO: Vote on the inclusion of this method public String jsFunction_getRealPath(String path) { - return context.getRealPath(path); + return context.getRealPath(path); } */ } @@ -926,6 +927,7 @@ wk = contMgr.createWebContinuation(unwrap(k), (parent == null ? null : parent.getWebContinuation()), timeToLive, + interpreter.getInterpreterID(), null); FOM_WebContinuation result = new FOM_WebContinuation(wk); result.setParentScope(getParentScope()); Modified: cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java ============================================================================== --- cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java (original) +++ cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java Sun Nov 21 06:20:13 2004 @@ -652,7 +652,7 @@ Redirector redirector) throws Exception { - WebContinuation wk = continuationsMgr.lookupWebContinuation(id); + WebContinuation wk = continuationsMgr.lookupWebContinuation(id, getInterpreterID()); if (wk == null) { Modified: cocoon/trunk/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java Sun Nov 21 06:20:13 2004 @@ -102,7 +102,7 @@ * * @return a unique ID for this interpreter */ - protected String getInterpreterID() { + public String getInterpreterID() { return this.instanceID; } Modified: cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManager.java ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManager.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManager.java Sun Nov 21 06:20:13 2004 @@ -31,7 +31,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a> * @since March 19, 2002 * @see WebContinuation - * @version CVS $Id: ContinuationsManager.java,v 1.6 2004/03/05 13:02:46 bdelacretaz Exp $ + * @version CVS $Id$ */ public interface ContinuationsManager { public final String ROLE = ContinuationsManager.class.getName(); @@ -47,6 +47,7 @@ * @param timeToLive an <code>int</code> value indicating how long * in seconds this continuation will live in the server if not * accessed + * @param interpreterId id of interpreter invoking continuation creation * @param disposer a <code>ContinuationsDisposer</code> instance to called when * the continuation gets cleaned up. * @return a <code>WebContinuation</code> value @@ -55,6 +56,7 @@ public WebContinuation createWebContinuation(Object kont, WebContinuation parentKont, int timeToLive, + String interpreterId, ContinuationsDisposer disposer); /** @@ -71,12 +73,16 @@ /** * Given a <code>WebContinuation</code> id, retrieve the associated * <code>WebContinuation</code> object. - * * @param id a <code>String</code> value - * @return a <code>WebContinuation</code> object, or null if no such - * <code>WebContinuation</code> could be found. + * @param interpreterId Id of an interpreter that queries for + * the continuation + * + * @return a <code>WebContinuation</code> object, null if no such + * <code>WebContinuation</code> could be found. Also null if + * <code>WebContinuation</code> was found but interpreter id does + * not match the one that the continuation was initialy created for. */ - public WebContinuation lookupWebContinuation(String id); + public WebContinuation lookupWebContinuation(String id, String interpreterId); /** * Prints debug information about all web continuations into the log file. Modified: cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java Sun Nov 21 06:20:13 2004 @@ -134,10 +134,11 @@ public WebContinuation createWebContinuation(Object kont, WebContinuation parent, int timeToLive, + String interpreterId, ContinuationsDisposer disposer) { int ttl = (timeToLive == 0 ? defaultTimeToLive : timeToLive); - WebContinuation wk = generateContinuation(kont, parent, ttl, disposer); + WebContinuation wk = generateContinuation(kont, parent, ttl, interpreterId, disposer); wk.enableLogging(getLogger()); if (parent == null) { @@ -162,10 +163,11 @@ return wk; } - public WebContinuation lookupWebContinuation(String id) { + public WebContinuation lookupWebContinuation(String id, String interpreterId) { // REVISIT: Is the following check needed to avoid threading issues: // return wk only if !(wk.hasExpired) ? - return (WebContinuation) idToWebCont.get(id); + WebContinuation kont = (WebContinuation) idToWebCont.get(id); + return (kont.interpreterMatches(interpreterId)) ? kont : null; } /** @@ -179,6 +181,7 @@ * @param kont an <code>Object</code> value representing continuation * @param parent value representing parent <code>WebContinuation</code> * @param ttl <code>WebContinuation</code> time to live + * @param interpreterId id of interpreter invoking continuation creation * @param disposer <code>ContinuationsDisposer</code> instance to use for * cleanup of the continuation. * @return the generated <code>WebContinuation</code> with unique identifier @@ -186,6 +189,7 @@ private WebContinuation generateContinuation(Object kont, WebContinuation parent, int ttl, + String interpreterId, ContinuationsDisposer disposer) { char[] result = new char[bytes.length * 2]; @@ -203,7 +207,7 @@ final String id = new String(result); synchronized (idToWebCont) { if (!idToWebCont.containsKey(id)) { - wk = new WebContinuation(id, kont, parent, ttl, disposer); + wk = new WebContinuation(id, kont, parent, ttl, interpreterId, disposer); idToWebCont.put(id, wk); break; } Modified: cocoon/trunk/src/java/org/apache/cocoon/components/flow/Interpreter.java ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/flow/Interpreter.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/Interpreter.java Sun Nov 21 06:20:13 2004 @@ -93,7 +93,12 @@ public static final String ROLE = Interpreter.class.getName(); - /** + /** + * @return the unique ID for this interpreter. + */ + String getInterpreterID(); + + /** * Set the unique ID for this interpreter. */ void setInterpreterID(String interpreterID); Modified: cocoon/trunk/src/java/org/apache/cocoon/components/flow/WebContinuation.java ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/flow/WebContinuation.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/WebContinuation.java Sun Nov 21 06:20:13 2004 @@ -19,6 +19,7 @@ import java.util.List; import org.apache.avalon.framework.logger.AbstractLogEnabled; +import org.apache.commons.lang.StringUtils; /** * Representation of continuations in a Web environment. @@ -34,7 +35,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a> * @since March 19, 2002 - * @version CVS $Id: WebContinuation.java,v 1.9 2004/05/17 18:50:53 vgritsenko Exp $ + * @version CVS $Id$ */ public class WebContinuation extends AbstractLogEnabled implements Comparable { @@ -67,6 +68,11 @@ * The continuation id used to represent this instance in Web pages. */ protected String id; + + /** + * Interpreter id that this continuation is bound to + */ + protected String interpreterId; /** * A user definable object. This is present for convenience, to @@ -113,12 +119,14 @@ Object continuation, WebContinuation parentContinuation, int timeToLive, + String interpreterId, ContinuationsDisposer disposer) { this.id = id; this.continuation = continuation; this.parentContinuation = parentContinuation; this.updateLastAccessTime(); this.timeToLive = timeToLive; + this.interpreterId = interpreterId; this.disposer = disposer; if (parentContinuation != null) { @@ -363,5 +371,9 @@ */ public boolean disposed() { return this.continuation == null; + } + + public boolean interpreterMatches( String interpreterId ) { + return StringUtils.equals( this.interpreterId, interpreterId ); } } Modified: cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java Sun Nov 21 06:20:13 2004 @@ -1262,7 +1262,7 @@ /* TODO: Vote on the inclusion of this method public String jsFunction_getRealPath(String path) { - return context.getRealPath(path); + return context.getRealPath(path); } */ @@ -1485,6 +1485,14 @@ } /** + * Required by FOM_WebContinuation. This way we do not make whole Interpreter public + * @return interpreter Id associated with this FOM. + */ + public String getInterpreterId() { + return getInterpreter().getInterpreterID(); + } + + /** * Call the Cocoon Sitemap to process a page * @param uri Uri to match * @param bean Input to page @@ -1587,6 +1595,7 @@ wk = contMgr.createWebContinuation(unwrap(k), (parent == null ? null : parent.getWebContinuation()), timeToLive, + getInterpreter().getInterpreterID(), null); FOM_WebContinuation result = new FOM_WebContinuation(wk); result.setParentScope(getParentScope()); Modified: cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java Sun Nov 21 06:20:13 2004 @@ -371,7 +371,7 @@ /** * Associates a JavaScript scope, a Scriptable object, with - * [EMAIL PROTECTED] #getInterpreterID identifier} of this [EMAIL PROTECTED] Interpreter} + * [EMAIL PROTECTED] #getInterpreterID() identifier} of this [EMAIL PROTECTED] Interpreter} * instance. * * @param scope a <code>ThreadScope</code> value @@ -747,7 +747,7 @@ public void handleContinuation(String id, List params, Redirector redirector) throws Exception { - WebContinuation wk = continuationsMgr.lookupWebContinuation(id); + WebContinuation wk = continuationsMgr.lookupWebContinuation(id, getInterpreterID()); if (wk == null) { /* Modified: cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_WebContinuation.java ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_WebContinuation.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_WebContinuation.java Sun Nov 21 06:20:13 2004 @@ -90,6 +90,7 @@ wk = contMgr.createWebContinuation(c, (parent == null ? null : parent.getWebContinuation()), timeToLive, + cocoon.getInterpreterId(), null); result = new FOM_WebContinuation(wk); result.setParentScope(getTopLevelScope(scope)); Modified: cocoon/trunk/status.xml ============================================================================== --- cocoon/trunk/status.xml (original) +++ cocoon/trunk/status.xml Sun Nov 21 06:20:13 2004 @@ -78,6 +78,7 @@ <person name="Gerhard Froehlich" email="[EMAIL PROTECTED]" id="GF"/> <person name="Pierpaolo Fumagalli" email="[EMAIL PROTECTED]" id="PF"/> <person name="Antonio Gallardo" email="[EMAIL PROTECTED]" id="AG"/> + <person name="Leszek Gawron" email="[EMAIL PROTECTED]" id="LG"/> <person name="Ralph Goers" email="[EMAIL PROTECTED]" id="RG"/> <person name="Vadim Gritsenko" email="[EMAIL PROTECTED]" id="VG"/> <person name="Christian Haul" email="[EMAIL PROTECTED]" id="CH"/> @@ -201,6 +202,9 @@ <changes> <release version="@version@" date="@date@"> + <action dev="LG" type="fix"> + Fix: Continuation can only be invoked for the interpreter it was originally created for. + </action> <action dev="CZ" type="add" due-to="Sascha-Matthias Kulawik" due-to-email="[EMAIL PROTECTED]"> Authentication block: Add authenticator for JAAS. </action>