Package org.apache.sshd.server

Examples of org.apache.sshd.server.Command


    sshd.setShellFactory(new Factory<Command>() {

      @Override
      public Command create() {

        return new Command() {

          private InputStream in;
          private OutputStream out;
          private Shell shell;
          private ExitCallback ec;
View Full Code Here


        }

        Cmdlet cmdlet = null;
        try {
            cmdlet = buildCommand(tokens);
            Command command = parseCommand(cmdlet, tokens);
            return command;
        } catch (CmdLineException e) {
            Command command = new PrintErrorCommand(e.getMessage(), cmdlet);
            return command;
        } catch (Exception e) {
            log.warn("Error building command for line: " + line, e);
            Command command = new PrintErrorCommand("Error building command for line: " + line, cmdlet);
            return command;
        }
    }
View Full Code Here

    return r.toString();
  }

  @Override
  public void destroy() {
    Command cmd = atomicCmd.getAndSet(null);
    if (cmd != null) {
        cmd.destroy();
    }
  }
View Full Code Here

            (getName().isEmpty() ? "Gerrit Code Review" : getName()) + ": "
                + commandName + ": not found";
        throw new UnloggedFailure(1, msg);
      }

      final Command cmd = p.get();
      checkRequiresCapability(cmd);
      if (cmd instanceof BaseCommand) {
        final BaseCommand bc = (BaseCommand) cmd;
        if (getName().isEmpty())
          bc.setName(commandName);
        else
          bc.setName(getName() + " " + commandName);
        bc.setArguments(args.toArray(new String[args.size()]));

      } else if (!args.isEmpty()) {
        throw new UnloggedFailure(1, commandName + " does not take arguments");
      }

      provideStateTo(cmd);
      atomicCmd.set(cmd);
      cmd.start(env);

    } catch (UnloggedFailure e) {
      String msg = e.getMessage();
      if (!msg.endsWith("\n")) {
        msg += "\n";
View Full Code Here

    }
  }

  @Override
  public void destroy() {
    Command cmd = atomicCmd.getAndSet(null);
    if (cmd != null) {
        cmd.destroy();
    }
  }
View Full Code Here

      Provider<? extends Command> p = map.get(name);
      if (p == null) {
        throw new UnloggedFailure(1, getName() + ": not found");
      }

      Command cmd = p.get();
      if (!(cmd instanceof DispatchCommand)) {
        throw new UnloggedFailure(1, getName() + ": not found");
      }
      map = ((DispatchCommand) cmd).getMap();
    }

    Provider<? extends Command> p = map.get(command.value());
    if (p == null) {
      throw new UnloggedFailure(1, getName() + ": not found");
    }

    Command cmd = p.get();
    checkRequiresCapability(cmd);
    if (cmd instanceof BaseCommand) {
      BaseCommand bc = (BaseCommand)cmd;
      bc.setName(getName());
      bc.setArguments(getArguments());
    }
    provideStateTo(cmd);
    atomicCmd.set(cmd);
    cmd.start(env);
  }
View Full Code Here

    cmd.start(env);
  }

  @Override
  public void destroy() {
    Command cmd = atomicCmd.getAndSet(null);
    if (cmd != null) {
        cmd.destroy();
    }
  }
View Full Code Here

    //
    log.log(Level.FINE, "About to execute shell command " + command);

    for (CommandPlugin plugin : pluginContext.getPlugins(CommandPlugin.class)) {
      Command cmd = plugin.createCommand(command);
      if (cmd != null) {
        return cmd;
      }
    }
View Full Code Here

        prepareServer(true);
        server.start();
        try {
            org.apache.sshd.SshServer sshd = (org.apache.sshd.SshServer) ReflectionTestUtils.getField(server, "sshd");
            CommandFactory fact = sshd.getCommandFactory();
            Command cmd = fact.createCommand("shutdown now");
            assertTrue(cmd instanceof SshCommand);
            assertEquals(((SshCommand) cmd).getCommand(),"shutdown now");
        } finally {
            server.stop();
        }
View Full Code Here

            (prefix.isEmpty() ? "Gerrit Code Review" : prefix) + ": "
                + commandName + ": not found";
        throw new UnloggedFailure(1, msg);
      }

      final Command cmd = p.get();

      if (isAdminCommand(cmd) && !currentUser.get().isAdministrator()) {
        final String msg = "fatal: Not a Gerrit administrator";
        throw new UnloggedFailure(BaseCommand.STATUS_NOT_ADMIN, msg);
      }

      if (cmd instanceof BaseCommand) {
        final BaseCommand bc = (BaseCommand) cmd;
        if (prefix.isEmpty())
          bc.setName(commandName);
        else
          bc.setName(prefix + " " + commandName);
        bc.setArguments(args.toArray(new String[args.size()]));

      } else if (!args.isEmpty()) {
        throw new UnloggedFailure(1, commandName + " does not take arguments");
      }

      provideStateTo(cmd);

      synchronized (this) {
        this.cmd = cmd;
      }
      cmd.start(env);

    } catch (UnloggedFailure e) {
      String msg = e.getMessage();
      if (!msg.endsWith("\n")) {
        msg += "\n";
View Full Code Here

TOP

Related Classes of org.apache.sshd.server.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.