servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r709709 - in /servicemix/smx4/kernel/trunk: client/src/main/java/org/apache/servicemix/kernel/client/ gshell/gshell-admin/src/main/java/org/apache/servicemix/kernel/gshell/admin/internal/commands/ gshell/gshell-core/src/main/java/org/apache...
Date Sat, 01 Nov 2008 15:01:44 GMT
Author: gnodet
Date: Sat Nov  1 08:01:44 2008
New Revision: 709709

URL: http://svn.apache.org/viewvc?rev=709709&view=rev
Log:
Add some aliases and links.  Improve the remote stuff a bit (still need to display the instance
name when logged in a remote shell

Added:
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/RemoteShellProxy.java
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/RshAction.java
Modified:
    servicemix/smx4/kernel/trunk/client/src/main/java/org/apache/servicemix/kernel/client/Main.java
    servicemix/smx4/kernel/trunk/gshell/gshell-admin/src/main/java/org/apache/servicemix/kernel/gshell/admin/internal/commands/ConnectCommand.java
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/LocalConsole.java
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/LoginHandler.java
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/OpenShellHandler.java
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-commands.xml
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-remote.xml
    servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main/resources/META-INF/spring/gshell-log.xml

Modified: servicemix/smx4/kernel/trunk/client/src/main/java/org/apache/servicemix/kernel/client/Main.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/client/src/main/java/org/apache/servicemix/kernel/client/Main.java?rev=709709&r1=709708&r2=709709&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/client/src/main/java/org/apache/servicemix/kernel/client/Main.java
(original)
+++ servicemix/smx4/kernel/trunk/client/src/main/java/org/apache/servicemix/kernel/client/Main.java
Sat Nov  1 08:01:44 2008
@@ -19,23 +19,21 @@
 import java.net.URI;
 import java.util.List;
 import java.util.LinkedList;
-import java.io.InputStreamReader;
-import java.io.BufferedReader;
 
-import org.apache.geronimo.gshell.remote.client.RemoteExecuteException;
 import org.apache.geronimo.gshell.remote.client.RshClient;
 import org.apache.geronimo.gshell.remote.client.handler.EchoHandler;
 import org.apache.geronimo.gshell.remote.client.handler.ClientMessageHandler;
 import org.apache.geronimo.gshell.whisper.transport.TransportException;
 import org.apache.geronimo.gshell.whisper.transport.TransportFactory;
 import org.apache.geronimo.gshell.whisper.transport.TransportFactoryLocator;
-import org.apache.geronimo.gshell.whisper.transport.Transport;
 import org.apache.geronimo.gshell.whisper.transport.tcp.TcpTransportFactory;
 import org.apache.geronimo.gshell.whisper.transport.tcp.TcpTransport;
 import org.apache.geronimo.gshell.whisper.stream.StreamFeeder;
 import org.apache.geronimo.gshell.notification.ExitNotification;
 import org.apache.geronimo.gshell.security.crypto.CryptoContextImpl;
 import org.apache.geronimo.gshell.security.crypto.CryptoContext;
+import org.apache.geronimo.gshell.io.IO;
+import org.apache.servicemix.kernel.gshell.core.remote.RemoteShellProxy;
 
 /**
  * A very simple
@@ -78,6 +76,7 @@
         }
         RshClient client = null;
         try {
+            IO io = new IO();
             CryptoContext context = new CryptoContextImpl();
             List<ClientMessageHandler> handlers = new LinkedList<ClientMessageHandler>();
             handlers.add(new EchoHandler());
@@ -89,29 +88,17 @@
 
             client.connect(address, new URI("tcp://0.0.0.0:0"));
             client.login(user, password);
-            StreamFeeder outputFeeder = new StreamFeeder(client.getInputStream(), System.out);
+            StreamFeeder outputFeeder = new StreamFeeder(client.getInputStream(), io.outputStream);
             outputFeeder.createThread().start();
             client.openShell();
-            System.out.println("Connected");
+            io.out.println("Connected");
 
             String commandLine = sb.toString().trim();
             if (commandLine.length() > 0) {
                 client.execute(commandLine);
             } else {
-                BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
-                for (;;) {
-                    System.out.print("> ");
-                    String s = r.readLine().trim();
-                    if (s.length() > 0) {
-                        try {
-                            client.execute(s);
-                        } catch (RemoteExecuteException e) {
-                            String name = e.getCause().getClass().getName();
-                            name = name.substring(name.lastIndexOf('.') + 1);
-                            System.err.println(name + ": " + e.getCause().getMessage());
-                        }
-                    }
-                }
+                RemoteShellProxy shell = new RemoteShellProxy(client, io, "localhost", user);
+                shell.run();
             }
         } catch (ExitNotification e) {
             System.exit(0);

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-admin/src/main/java/org/apache/servicemix/kernel/gshell/admin/internal/commands/ConnectCommand.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-admin/src/main/java/org/apache/servicemix/kernel/gshell/admin/internal/commands/ConnectCommand.java?rev=709709&r1=709708&r2=709709&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-admin/src/main/java/org/apache/servicemix/kernel/gshell/admin/internal/commands/ConnectCommand.java
(original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-admin/src/main/java/org/apache/servicemix/kernel/gshell/admin/internal/commands/ConnectCommand.java
Sat Nov  1 08:01:44 2008
@@ -21,6 +21,7 @@
 import org.apache.geronimo.gshell.clp.Argument;
 import org.apache.geronimo.gshell.clp.Option;
 import org.apache.geronimo.gshell.shell.Shell;
+import org.apache.geronimo.gshell.shell.ShellContextHolder;
 import org.osgi.framework.ServiceReference;
 
 public class ConnectCommand extends AdminCommandSupport {
@@ -36,26 +37,7 @@
 
     protected Object doExecute() throws Exception {
         int port = getExistingInstance(instance).getPort();
-        ServiceReference ref = getBundleContext().getServiceReference(Shell.class.getName());
-        if (ref == null) {
-            io.out.println("CommandExecutor service is unavailable.");
-            return null;
-        }
-        try {
-            Shell exec = (Shell) getBundleContext().getService(ref);
-            if (exec == null) {
-                io.out.println("CommandExecutor service is unavailable.");
-                return null;
-            }
-
-            // TODO: -n option does not exist in smx
-            //exec.execute("remote/rsh -u " + username + " -p " + password + " -n " + instance
+ " tcp://localhost:" + port);
-            exec.execute("remote/rsh -u " + username + " -p " + password + " tcp://localhost:"
+ port);
-        }
-        finally {
-            getBundleContext().ungetService(ref);
-        }
-
+        ShellContextHolder.get().getShell().execute("remote/rsh -u " + username + " -p "
+ password + " -n " + instance + " tcp://localhost:" + port);
         return Result.SUCCESS;
     }
 }

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/LocalConsole.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/LocalConsole.java?rev=709709&r1=709708&r2=709709&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/LocalConsole.java
(original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/LocalConsole.java
Sat Nov  1 08:01:44 2008
@@ -80,6 +80,9 @@
     }
 
     public void init() {
+        shell.getContext().getVariables().set("gshell.prompt",
+                                              "@|bold %{gshell.user}|@%{application.localHost.hostName}:@|bold
%{gshell.group.name}|> ");
+        shell.getContext().getVariables().set("gshell.user", "smx");
         frameworkStarted = new CountDownLatch(1);
 		getBundleContext().addFrameworkListener(new FrameworkListener(){
 			public void frameworkEvent(FrameworkEvent event) {

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/LoginHandler.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/LoginHandler.java?rev=709709&r1=709708&r2=709709&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/LoginHandler.java
(original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/LoginHandler.java
Sat Nov  1 08:01:44 2008
@@ -23,6 +23,7 @@
 import org.apache.geronimo.gshell.remote.server.handler.ServerSessionContext;
 import org.apache.geronimo.gshell.remote.server.handler.ServerMessageHandlerSupport;
 import org.apache.geronimo.gshell.whisper.transport.Session;
+import org.apache.geronimo.gshell.command.Variables;
 
 import java.util.UUID;
 
@@ -86,6 +87,10 @@
                 session.send(reply);
             }
             else {
+                if (context.variables == null) {
+                    context.variables = new Variables();
+                }
+                context.variables.set("gshell.user", username);
                 UUID identity = UUID.randomUUID();
                 LoginMessage.Success reply = new LoginMessage.Success(identity);
                 reply.setCorrelationId(message.getId());

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/OpenShellHandler.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/OpenShellHandler.java?rev=709709&r1=709708&r2=709709&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/OpenShellHandler.java
(original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/OpenShellHandler.java
Sat Nov  1 08:01:44 2008
@@ -60,8 +60,12 @@
         context.container = container;
 
         // Setup the shell context and related components
-        context.io = new RemoteIO(session);
-        context.variables = new Variables();
+        if (context.io == null) {
+            context.io = new RemoteIO(session);
+        }
+        if (context.variables == null) {
+            context.variables = new Variables();
+        }
 
         // Create a new shell instance
         context.shell = context.container.getBean("remoteShell", Shell.class);

Added: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/RemoteShellProxy.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/RemoteShellProxy.java?rev=709709&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/RemoteShellProxy.java
(added)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/RemoteShellProxy.java
Sat Nov  1 08:01:44 2008
@@ -0,0 +1,298 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.servicemix.kernel.gshell.core.remote;
+
+import org.apache.geronimo.gshell.ansi.AnsiRenderer;
+import org.apache.geronimo.gshell.console.Console;
+import org.apache.geronimo.gshell.console.JLineConsole;
+import org.apache.geronimo.gshell.io.IO;
+import org.apache.geronimo.gshell.io.Closer;
+import org.apache.geronimo.gshell.notification.ExitNotification;
+import org.apache.geronimo.gshell.remote.client.RshClient;
+import org.apache.geronimo.gshell.remote.client.proxy.RemoteHistoryProxy;
+import org.apache.geronimo.gshell.remote.client.proxy.RemoteCompleterProxy;
+import org.apache.geronimo.gshell.shell.ShellContext;
+import org.apache.geronimo.gshell.shell.Shell;
+import org.apache.geronimo.gshell.shell.ShellContextHolder;
+import org.apache.geronimo.gshell.whisper.stream.StreamFeeder;
+import org.apache.geronimo.gshell.command.Variables;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Provides a shell interface which will proxy to a remote shell instance.
+ *
+ * @version $Rev: 707952 $ $Date: 2008-10-26 08:51:45 +0100 (Sun, 26 Oct 2008) $
+ */
+public class RemoteShellProxy
+    implements Shell
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final RshClient client;
+
+    private final IO io;
+
+    private final StreamFeeder outputFeeder;
+
+    private final ShellContext context;
+
+    private final RemoteHistoryProxy history;
+
+    private boolean opened;
+
+    private String instance;
+
+    private String user;
+
+    public RemoteShellProxy(final RshClient client, final IO io, final String instance, final
String user) throws Exception {
+        assert client != null;
+        assert io != null;
+
+        this.client = client;
+        this.io = io;
+        this.instance = instance;
+        this.user = user;
+
+        //
+        // TODO: send over some client-side details, like the terminal features, etc, as
well, verbosity too)
+        //       If any problem or denial occurs, throw an exception, once created the proxy
is considered valid.
+        //
+
+        client.openShell();
+
+        // Setup other proxies
+        history = new RemoteHistoryProxy(client);
+
+        // Copy the client's input stream to our outputstream so users see command output
+        outputFeeder = new StreamFeeder(client.getInputStream(), io.outputStream);
+        outputFeeder.createThread().start();
+
+        context = new ShellContext() {
+            private Variables vars = new Variables();
+            public Shell getShell() {
+                return RemoteShellProxy.this;
+            }
+
+            public IO getIo() {
+                return io;
+            }
+
+            public Variables getVariables() {
+                return vars;
+            }
+        };
+
+        opened = true;
+
+        getContext().getVariables().set("gshell.group.name", "");
+        getContext().getVariables().set("gshell.prompt", "@|bold %{gshell.user}|@%{gshell.instance}:@|bold
%{gshell.group.name}|> ");
+        getContext().getVariables().set("gshell.user", user);
+        getContext().getVariables().set("gshell.instance", instance != null ? instance :
"unknown");
+    }
+
+    private void ensureOpened() {
+        if (!opened) {
+            throw new IllegalStateException("Remote shell proxy has been closed");
+        }
+    }
+
+    public boolean isOpened() {
+        return opened;
+    }
+
+    public void close() {
+        try {
+            client.closeShell();
+        }
+        catch (Exception ignore) {}
+
+        Closer.close(outputFeeder);
+
+        opened = false;
+    }
+
+    public ShellContext getContext() {
+        ensureOpened();
+
+        return context;
+    }
+
+    public Object execute(final String line) throws Exception {
+        ensureOpened();
+        ShellContext ctx = ShellContextHolder.get(true);
+        try {
+            ShellContextHolder.set(context);
+            return client.execute(line);
+        } finally {
+            ShellContextHolder.set(ctx);
+        }
+    }
+
+    public Object execute(final String command, final Object[] args) throws Exception {
+        ensureOpened();
+        ShellContext ctx = ShellContextHolder.get(true);
+        try {
+            ShellContextHolder.set(context);
+            return client.execute(command, args);
+        } finally {
+            ShellContextHolder.set(ctx);
+        }
+    }
+
+    public Object execute(final Object... args) throws Exception {
+        ensureOpened();
+        ShellContext ctx = ShellContextHolder.get(true);
+        try {
+            ShellContextHolder.set(context);
+            return client.execute(args);
+        } finally {
+            ShellContextHolder.set(ctx);
+        }
+    }
+
+    public Object execute(final Object[][] commands) throws Exception {
+        ensureOpened();
+        ShellContext ctx = ShellContextHolder.get(true);
+        try {
+            ShellContextHolder.set(context);
+            return client.execute(commands);
+        } finally {
+            ShellContextHolder.set(ctx);
+        }
+    }
+
+    public boolean isInteractive() {
+        return true;
+    }
+
+    public void run(final Object... args) throws Exception {
+        assert args != null;
+
+        ensureOpened();
+
+        log.debug("Starting interactive console; args: {}", args);
+
+        //
+        // TODO: We need a hook into the session state here so that we can abort the console
muck when the session closes
+        //
+
+        //
+        // TODO: Request server to load...
+        //
+        // loadUserScript(branding.getInteractiveScriptName());
+
+        final AtomicReference<ExitNotification> exitNotifHolder = new AtomicReference<ExitNotification>();
+        final AtomicReference<Object> lastResultHolder = new AtomicReference<Object>();
+
+        Console.Executor executor = new Console.Executor() {
+            public Result execute(final String line) throws Exception {
+                assert line != null;
+
+                try {
+                    Object result = RemoteShellProxy.this.execute(line);
+
+                    lastResultHolder.set(result);
+                }
+                catch (ExitNotification n) {
+                    exitNotifHolder.set(n);
+
+                    return Result.STOP;
+                }
+
+                return Result.CONTINUE;
+            }
+        };
+
+        JLineConsole console = new JLineConsole(executor, io);
+
+        console.setPrompter(new RemotePrompter());
+
+        console.setErrorHandler(new Console.ErrorHandler() {
+            public Result handleError(final Throwable error) {
+                assert error != null;
+
+                //
+                // TODO: Do something here...
+                //
+
+                return Result.CONTINUE;
+            }
+        });
+
+        console.addCompleter(new RemoteCompleterProxy(client));
+
+        //
+        // TODO: What are we to do with history here?  Really should be history on the server...
+        //
+
+        /*
+        // Hook up a nice history file (we gotta hold on to the history object at some point
so the 'history' command can get to it)
+        History history = new History();
+        console.setHistory(history);
+        console.setHistoryFile(new File(branding.getUserDirectory(), branding.getHistoryFileName()));
+        */
+
+        // Unless the user wants us to shut up, then display a nice welcome banner
+        /*
+        if (!io.isQuiet()) {
+            io.out.println(branding.getWelcomeBanner());
+        }
+        */
+
+        // Check if there are args, and run them and then enter interactive
+        if (args.length != 0) {
+            execute(args);
+        }
+
+        // And then spin up the console and go for a jog
+        ShellContext ctx = ShellContextHolder.get(true);
+        try {
+            ShellContextHolder.set(context);
+            console.run();
+        } finally {
+            ShellContextHolder.set(ctx);
+        }
+
+        // If any exit notification occured while running, then puke it up
+        ExitNotification n = exitNotifHolder.get();
+        if (n != null) {
+            throw n;
+        }
+    }
+
+    protected class RemotePrompter implements Console.Prompter {
+
+        public String prompt() {
+            String prompt = "@|bold " + user + "|@" + instance + ":> ";
+
+
+            // Encode ANSI muck if it looks like there are codes encoded
+            if (AnsiRenderer.test(prompt)) {
+                prompt = new AnsiRenderer().render(prompt);
+            }
+
+            return prompt;
+        }
+
+    }
+}
\ No newline at end of file

