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();
}
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);
}
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);
}
}
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);
}
}
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);
}
}
Aggregations