static void install(final Env env, final Config conf) { String path = conf.getString("crash.httpshell.path"); Router router = env.router(); router.get(path + "/{cmd:.*}", router.promise("direct", (req, deferred) -> { MediaType type = req.accepts(MediaType.json) .map(it -> MediaType.json) .orElse(MediaType.html); PluginContext ctx = req.require(PluginContext.class); ShellFactory shellFactory = ctx.getPlugin(ShellFactory.class); Shell shell = shellFactory.create(null); String cmd = req.param("cmd").value().replaceAll("/", " "); ShellProcess process = shell.createProcess(cmd); ShellProcessContext spc = new SimpleProcessContext( result -> deferred.resolve(result.type(type))); process.execute(spc); })); }
public void run() { context.process.cancel(); } };
@Override public KeyHandler getKeyHandler() { synchronized (lock) { if (status != Status.EVALUATING) { throw new IllegalStateException(); } } // Should it be synchronous or not ???? // no clue for now :-) return callee.getKeyHandler(); }
ProcessHandler context = new ProcessHandler(this, process); handler.set(context); process.execute(context); KeyHandler keyHandler = processHandler.process.getKeyHandler(); if (keyHandler != null) { KeyType type = key.map();
if (session.current.getAndSet(context) == null) { log.fine("Executing \"" + command + "\""); process.execute(context); } else { log.fine("Could not execute \"" + command + "\""); if (current != null) { log.fine("Cancelling command \"" + current.command + "\""); current.process.cancel(); } else { log.fine("No process to cancel");
ProcessHandler context = new ProcessHandler(this, process); handler.set(context); process.execute(context); KeyHandler keyHandler = processHandler.process.getKeyHandler(); if (keyHandler != null) { KeyType type = key.map();
public SSHInlineShellProcessContext execute() { process.execute(this); return this; }
callee.cancel();
if (session.current.getAndSet(context) == null) { log.fine("Executing \"" + command + "\""); process.execute(context); } else { log.fine("Could not execute \"" + command + "\""); if (current != null) { log.fine("Cancelling command \"" + current.command + "\""); current.process.cancel(); } else { log.fine("No process to cancel");
ProcessHandler context = new ProcessHandler(this, process); handler.set(context); process.execute(context); KeyHandler keyHandler = null; try { keyHandler = processHandler.process.getKeyHandler(); } catch (IllegalStateException ignored) {
@Override public void handle(KeyType type, int[] sequence) { KeyHandler keyHandler = process.getKeyHandler(); if (keyHandler != null) { CRaSHConnector.log.fine("Processing key event " + type + " " + Arrays.toString(sequence)); try { keyHandler.handle(type, sequence); } catch (Exception e) { CRaSHConnector.log.log(Level.SEVERE, "Processing key handler " + keyHandler + " threw an exception", e); } } }
public void run() { process.execute(this); }
public BaseProcessContext cancel() { process.cancel(); return this; }
public BaseProcessContext on(KeyType type, int[] sequence) { KeyHandler handler = process.getKeyHandler(); if (handler != null) { handler.handle(type, sequence); } return this; }
public BaseProcessContext execute() { process.execute(this); return this; }
public void run() { context.process.cancel(); close(); } };
@Override public KeyHandler getKeyHandler() { synchronized (lock) { if (status != Status.EVALUATING) { throw new IllegalStateException(); } } // Should it be synchronous or not ???? // no clue for now :-) return callee.getKeyHandler(); }
void execute() { try { process.execute(this); } catch(final Throwable t) { new Statement() { @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(); } }
@OnClose public void end(Session wsSession) { current.set(wsSession); try { CRaSHSession session = sessions.remove(wsSession.getId()); if (session != null) { log.fine("Destroying session " + wsSession.getId()); WSProcessContext current = session.current.getAndSet(null); if (current != null) { log.fine("Cancelling on going command " + current.command + " for " + wsSession.getId()); current.process.cancel(); } } else { log.fine("No shell session found"); } } finally { current.set(null); } }