Added: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/RshAction.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/RshAction.java?rev=709709&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/RshAction.java
(added)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/remote/RshAction.java
Sat Nov  1 08:01:44 2008
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.servicemix.kernel.gshell.core.remote;
+
+import org.apache.geronimo.gshell.clp.Argument;
+import org.apache.geronimo.gshell.clp.Option;
+import org.apache.geronimo.gshell.command.CommandAction;
+import org.apache.geronimo.gshell.command.CommandContext;
+import org.apache.geronimo.gshell.io.IO;
+import org.apache.geronimo.gshell.io.PromptReader;
+import org.apache.geronimo.gshell.notification.ExitNotification;
+import org.apache.geronimo.gshell.remote.client.RshClient;
+import org.apache.geronimo.gshell.spring.BeanContainer;
+import org.apache.geronimo.gshell.spring.BeanContainerAware;
+import org.apache.geronimo.gshell.i18n.MessageSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Connect to a remote shell server.
+ *
+ * @version $Rev: 707952 $ $Date: 2008-10-26 08:51:45 +0100 (Sun, 26 Oct 2008) $
+ */
+public class RshAction
+    implements CommandAction, BeanContainerAware
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Option(name="-b", aliases={"--bind"})
+    private URI local;
+
+    @Option(name="-u", aliases={"--username"})
+    private String username;
+
+    @Option(name="-p", aliases={"--password"})
+    private String password;
+
+    @Option(name="-n", aliases={"--instance"})
+    private String instance;
+
+    @Argument(required=true, index=0)
+    private URI remote;
+
+    @Argument(index=1, multiValued=true)
+    private List<String> command = null;
+
+    private BeanContainer container;
+
+    public void setBeanContainer(final BeanContainer container) {
+        assert container != null;
+        this.container = container;
+    }
+
+    /**
+     * Helper to validate that prompted username or password is not null or empty.
+     */
+    private class UsernamePasswordValidator
+        implements PromptReader.Validator
+    {
+        private String type;
+
+        private int count = 0;
+
+        private int max = 3;
+
+        public UsernamePasswordValidator(final String type) {
+            assert type != null;
+
+            this.type = type;
+        }
+
+        public boolean isValid(final String value) {
+            count++;
+
+            if (value != null && value.trim().length() > 0) {
+                return true;
+            }
+
+            if (count >= max) {
+                throw new RuntimeException("Too many attempts; failed to prompt user for
" + type + " after " + max + " tries");
+            }
+
+            return false;
+        }
+    }
+
+    public Object execute(final CommandContext context) throws Exception {
+        assert context != null;
+        IO io = context.getIo();
+        MessageSource messages = context.getCommand().getMessages();
+
+        io.info(messages.format("info.connecting", remote));
+
+        // If the username/password was not configured via cli, then prompt the user for
the values
+        if (username == null || password == null) {
+            PromptReader prompter = new PromptReader(io);
+            String text;
+
+            log.debug("Prompting user for credentials");
+
+            if (username == null) {
+                text = messages.getMessage("prompt.username");
+                username = prompter.readLine(text + ": ", new UsernamePasswordValidator(text));
+            }
+
+            if (password == null) {
+                text = messages.getMessage("prompt.password");
+                password = prompter.readLine(text + ": ", new UsernamePasswordValidator(text));
+            }
+        }
+
+        // Create the client from prototype
+        RshClient client = container.getBean(RshClient.class);
+
+        log.debug("Created client: {}", client);
+
+        client.connect(remote, local);
+
+        io.info(messages.getMessage("info.connected"));
+
+        client.login(username, password);
+
+        // client.echo("HELLO");
+        // Thread.sleep(1 * 1000);
+
+        RemoteShellProxy shell = new RemoteShellProxy(client, io, instance, username);
+
+        Object result = Result.SUCCESS;
+
+        try {
+            if (command == null) {
+                command = new ArrayList<String>();
+            }
+
+            shell.run(command.toArray());
+        }
+        catch (ExitNotification n) {
+            // Make sure that we catch this notification, so that our parent shell doesn't
exit when the remote shell does
+            result = n.code;
+        }
+
+        shell.close();
+
+        io.verbose(messages.getMessage("verbose.disconnecting"));
+
+        client.close();
+
+        io.verbose(messages.getMessage("verbose.disconnected"));
+
+        return result;
+    }
+}
\ No newline at end of file

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-commands.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-commands.xml?rev=709709&r1=709708&r2=709709&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-commands.xml
(original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-commands.xml
Sat Nov  1 08:01:44 2008
@@ -131,7 +131,7 @@
 
     <gshell:command-bundle>
         <gshell:command name="remote/rsh">
-            <gshell:action class="org.apache.geronimo.gshell.commands.remote.RshAction"/>
+            <gshell:action class="org.apache.servicemix.kernel.gshell.core.remote.RshAction"/>
         </gshell:command>
 
         <gshell:command name="remote/rsh-server">

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-remote.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-remote.xml?rev=709709&r1=709708&r2=709709&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-remote.xml
(original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-remote.xml
Sat Nov  1 08:01:44 2008
@@ -55,12 +55,20 @@
                 <bean class="org.apache.geronimo.gshell.remote.server.handler.ExecuteHandler"/>
                 <bean class="org.apache.geronimo.gshell.remote.server.handler.CloseShellHandler"/>
                 <bean class="org.apache.geronimo.gshell.remote.server.handler.EchoHandler"/>
+                <bean class="org.apache.geronimo.gshell.remote.server.handler.CompleteHandler"
/>
             </list>
         </constructor-arg>
     </bean>
 
     <bean id="remoteShell" class="org.apache.geronimo.gshell.remote.server.RemoteShellImpl"
scope="prototype">
         <constructor-arg ref="commandLineExecutor"/>
+
+        <property name="completers">
+            <list>
+                <ref bean="commandsCompleter"/>
+                <ref bean="aliasNameCompleter"/>
+            </list>
+        </property>
     </bean>
 
     <bean class="org.apache.geronimo.gshell.remote.client.RshClient" scope="prototype">

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main/resources/META-INF/spring/gshell-log.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main/resources/META-INF/spring/gshell-log.xml?rev=709709&r1=709708&r2=709709&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main/resources/META-INF/spring/gshell-log.xml
(original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main/resources/META-INF/spring/gshell-log.xml
Sat Nov  1 08:01:44 2008
@@ -38,23 +38,28 @@
     <import resource="classpath:org/apache/servicemix/kernel/gshell/core/commands.xml"
/>
 
     <gshell:command-bundle>
-        <gshell:command name="log/d">
+        <gshell:command name="log/display">
             <gshell:action class="org.apache.servicemix.kernel.gshell.log.DisplayLog">
                 <property name="events" ref="events" />
                 <property name="pattern" value="${pattern}" />
             </gshell:action>
         </gshell:command>
-        <gshell:command name="log/de">
+        <gshell:link name="log/d" target="log/display" />
+        <gshell:command name="log/display-exception">
             <gshell:action class="org.apache.servicemix.kernel.gshell.log.DisplayException">
                 <property name="events" ref="events" />
             </gshell:action>
         </gshell:command>
+        <gshell:link name="log/de" target="log/display-exception" />
         <gshell:command name="log/get">
             <gshell:action class="org.apache.servicemix.kernel.gshell.log.GetLogLevel"
/>
         </gshell:command>
         <gshell:command name="log/set">
             <gshell:action class="org.apache.servicemix.kernel.gshell.log.SetLogLevel"
/>
         </gshell:command>
+
+        <gshell:alias name="ld" alias="log/d" />
+        <gshell:alias name="lde" alias="log/de" />
     </gshell:command-bundle>
 
     <bean id="vmLogAppender" class="org.apache.servicemix.kernel.gshell.log.VmLogAppender">



Mime
View raw message