Merged V3.0 to HEAD

12185: Fix 3.0 SP1 installation on non-Oracle databases. Removed creation of indexes in AlfrescoPostCreate-2.2-MappedFKIndexes.sql that were also in AlfrescoPostCreate-2.2-Extra.sql
  12186: Performance improvements to HibernateNodeDaoServiceImpl
  12188: Multi user tests: enable graceful web script recovery on optimistic locking failure (...)
  12191: Improve Javascript execution performance in Web Scripts & Improve error presentation (...) thrown by JavaScript
  12192: Share performance improvements: stop AbstractFeedGenerator from 'choking' the repository with too many web script requests
  12193: Multi user testing: don't suppress all exceptions during Wiki Move.
  12194: Multi user testing. Don't suppress all runtime exceptions in script site node object.
  12195: Multi user testing. Convert User bean object to use a retrying transaction so that optimistic locking failures are handled.
  12196: Multi user testing: Configuration changes to support concurrent access by 20 users


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12522 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2008-12-19 17:44:01 +00:00
parent de05f999e4
commit 08676ac665
14 changed files with 287 additions and 201 deletions

View File

@@ -57,6 +57,8 @@ import org.mozilla.javascript.ImporterTopLevel;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.WrapFactory;
import org.mozilla.javascript.WrappedException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.FileCopyUtils;
/**
@@ -64,7 +66,7 @@ import org.springframework.util.FileCopyUtils;
*
* @author Kevin Roast
*/
public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcessor, ScriptResourceLoader
public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcessor, ScriptResourceLoader, InitializingBean
{
private static final Log logger = LogFactory.getLog(RhinoScriptProcessor.class);
@@ -82,6 +84,12 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
/** Store root path to resolve cm:name based scripts path from */
private String storePath;
/** Pre initialized secure scope object. */
private Scriptable secureScope;
/** Pre initialized non secure scope object. */
private Scriptable nonSecureScope;
/**
* Set the default store reference
*
@@ -340,27 +348,12 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
Context cx = Context.enter();
try
{
// The easiest way to embed Rhino is just to create a new scope this way whenever
// you need one. However, initStandardObjects is an expensive method to call and it
// allocates a fair amount of memory.
// Create a thread-specific scope from one of the shared scopes. See http://www.mozilla.org/rhino/scopes.html
cx.setWrapFactory(wrapFactory);
Scriptable scope;
if (!secure)
{
scope = cx.initStandardObjects();
// remove security issue related objects - this ensures the script may not access
// unsecure java.* libraries or import any other classes for direct access - only
// the configured root host objects will be available to the script writer
scope.delete("Packages");
scope.delete("getClass");
scope.delete("java");
}
else
{
// allow access to all libraries and objects, including the importer
// @see http://www.mozilla.org/rhino/ScriptingJava.html
scope = new ImporterTopLevel(cx);
}
Scriptable sharedScope = secure ? this.nonSecureScope : this.secureScope;
Scriptable scope = cx.newObject(sharedScope);
scope.setPrototype(sharedScope);
scope.setParentScope(null);
// there's always a model, if only to hold the util objects
if (model == null)
@@ -398,6 +391,15 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
// extract java object result if wrapped by Rhino
return valueConverter.convertValueForRepo((Serializable)result);
}
catch (WrappedException w)
{
Throwable err = w.getWrappedException();
if (err instanceof RuntimeException)
{
throw (RuntimeException) err;
}
throw new AlfrescoRuntimeException(err.getMessage(), err);
}
catch (Throwable err)
{
throw new AlfrescoRuntimeException(err.getMessage(), err);
@@ -464,4 +466,50 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
return super.wrapAsJavaObject(cx, scope, javaObject, staticType);
}
}
/**
* Pre initializes two scope objects (one secure and one not) with the standard objects preinitialised. This saves
* on very expensive calls to reinitialize a new scope on every web script execution. See
* http://www.mozilla.org/rhino/scopes.html
*
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception
{
// Initialise the secure scope
Context cx = Context.enter();
try
{
cx.setWrapFactory(wrapFactory);
this.secureScope = cx.initStandardObjects();
// remove security issue related objects - this ensures the script may not access
// unsecure java.* libraries or import any other classes for direct access - only
// the configured root host objects will be available to the script writer
this.secureScope.delete("Packages");
this.secureScope.delete("getClass");
this.secureScope.delete("java");
}
finally
{
Context.exit();
}
// Initialise the non-secure scope
cx = Context.enter();
try
{
cx.setWrapFactory(wrapFactory);
// allow access to all libraries and objects, including the importer
// @see http://www.mozilla.org/rhino/ScriptingJava.html
this.nonSecureScope = new ImporterTopLevel(cx);
}
finally
{
Context.exit();
}
}
}