@Override public void end(final ShellResponse response) { Status status = Status.SERVER_ERROR; if (response instanceof ShellResponse.Ok) { status = Status.OK; } else if (response instanceof ShellResponse.UnknownCommand) { status = Status.BAD_REQUEST; } deferred.accept(Results.with(buff.length() == 0 ? response.getMessage() : buff, status)); }
protected ShellResponse execute(String request) { return ShellResponse.ok(); }
public ShellProcess createProcess(String request) { log.log(Level.FINE, "Invoking request " + request); String trimmedRequest = request.trim(); final StringBuilder msg = new StringBuilder(); final ShellResponse response; if ("bye".equals(trimmedRequest) || "exit".equals(trimmedRequest)) { response = ShellResponse.close(); } else { ReplResponse r = repl.eval(this, request); if (r instanceof ReplResponse.Response) { ReplResponse.Response rr = (ReplResponse.Response)r; response = rr.response; } else { final CommandInvoker<Void, ?> pipeLine = ((ReplResponse.Invoke)r).invoker; return new CRaSHCommandProcess(this, request, pipeLine); } } return new CRaSHResponseProcess(this, request, msg, response); }
case CANCELED: response = ShellResponse.cancelled(); break; case QUEUED: response = ShellResponse.ok(); response = ShellResponse.internalError("Unexpected throwable when executing process", t);
resp = ShellResponse.cancelled(); resp = ShellResponse.internalError("Unexpected error when executing process", t); } finally { thread = null;
public ReplResponse eval(ShellSession session, String request) { PipeLineFactory factory; try { factory = Token.parse(request).createFactory(); } catch (CommandException e) { return new ReplResponse.Response(ShellResponse.error(e.getErrorKind(), e.getMessage(), e.getCause())); } if (factory != null) { try { CommandInvoker<Void, Object> invoker = factory.create(session); return new ReplResponse.Invoke(invoker); } catch (CommandNotFoundException e) { log.log(Level.FINER, "Could not create command", e); return new ReplResponse.Response(ShellResponse.unknownCommand(e.getName())); } catch (CommandException e) { log.log(Level.FINER, "Could not create command", e); return new ReplResponse.Response(ShellResponse.error(e.getErrorKind(), e.getMessage(), e)); } } else { return new ReplResponse.Response(ShellResponse.noCommand()); } }
final ShellResponse response; if ("bye".equals(request) || "exit".equals(request)) { response = ShellResponse.close(); } else { response = ShellResponse.unknownCommand(e.getCommandName()); response = ShellResponse.noCommand();
@Override protected void run() throws Throwable { // If it's not executing then we attempt to end it end(ShellResponse.error(ErrorKind.INTERNAL, "Unexpected process execution error", t)); } }.all();
public void end(ShellResponse response) { // Always leave the status in terminated status if the method succeeds // Cancelled -> Terminated // Evaluating -> Terminated // Terminated -> Terminated synchronized (lock) { switch (status) { case CONSTRUCTED: case QUEUED: throw new AssertionError("Should not happen"); case CANCELED: // We substitute the response response = ShellResponse.cancelled(); status = Status.TERMINATED; break; case EVALUATING: status = Status.TERMINATED; break; case TERMINATED: throw new IllegalStateException("Cannot end a process already terminated"); } } // caller.end(response); } };
processContext.flush(); } else { response = ShellResponse.internalError("Unexpected"); response = ShellResponse.internalError("Remoting issue", e); processContext.end(response); } else { processContext.end(ShellResponse.internalError(""));
case CANCELED: response = ShellResponse.cancelled(); break; case QUEUED: response = ShellResponse.ok(); response = ShellResponse.internalError("Unexpected throwable when executing process", t);
public ReplResponse eval(ShellSession session, String request) { PipeLineFactory factory; try { factory = Token.parse(request).createFactory(); } catch (CommandException e) { return new ReplResponse.Response(ShellResponse.error(e.getErrorKind(), e.getMessage(), e.getCause())); } if (factory != null) { try { CommandInvoker<Void, Object> invoker = factory.create(session); return new ReplResponse.Invoke(invoker); } catch (CommandNotFoundException e) { log.log(Level.FINER, "Could not create command", e); return new ReplResponse.Response(ShellResponse.unknownCommand(e.getName())); } catch (CommandException e) { log.log(Level.FINER, "Could not create command", e); return new ReplResponse.Response(ShellResponse.error(e.getErrorKind(), e.getMessage(), e)); } } else { return new ReplResponse.Response(ShellResponse.noCommand()); } }
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { if (ois.readBoolean()) { response = (ShellResponse)ois.readObject(); } else { ErrorKind type = (ErrorKind)ois.readObject(); String message = (String)ois.readObject(); String errorMessage = (String)ois.readObject(); StackTraceElement[] errorTrace = (StackTraceElement[])ois.readObject(); Exception ex = new Exception(errorMessage); ex.setStackTrace(errorTrace); response = ShellResponse.error(type, message, ex); } } }
resp = ShellResponse.cancelled(); resp = ShellResponse.internalError("Unexpected error when executing process", t); } finally { thread = null;
caller.end(ShellResponse.cancelled());
processContext.flush(); } else { response = ShellResponse.internalError("Unexpected"); response = ShellResponse.internalError("Remoting issue", e); processContext.end(response); } else { processContext.end(ShellResponse.internalError(""));
public void end(ShellResponse response) { CRaSHConnector.log.fine("Ended \"" + command + "\""); session.current.compareAndSet(this, null); flush(); String msg = response.getMessage(); if (msg.length() > 0) { session.send("print", msg); } String prompt = session.shell.getPrompt(); session.send("prompt", prompt); session.send("end"); }
@Override public void run(String request, ShellProcessContext context) throws Exception { context.end(ShellResponse.ok()); } });
case CANCELED: response = ShellResponse.cancelled(); break; case QUEUED: response = ShellResponse.ok(); response = ShellResponse.internalError("Unexpected throwable when executing process", t);
public ReplResponse eval(ShellSession session, String request) { PipeLineFactory factory; try { factory = Token.parse(request).createFactory(); } catch (CommandException e) { return new ReplResponse.Response(ShellResponse.error(e.getErrorKind(), e.getMessage(), e.getCause())); } if (factory != null) { try { CommandInvoker<Void, Object> invoker = factory.create(session); return new ReplResponse.Invoke(invoker); } catch (CommandNotFoundException e) { log.log(Level.FINER, "Could not create command", e); return new ReplResponse.Response(ShellResponse.unknownCommand(e.getName())); } catch (CommandException e) { log.log(Level.FINER, "Could not create command", e); return new ReplResponse.Response(ShellResponse.error(e.getErrorKind(), e.getMessage(), e)); } } else { return new ReplResponse.Response(ShellResponse.noCommand()); } }