Examples of CommandSession


Examples of org.apache.felix.service.command.CommandSession

    }

    public void start(final Environment env) throws IOException {
        int exitStatus = 0;
        try {
            final CommandSession session = commandProcessor.createSession(in, new PrintStream(out), new PrintStream(err));
            session.put("SCOPE", "shell:osgi:*");
            session.put("APPLICATION", System.getProperty("karaf.name", "root"));
            for (Map.Entry<String,String> e : env.getEnv().entrySet()) {
                session.put(e.getKey(), e.getValue());
            }
            try {
                Subject subject = this.session != null ? this.session.getAttribute(KarafJaasAuthenticator.SUBJECT_ATTRIBUTE_KEY) : null;
                Object result;
                if (subject != null) {
                    try {
                        String scriptFileName = System.getProperty(SHELL_INIT_SCRIPT);
                        executeScript(scriptFileName, session);
                        result = JaasHelper.doAs(subject, new PrivilegedExceptionAction<Object>() {
                            public Object run() throws Exception {
                                return session.execute(command);
                            }
                        });
                    } catch (PrivilegedActionException e) {
                        throw e.getException();
                    }
                } else {
                    String scriptFileName = System.getProperty(SHELL_INIT_SCRIPT);
                    executeScript(scriptFileName, session);
                    result = session.execute(command);
                }
                if (result != null)
                {
                    session.getConsole().println(session.format(result, Converter.INSPECT));
                }
            } catch (Throwable t) {
                exitStatus = 1;
                ShellUtil.logException(session, t);
            }
View Full Code Here

Examples of org.apache.felix.service.command.CommandSession

    public static boolean showHiddenComponent(Component component) {
        boolean answer = false;
        // first look to see if the show all option is there
        // if it is we set showAllFlag to true so the next section will be skipped
        CommandSession commandSession = CommandSessionHolder.getSession();
        ArgumentCompleter.ArgumentList list = (ArgumentCompleter.ArgumentList) commandSession.get(ArgumentCompleter.ARGUMENTS_LIST);
        if (list != null && list.getArguments() != null && list.getArguments().length > 0) {
            List<String> arguments = Arrays.asList(list.getArguments());
            if (arguments.contains(ScrActionSupport.SHOW_ALL_OPTION) || arguments.contains(ScrActionSupport.SHOW_ALL_ALIAS)) {
                answer = true;
            }
View Full Code Here

Examples of org.apache.felix.service.command.CommandSession

    @Override
    public Console create(CommandProcessor processor, ThreadIO threadIO, InputStream in, PrintStream out, PrintStream err, final Terminal terminal,
            String encoding, Runnable closeCallback) {
        ConsoleImpl console = new ConsoleImpl(processor, threadIO, in, out, err, terminal, encoding, closeCallback, bundleContext);
        CommandSession session = console.getSession();
        session.put("APPLICATION", System.getProperty("karaf.name", "root"));
        session.put("#LINES", new Function() {
            public Object execute(CommandSession session, List<Object> arguments) throws Exception {
                return Integer.toString(terminal.getHeight());
            }
        });
        session.put("#COLUMNS", new Function() {
            public Object execute(CommandSession session, List<Object> arguments) throws Exception {
                return Integer.toString(terminal.getWidth());
            }
        });
        session.put(".jline.terminal", terminal);
        addSystemProperties(session);
        return console;
    }
View Full Code Here

Examples of org.apache.felix.service.command.CommandSession

        final String userName = getUserName(subject);
        new Thread(console, "Karaf Console " + consoleType + " user " + userName) {
            @Override
            public void run() {
                if (subject != null) {
                    CommandSession session = console.getSession();
                    session.put("USER", userName);
                    JaasHelper.doAs(subject, new PrivilegedAction<Object>() {
                        public Object run() {
                            doRun();
                            return null;
                        }
View Full Code Here

Examples of org.apache.felix.service.command.CommandSession

        }
        DelegateSession is = (DelegateSession) session;

        // make it active
        SecuredCommandProcessorImpl secCP = new SecuredCommandProcessorImpl(bundleContext);
        CommandSession s = secCP.createSession(consoleInput, out, err);

        // before the session is activated attributes may have been set on it. Pass these on to the real session now
        is.setDelegate(s);
        return secCP;
    }
View Full Code Here

Examples of org.apache.felix.service.command.CommandSession

                                    public void run() {
                                        ShellImpl.this.destroy();
                                    }
                                },
                                bundleContext);
                        final CommandSession session = console.getSession();
                        session.put("APPLICATION", System.getProperty("karaf.name", "root"));
                        for (Map.Entry<String,String> e : env.getEnv().entrySet()) {
                            session.put(e.getKey(), e.getValue());
                        }
                        session.put("#LINES", new Function() {
                            public Object execute(CommandSession session, List<Object> arguments) throws Exception {
                                return Integer.toString(terminal.getHeight());
                            }
                        });
                        session.put("#COLUMNS", new Function() {
                            public Object execute(CommandSession session, List<Object> arguments) throws Exception {
                                return Integer.toString(terminal.getWidth());
                            }
                        });
                        session.put(".jline.terminal", terminal);
                        console.run();
                    } catch (Exception e) {
                        LOGGER.warn("Unable to start shell", e);
                    }
                }
View Full Code Here

Examples of org.apache.felix.service.command.CommandSession

                                   wrap(err),
                                   terminal,
                                   encoding,
                                   callback,
                                   bundleContext);
        CommandSession session = console.getSession();
        for (Object o : System.getProperties().keySet()) {
            String key = o.toString();
            session.put(key, System.getProperty(key));
        }
        session.put("USER", user);
        session.put("APPLICATION", System.getProperty("karaf.name", "root"));
        session.put("#LINES", new Function() {
            public Object execute(CommandSession session, List<Object> arguments) throws Exception {
                return Integer.toString(terminal.getHeight());
            }
        });
        session.put("#COLUMNS", new Function() {
            public Object execute(CommandSession session, List<Object> arguments) throws Exception {
                return Integer.toString(terminal.getWidth());
            }
        });
        if (ctype != null) {
            session.put("LC_CTYPE", ctype);
        }
        session.put(".jline.terminal", terminal);
        session.put("pid", getPid());

        registration = bundleContext.registerService(CommandSession.class, session, null);

        boolean delayconsole = Boolean.parseBoolean(System.getProperty("karaf.delay.console"));
        if (delayconsole) {
View Full Code Here

Examples of org.apache.felix.service.command.CommandSession

                        pipedOut,
                        new WebTerminal(TERM_WIDTH, TERM_HEIGHT),
                        null,
                        null,
                        bundleContext);
                CommandSession session = console.getSession();
                session.put("APPLICATION", System.getProperty("karaf.name", "root"));
                session.put("USER", "karaf");
                session.put("COLUMNS", Integer.toString(TERM_WIDTH));
                session.put("LINES", Integer.toString(TERM_HEIGHT));
            } catch (IOException e) {
                e.printStackTrace();
                throw e;
            } catch (Exception e) {
                e.printStackTrace();
View Full Code Here

Examples of org.apache.felix.service.command.CommandSession

        }

        public void start(final Environment env) throws IOException {
            int exitStatus = 0;
            try {
                final CommandSession session = commandProcessor.createSession(in, new PrintStream(out), new PrintStream(err));
                session.put("SCOPE", "shell:osgi:*");
                session.put("APPLICATION", System.getProperty("karaf.name", "root"));
                for (Map.Entry<String,String> e : env.getEnv().entrySet()) {
                    session.put(e.getKey(), e.getValue());
                }
                try {
                    Subject subject = this.session != null ? this.session.getAttribute(KarafJaasAuthenticator.SUBJECT_ATTRIBUTE_KEY) : null;
                    Object result;
                    if (subject != null) {
                        try {
                            String scriptFileName = System.getProperty(SHELL_INIT_SCRIPT);
                            executeScript(scriptFileName, session);
                            result = JaasHelper.doAs(subject, new PrivilegedExceptionAction<Object>() {
                                public Object run() throws Exception {
                                    return session.execute(command);
                                }
                            });
                        } catch (PrivilegedActionException e) {
                            throw e.getException();
                        }
                    } else {
                        String scriptFileName = System.getProperty(SHELL_INIT_SCRIPT);
                        executeScript(scriptFileName, session);
                        result = session.execute(command);
                    }
                    if (result != null)
                    {
                        session.getConsole().println(session.format(result, Converter.INSPECT));
                    }
                } catch (Throwable t) {
                    exitStatus = 1;
                    try {
                        boolean isCommandNotFound = "org.apache.felix.gogo.runtime.CommandNotFoundException".equals(t.getClass().getName());
                        if (isCommandNotFound) {
                            LOGGER.debug("Unknown command entered", t);
                        } else {
                            LOGGER.info("Exception caught while executing command", t);
                        }
                        session.put(Console.LAST_EXCEPTION, t);
                        if (t instanceof CommandException) {
                            session.getConsole().println(((CommandException) t).getNiceHelp());
                        } else if (isCommandNotFound) {
                            String str = Ansi.ansi()
                                    .fg(Ansi.Color.RED)
                                    .a("Command not found: ")
                                    .a(Ansi.Attribute.INTENSITY_BOLD)
                                    .a(t.getClass().getMethod("getCommand").invoke(t))
                                    .a(Ansi.Attribute.INTENSITY_BOLD_OFF)
                                    .fg(Ansi.Color.DEFAULT).toString();
                            session.getConsole().println(str);
                        }
                        if (getBoolean(session, Console.PRINT_STACK_TRACES)) {
                            session.getConsole().print(Ansi.ansi().fg(Ansi.Color.RED).toString());
                            t.printStackTrace(session.getConsole());
                            session.getConsole().print(Ansi.ansi().fg(Ansi.Color.DEFAULT).toString());
                        }
                        else if (!(t instanceof CommandException) && !isCommandNotFound) {
                            session.getConsole().print(Ansi.ansi().fg(Ansi.Color.RED).toString());
                            session.getConsole().println("Error executing command: "
                                    + (t.getMessage() != null ? t.getMessage() : t.getClass().getName()));
                            session.getConsole().print(Ansi.ansi().fg(Ansi.Color.DEFAULT).toString());
                        }
                        session.getConsole().flush();
                    } catch (Exception ignore) {
                        // ignore
                    }
                }
            } catch (Exception e) {
View Full Code Here

Examples of org.apache.felix.service.command.CommandSession

        if (command.length() > 0) {

            // Shell is directly executing a sub/command, we don't setup a terminal and console
            // in this case, this avoids us reading from stdin un-necessarily.
            CommandSession session = commandProcessor.createSession(in, out, err);
            session.put("USER", user);
            session.put("APPLICATION", application);
            session.put(NameScoping.MULTI_SCOPE_MODE_KEY, Boolean.toString(isMultiScopeMode()));

            try {
                session.execute(command);
            } catch (Throwable t) {
                if (t instanceof CommandNotFoundException) {
                    String str = Ansi.ansi()
                        .fg(Ansi.Color.RED)
                        .a("Command not found: ")
                        .a(Ansi.Attribute.INTENSITY_BOLD)
                        .a(((CommandNotFoundException) t).getCommand())
                        .a(Ansi.Attribute.INTENSITY_BOLD_OFF)
                        .fg(Ansi.Color.DEFAULT).toString();
                    session.getConsole().println(str);
                } else if (t instanceof CommandException) {
                    session.getConsole().println(((CommandException) t).getNiceHelp());
                } else {
                    session.getConsole().print(Ansi.ansi().fg(Ansi.Color.RED).toString());
                    t.printStackTrace(session.getConsole());
                    session.getConsole().print(Ansi.ansi().fg(Ansi.Color.DEFAULT).toString());
                }
            }
        } else {
            // We are going into full blown interactive shell mode.

            final TerminalFactory terminalFactory = new TerminalFactory();
            final Terminal terminal = terminalFactory.getTerminal();
            Console console = createConsole(commandProcessor, threadIO, in, out, err, terminal);
            CommandSession session = console.getSession();
            session.put("USER", user);
            session.put("APPLICATION", application);
            session.put(NameScoping.MULTI_SCOPE_MODE_KEY, Boolean.toString(isMultiScopeMode()));
            session.put("#LINES", new Function() {
                public Object execute(CommandSession session, List<Object> arguments) throws Exception {
                    return Integer.toString(terminal.getHeight());
                }
            });
            session.put("#COLUMNS", new Function() {
                public Object execute(CommandSession session, List<Object> arguments) throws Exception {
                    return Integer.toString(terminal.getWidth());
                }
            });
            session.put(".jline.terminal", terminal);

            console.run();

            terminalFactory.destroy();
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.