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 init() { try { ShellFactory factory = context.getPlugin(ShellFactory.class);
public void onOpen(final Request req, final WebSocket ws) throws Exception { PluginContext ctx = req.require(PluginContext.class); ShellFactory factory = ctx.getPlugin(ShellFactory.class); Shell shell = factory.create(null);
public void init() { try { ShellFactory factory = context.getPlugin(ShellFactory.class);
@Override public void init() { this.factory = getContext().getPlugin(ShellFactory.class); }
ShellFactory factory = getContext().getPlugin(ShellFactory.class); TaskTable table = new TaskTable(); for (String cronLine : lines) {
@OnOpen public void start(Session wsSession) { current.set(wsSession); try { URI uri = wsSession.getRequestURI(); String path = uri.getPath(); log.fine("Establishing session for " + path); String contextPath = path.substring(0, path.lastIndexOf('/')); PluginContext context = WebPluginLifeCycle.getPluginContext(contextPath); if (context != null) { Boolean enabled = context.getProperty(WebPlugin.ENABLED); if (enabled != null && enabled) { log.fine("Using shell " + context); ShellFactory factory = context.getPlugin(ShellFactory.class); Principal user = wsSession.getUserPrincipal(); Shell shell = factory.create(user); CRaSHSession session = new CRaSHSession(wsSession, shell); sessions.put(wsSession.getId(), session); log.fine("Established session " + wsSession.getId()); } else { log.fine("Web plugin disabled"); } } else { log.fine("No shell found"); } } finally { current.set(null); } }
Shell shell = pluginContext.getPlugin(ShellFactory.class).create(user); ShellProcess shellProcess = shell.createProcess(command);
ShellFactory factory = bootstrap.getContext().getPlugin(ShellFactory.class); shell = factory.create(null); } else {
protected void execute(TestPluginLifeCycle lifeCycle, Wiser wiser) throws IOException, MessagingException, ExecutionException, InterruptedException { MailPlugin plugin = lifeCycle.getContext().getPlugin(MailPlugin.class); Future<Boolean> future = send(plugin); assertResponse(wiser, future); }
ShellFactory factory = bootstrap.getContext().getPlugin(ShellFactory.class); Shell shell = factory.create(null); RemoteClient client = new RemoteClient(port, shell);
public void testCron() throws Exception { Support support = new Support("* * * * * foobar toto"); support.lifecycle.bindGroovy("foobar", "" + "public class foobar {\n" + "@Command\n" + "public void main(@Argument String arg) {\n" + CrontabTestCase.class.getName() + ".countDown(arg);\n" + "}\n" + "}\n" ); CronPlugin plugin = support.lifecycle.getContext().getPlugin(CronPlugin.class); assertNotNull(plugin); assertTrue(plugin.spawn()); while (latch.getCount() == 2) { // Do nothing } Logger.getLogger(CrontabTestCase.class.getName()).log(Level.FINE, "Checking cron history"); assertEquals(1, plugin.getHistory().size()); CRaSHTaskProcess process = plugin.getHistory().peek(); assertEquals("foobar toto", process.getLine()); assertEquals("* * * * *", process.getSchedulingPattern().toString()); assertTrue(plugin.spawn()); assertTrue(latch.await(10, TimeUnit.SECONDS)); assertEquals(Arrays.asList("toto", "toto"), queue); assertEquals(2, plugin.getHistory().size()); } }
@Override public void init() { this.factory = getContext().getPlugin(ShellFactory.class); }
@Override public void init() { this.factory = getContext().getPlugin(ShellFactory.class); }
public void testFoo() throws Exception { URL xml = SpringTestCase.class.getResource("spring.xml"); Assert.assertNotNull(xml); // GenericXmlApplicationContext context = new GenericXmlApplicationContext(new UrlResource(xml)); context.start(); // SpringBootstrap bootstrap = context.getBean(SpringBootstrap.class); // Test a bit ShellFactory factory = bootstrap.getContext().getPlugin(ShellFactory.class); Shell shell = factory.create(null); assertNotNull(shell); ShellProcess process = shell.createProcess("foo_cmd"); assertNotNull(process); BaseProcessContext pc = BaseProcessContext.create(process).execute(); assertTrue(pc.getResponse() instanceof ShellResponse.Ok); String r = pc.getOutput(); assertEquals("bar", r); } }
@OnOpen public void start(Session wsSession) { current.set(wsSession); try { URI uri = wsSession.getRequestURI(); String path = uri.getPath(); log.fine("Establishing session for " + path); String contextPath = path.substring(0, path.lastIndexOf('/')); PluginContext context = WebPluginLifeCycle.getPluginContext(contextPath); if (context != null) { Boolean enabled = context.getProperty(WebPlugin.ENABLED); if (enabled != null && enabled) { log.fine("Using shell " + context); ShellFactory factory = context.getPlugin(ShellFactory.class); Principal user = wsSession.getUserPrincipal(); Shell shell = factory.create(user); CRaSHSession session = new CRaSHSession(wsSession, shell); sessions.put(wsSession.getId(), session); log.fine("Established session " + wsSession.getId()); } else { log.fine("Web plugin disabled"); } } else { log.fine("No shell found"); } } finally { current.set(null); } }
Shell shell = pluginContext.getPlugin(ShellFactory.class).create(user); ShellProcess shellProcess = shell.createProcess(command);
Shell shell = pluginContext.getPlugin(ShellFactory.class).create(user); ShellProcess shellProcess = shell.createProcess(command);
ShellFactory factory = bootstrap.getContext().getPlugin(ShellFactory.class); Shell shell = factory.create(null); RemoteClient client = new RemoteClient(port, shell);
ShellFactory factory = bootstrap.getContext().getPlugin(ShellFactory.class); Shell shell = factory.create(null, null); RemoteClient client = new RemoteClient(port, shell);