Search in sources :

Example 41 with ScriptException

use of org.jaggeryjs.scriptengine.exceptions.ScriptException in project jaggery by wso2.

the class WebAppFileManager method getDirectoryPath.

@SuppressFBWarnings({ "PATH_TRAVERSAL_IN", "PATH_TRAVERSAL_IN" })
@Override
public String getDirectoryPath(String path) throws ScriptException {
    if (path.startsWith(FILE_PATH)) {
        return new JavaScriptFileManagerImpl().getFile(path).getAbsolutePath();
    }
    String oldPath = path;
    path = FilenameUtils.normalizeNoEndSeparator(path);
    if (path == null) {
        String msg = "Invalid file path : " + oldPath;
        log.error(msg);
        throw new ScriptException(msg);
    }
    File file = new File(context.getRealPath("/"), path);
    return file.getPath();
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) JavaScriptFileManagerImpl(org.jaggeryjs.hostobjects.file.JavaScriptFileManagerImpl) JavaScriptFile(org.jaggeryjs.hostobjects.file.JavaScriptFile) File(java.io.File) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 42 with ScriptException

use of org.jaggeryjs.scriptengine.exceptions.ScriptException in project jaggery by wso2.

the class JaggeryWebSocketServlet method doGet.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        CommonManager.getInstance().getEngine().enterContext();
    } catch (ScriptException e) {
        log.error(e.getMessage(), e);
        throw new ServletException(e);
    }
    WebAppManager.execute(request, response);
    JaggeryContext context = CommonManager.getJaggeryContext();
    Scriptable scope = context.getScope();
    wsMessageInBound = new WSMessageInBound((WebSocketHostObject) scope.get("webSocket", scope));
    RhinoEngine.exitContext();
    super.doGet(request, response);
}
Also used : ServletException(javax.servlet.ServletException) ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) WebSocketHostObject(org.jaggeryjs.hostobjects.web.WebSocketHostObject) JaggeryContext(org.jaggeryjs.scriptengine.engine.JaggeryContext) Scriptable(org.mozilla.javascript.Scriptable)

Example 43 with ScriptException

use of org.jaggeryjs.scriptengine.exceptions.ScriptException in project jaggery by wso2.

the class CacheManager method cacheScript.

public synchronized void cacheScript(Reader scriptReader, ScriptCachingContext sctx) throws ScriptException {
    if (scriptReader == null) {
        String msg = "Unable to find the Reader for script source in CachingContext";
        log.error(msg);
        throw new ScriptException(msg);
    }
    String className;
    TenantWrapper tenant = initContexts(sctx);
    CachingContext ctx = getCachingContext(sctx);
    if (ctx != null) {
        if (sctx.getSourceModifiedTime() <= ctx.getSourceModifiedTime()) {
            return;
        }
        className = ctx.getClassName();
        invalidateCache(sctx);
        ctx.setSourceModifiedTime(0L);
        ctx.setCacheUpdatedTime(0L);
    } else {
        className = getClassName(tenant, sctx);
        ctx = new CachingContext(sctx.getContext(), sctx.getPath(), sctx.getCacheKey());
        ctx.setTenantId(sctx.getTenantDomain());
        ctx.setContext(sctx.getContext());
        ctx.setPath(sctx.getPath());
        ctx.setCacheKey(sctx.getCacheKey());
        ctx.setClassName(className);
    }
    try {
        String scriptPath = sctx.getContext() + sctx.getPath() + sctx.getCacheKey();
        Object[] compiled = compiler.compileToClassFiles(HostObjectUtil.readerToString(scriptReader), scriptPath, 1, className);
        ctx.setScript(getScriptObject(compiled, sctx));
        ctx.setCacheUpdatedTime(System.currentTimeMillis());
        ctx.setSourceModifiedTime(sctx.getSourceModifiedTime());
        tenant.setCachingContext(ctx);
    } catch (Exception e) {
        throw new ScriptException(e);
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException)

Example 44 with ScriptException

use of org.jaggeryjs.scriptengine.exceptions.ScriptException in project jaggery by wso2.

the class CacheManager method getScriptObject.

private Script getScriptObject(Object[] compiled, ScriptCachingContext sctx) throws ScriptException {
    String className = (String) compiled[0];
    byte[] classBytes = (byte[]) compiled[1];
    ClassLoader rhinoLoader = getClass().getClassLoader();
    GeneratedClassLoader loader;
    try {
        loader = SecurityController.createLoader(rhinoLoader, sctx.getSecurityDomain());
        Class cl = loader.defineClass(className, classBytes);
        loader.linkClass(cl);
        return (Script) cl.newInstance();
    } catch (SecurityException e) {
        throw new ScriptException(e);
    } catch (IllegalArgumentException e) {
        throw new ScriptException(e);
    } catch (InstantiationException e) {
        throw new ScriptException(e);
    } catch (IllegalAccessException e) {
        throw new ScriptException(e);
    }
}
Also used : Script(org.mozilla.javascript.Script) ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) GeneratedClassLoader(org.mozilla.javascript.GeneratedClassLoader) GeneratedClassLoader(org.mozilla.javascript.GeneratedClassLoader)

Example 45 with ScriptException

use of org.jaggeryjs.scriptengine.exceptions.ScriptException in project jaggery by wso2.

the class UploadedFile method close.

@Override
public void close() throws ScriptException {
    if (!opened) {
        return;
    }
    try {
        stream.close();
        opened = false;
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw new ScriptException(e);
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException)

Aggregations

ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)83 IOException (java.io.IOException)15 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)13 ScriptableObject (org.mozilla.javascript.ScriptableObject)12 RegistryException (org.wso2.carbon.registry.api.RegistryException)11 ScriptReader (org.jaggeryjs.jaggery.core.ScriptReader)9 URL (java.net.URL)8 JaggeryContext (org.jaggeryjs.scriptengine.engine.JaggeryContext)8 MalformedURLException (java.net.MalformedURLException)7 ServletContext (javax.servlet.ServletContext)6 ScriptCachingContext (org.jaggeryjs.scriptengine.cache.ScriptCachingContext)6 RhinoEngine (org.jaggeryjs.scriptengine.engine.RhinoEngine)5 Context (org.mozilla.javascript.Context)5 File (java.io.File)4 StringReader (java.io.StringReader)4 Callable (java.util.concurrent.Callable)4 ExecutorService (java.util.concurrent.ExecutorService)4 FileItem (org.apache.commons.fileupload.FileItem)4 FileHostObject (org.jaggeryjs.hostobjects.file.FileHostObject)4 StreamHostObject (org.jaggeryjs.hostobjects.stream.StreamHostObject)4