Search in sources :

Example 31 with ScriptException

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

the class WebAppFile method readAll.

@Override
public String readAll() throws ScriptException {
    if (!opened) {
        log.warn("You need to open the file for reading");
        return null;
    }
    if (!readable) {
        log.warn("File has not opened in a readable mode.");
        return null;
    }
    try {
        long pointer = file.getFilePointer();
        file.seek(0);
        String data = read(file.length());
        file.seek(pointer);
        return data;
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw new ScriptException(e);
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException)

Example 32 with ScriptException

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

the class WebAppFile method read.

@Override
public String read(long count) throws ScriptException {
    if (!opened) {
        log.warn("You need to open the file for reading");
        return null;
    }
    if (!readable) {
        log.warn("File has not opened in a readable mode.");
        return null;
    }
    try {
        byte[] arr = new byte[(int) min(count, file.length())];
        file.readFully(arr);
        return new String(arr, "UTF-8");
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw new ScriptException(e);
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException)

Example 33 with ScriptException

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

the class ResponseHostObject method jsFunction_sendRedirect.

@SuppressFBWarnings("UNVALIDATED_REDIRECT")
public static void jsFunction_sendRedirect(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws ScriptException {
    String functionName = "sendRedirect";
    int argsCount = args.length;
    if (argsCount != 1) {
        HostObjectUtil.invalidNumberOfArgs(hostObjectName, functionName, argsCount, false);
    }
    if (!(args[0] instanceof String)) {
        HostObjectUtil.invalidArgsError(hostObjectName, functionName, "1", "string", args[0], false);
    }
    ResponseHostObject rho = (ResponseHostObject) thisObj;
    try {
        rho.response.sendRedirect((String) args[0]);
    } catch (IOException e) {
        String msg = "Error sending redirect : " + args[0];
        log.warn(msg, e);
        throw new ScriptException(msg, e);
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) IOException(java.io.IOException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 34 with ScriptException

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

the class ResponseHostObject method jsSet_content.

public void jsSet_content(Object object) throws ScriptException {
    try {
        String content = HostObjectUtil.serializeObject(object);
        response.getOutputStream().write(content.getBytes("UTF-8"));
    } catch (IOException e) {
        String msg = "Error occurred while reading Servlet OutputStream";
        log.error(msg, e);
        throw new ScriptException(msg, e);
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) IOException(java.io.IOException)

Example 35 with ScriptException

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

the class RegistryHostObject method jsFunction_newResource.

public static Scriptable jsFunction_newResource(Context cx, Scriptable thisObj, Object[] arguments, Function funObj) throws ScriptException {
    RegistryHostObject registryHostObject = (RegistryHostObject) thisObj;
    if (arguments.length == 0) {
        if (registryHostObject.registry != null) {
            try {
                Resource resource = registryHostObject.registry.newResource();
                ResourceHostObject rho = (ResourceHostObject) cx.newObject(registryHostObject, "Resource", new Object[] { resource });
                return rho;
            } catch (RegistryException e) {
                throw new ScriptException("Error occurred while creating a new Resource", e);
            }
        } else {
            throw new ScriptException("Registry has not initialized");
        }
    } else {
        throw new ScriptException("newResource() Method doesn't accept arguments");
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) RegistryException(org.wso2.carbon.registry.api.RegistryException)

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