Example usage for javax.script ScriptException printStackTrace

List of usage examples for javax.script ScriptException printStackTrace

Introduction

In this page you can find the example usage for javax.script ScriptException printStackTrace.

Prototype

public void printStackTrace(PrintStream s) 

Source Link

Document

Prints this throwable and its backtrace to the specified print stream.

Usage

From source file:com.aionemu.commons.scripting.AionScriptEngineManager.java

public void reportScriptFileError(File script, ScriptException e) {
    log.warn("Failed executing script: " + script.getPath() + ".");

    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    pw.println("Error on: " + script.getAbsolutePath());
    pw.println("Line: " + e.getLineNumber() + " - Column: " + e.getColumnNumber());
    pw.println();/*from   w w  w  .j  a  va2 s. c o m*/
    e.printStackTrace(pw);
    pw.close();

    final String report = sw.toString();

    FileOutputStream fos = null;
    try {
        String fileName = script.getName() + ".error.log";

        fos = new FileOutputStream(new File(script.getParent(), fileName));
        fos.write(report.getBytes());

        log.warn("See " + fileName + " for details.");
    } catch (IOException ioe) {
        log.warn("Additionally failed when trying to write an error report on script directory.", ioe);
        log.info(report);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:com.l2jfree.gameserver.scripting.L2ScriptEngineManager.java

public void reportScriptFileError(File script, ScriptException e) {
    _log.warn("Failed executing script: " + script.getPath() + ".");

    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    pw.println("Error on: " + script.getAbsolutePath());
    pw.println("Line: " + e.getLineNumber() + " - Column: " + e.getColumnNumber());
    pw.println();//from w w  w.  j a v a 2 s  .c  o  m
    e.printStackTrace(pw);
    pw.close();

    final String report = sw.toString();

    FileOutputStream fos = null;
    try {
        String fileName = script.getName() + ".error.log";

        fos = new FileOutputStream(new File(script.getParent(), fileName));
        fos.write(report.getBytes());

        _log.warn("See " + fileName + " for details.");
    } catch (IOException ioe) {
        _log.warn("Additionally failed when trying to write an error report on script directory.", ioe);
        _log.info(report);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:com.github.safrain.remotegsh.server.RgshFilter.java

private void performShellExecute(HttpServletRequest request, HttpServletResponse response) throws IOException {
    ShellSession session = getSession(request.getParameter("sid"));
    if (session == null) {
        response.setStatus(410);// Http status GONE
        return;//from w  w w . jav a 2s .co  m
    }
    ScriptEngine engine = session.getEngine();

    String action = request.getParameter("action");
    if (action == null) {
        StringWriter responseWriter = new StringWriter();
        engine.getContext().setWriter(responseWriter);
        engine.getContext().setErrorWriter(response.getWriter());
        String script = toString(request.getInputStream(), charset);
        JSONObject json = new JSONObject();
        try {
            try {
                Object result = engine.eval(script);
                json.put("result", String.valueOf(result));
                response.setStatus(200);
                json.put("response", responseWriter.getBuffer().toString());
            } catch (ScriptException e) {
                log.log(Level.SEVERE, "Error while running shell command:" + script, e);
                response.setStatus(500);
                e.getCause().printStackTrace(response.getWriter());
                return;
            }
        } catch (JSONException e) {
            log.log(Level.SEVERE, "Error while running shell command:" + script, e);
            response.setStatus(500);
            e.printStackTrace(response.getWriter());
            return;
        }
        response.getWriter().write(json.toString());
    } else {
        Invocable invocable = (Invocable) engine;
        try {
            invocable.invokeFunction("shellAction", action);
        } catch (ScriptException e) {
            response.setStatus(500);
            e.printStackTrace(response.getWriter());
        } catch (NoSuchMethodException e) {
            response.setStatus(500);
            response.getWriter().println("Action not supported");
        } catch (Exception e) {
            response.setStatus(500);
            e.printStackTrace(response.getWriter());
        }
    }

}