Package org.apache.karaf.shell.api.console

Examples of org.apache.karaf.shell.api.console.Session


    }

    @Override
    public Object execute(final CommandSession commandSession, List<Object> arguments) throws Exception {
        // TODO: remove the hack for .session
        Session session = (Session) commandSession.get(".session");
        // When need to translate closures to a compatible type for the command
        for (int i = 0; i < arguments.size(); i++) {
            Object v = arguments.get(i);
            if (v instanceof Closure) {
                final Closure closure = (Closure) v;
View Full Code Here


    private void run(final SessionFactory sessionFactory, String command, final InputStream in, final PrintStream out, final PrintStream err, ClassLoader cl) throws Exception {

        final TerminalFactory terminalFactory = new TerminalFactory();
        try {
            final Terminal terminal = new JLineTerminal(terminalFactory.getTerminal());
            Session session = createSession(sessionFactory, command.length() > 0 ? null : in, out, err, terminal);
            session.put("USER", user);
            session.put("APPLICATION", application);

            discoverCommands(session, cl, getDiscoveryResource());

            if (command.length() > 0) {
                // Shell is directly executing a sub/command, we don't setup a console
                // in this case, this avoids us reading from stdin un-necessarily.
                session.put(NameScoping.MULTI_SCOPE_MODE_KEY, Boolean.toString(isMultiScopeMode()));
                session.put(Session.PRINT_STACK_TRACES, "execution");
                try {
                    session.execute(command);
                } catch (Throwable t) {
                    ShellUtil.logException(session, t);
                }

            } else {
                // We are going into full blown interactive shell mode.
                session.run();
            }
        } finally {
            terminalFactory.destroy();
        }
    }
View Full Code Here

        String resolved = session.resolveCommand(path);


        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(baos, true);
        Session s = session.getFactory().create(null, ps, ps);
        s.put(Session.SCOPE, session.get(Session.SCOPE));
        s.put(Session.SUBSHELL, session.get(Session.SUBSHELL));
        try {
            s.execute(path + " --help");
        } catch (Throwable t) {
            return null;
        } finally {
            s.close();
        }
        return baos.toString();
    }
View Full Code Here

    public Session create(InputStream in, PrintStream out, PrintStream err, Terminal term, String encoding, Runnable closeCallback) {
        synchronized (sessions) {
            if (closed) {
                throw new IllegalStateException("SessionFactory has been closed");
            }
            final Session session = new ConsoleSessionImpl(this, commandProcessor, threadIO, in, out, err, term, encoding, closeCallback);
            sessions.add(session);
            return session;
        }
    }
View Full Code Here

    public Session create(InputStream in, PrintStream out, PrintStream err) {
        synchronized (sessions) {
            if (closed) {
                throw new IllegalStateException("SessionFactory has been closed");
            }
            final Session session = new HeadlessSessionImpl(this, commandProcessor, in, out, err);
            sessions.add(session);
            return session;
        }
    }
View Full Code Here

                in = new PipedOutputStream();
                out = new PipedInputStream();
                PrintStream pipedOut = new PrintStream(new PipedOutputStream(out), true);
               
                Session session = sessionFactory.create(
                        new PipedInputStream(in),
                        pipedOut,
                        pipedOut,
                        new WebTerminal(TERM_WIDTH, TERM_HEIGHT),
                        null,
View Full Code Here

        String response;
        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        final PrintStream printStream = new PrintStream(byteArrayOutputStream);
        final SessionFactory sessionFactory = getOsgiService(SessionFactory.class);
        final Session session = sessionFactory.create(System.in, printStream, System.err);

        final Callable<String> commandCallable = new Callable<String>() {
            @Override
            public String call() throws Exception {
                try {
                    if (!silent) {
                        System.err.println(command);
                    }
                    session.execute(command);
                } catch (Exception e) {
                    throw new RuntimeException(e.getMessage(), e);
                }
                printStream.flush();
                return byteArrayOutputStream.toString();
View Full Code Here

        super.doOpen();

        sessionTracker = new ServiceTracker<Session, Session>(bundleContext, Session.class, null) {
            @Override
            public Session addingService(ServiceReference<Session> reference) {
                Session session = super.addingService(reference);
                agentFactory.registerSession(session);
                return session;
            }
            @Override
            public void removedService(ServiceReference<Session> reference, Session session) {
View Full Code Here

                    public void run() {
                        destroy();
                    }
                };
                String encoding = getEncoding();
                final Session session = sessionFactory.create(in,
                        lfToCrLfPrintStream(out), lfToCrLfPrintStream(err), terminal, encoding, destroyCallback);
                for (Map.Entry<String, String> e : env.getEnv().entrySet()) {
                    session.put(e.getKey(), e.getValue());
                }
                JaasHelper.doAs(subject, new PrivilegedAction<Object>() {
                    public Object run() {
                        new Thread(session, "Karaf ssh console user " + ShellUtil.getCurrentUserName()).start();
                        return null;
View Full Code Here

    }

    @Override
    public Object execute(final CommandSession commandSession, List<Object> arguments) throws Exception {
        // TODO: remove the hack for .session
        Session session = (Session) commandSession.get(".session");
        // When need to translate closures to a compatible type for the command
        for (int i = 0; i < arguments.size(); i++) {
            Object v = arguments.get(i);
            if (v instanceof Closure) {
                final Closure closure = (Closure) v;
View Full Code Here

TOP

Related Classes of org.apache.karaf.shell.api.console.Session

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.