@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)); }
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); })); }
import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; public class SWTFileOpenSnippet { public static void main (String [] args) { Display display = new Display (); Shell shell = new Shell (display); // Don't show the shell. //shell.open (); FileDialog dialog = new FileDialog (shell, SWT.OPEN | SWT.MULTI); String [] filterNames = new String [] {"All Files (*)"}; String [] filterExtensions = new String [] {"*"}; String filterPath = "c:\\"; dialog.setFilterNames (filterNames); dialog.setFilterExtensions (filterExtensions); dialog.setFilterPath (filterPath); dialog.open(); System.out.println ("Selected files: "); String[] selectedFileNames = dialog.getFileNames(); for(String fileName : selectedFileNames) { System.out.println(" " + fileName); } shell.close(); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); } }
PluginContext ctx = req.require(PluginContext.class); ShellFactory factory = ctx.getPlugin(ShellFactory.class); Shell shell = factory.create(null); case "welcome": log.debug("sending welcome + prompt"); ws.send(event("print", shell.getWelcome())); ws.send(event("prompt", shell.getPrompt())); break; case "execute": Integer width = (Integer) event.get("width"); Integer height = (Integer) event.get("height"); process.set(shell.createProcess(command)); SimpleProcessContext context = new SimpleProcessContext(r -> { Try.run(() -> { ws.send(event("prompt", shell.getPrompt())); ws.send(event("end")); }).onFailure(x -> log.error("error found while sending output", x)); process.get().execute(context); break; case "cancel": if (p != null) { log.info("cancelling {}", p); p.cancel();
protected final Throwable assertError(String s, ErrorKind expectedErrorType) { ShellResponse resp = evaluate(s); ShellResponse.Error error = assertInstance(ShellResponse.Error.class, resp); assertEquals(expectedErrorType, error.getKind()); return error.getThrowable(); }
public void testPromptNoClosure() { Object prompt = session.remove("prompt"); try { String s = shell.getPrompt(); assertNotNull(s); } finally { session.put("prompt", prompt); } } }
@Override public Screenable append(char c) throws IOException { caller.append(c); return this; }
protected final void assertUnknownCommand(String s) { ShellResponse resp = evaluate(s); assertTrue("Was expecting an ok response instead of " + resp, resp instanceof ShellResponse.UnknownCommand); assertEquals(s, ((ShellResponse.UnknownCommand)resp).getName()); }
@Override protected void tearDown() throws Exception { if (shell != null) { shell.close(); shell = null; groovyShell = null; } }
@Override public Screenable append(CharSequence csq, int start, int end) throws IOException { caller.append(csq, start, end); return this; }