geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r721244 - in /geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main: java/org/apache/geronimo/gshell/commands/ssh/SshAction.java resources/META-INF/gshell/components.xml
Date Thu, 27 Nov 2008 17:19:57 GMT
Author: gnodet
Date: Thu Nov 27 09:19:56 2008
New Revision: 721244

URL: http://svn.apache.org/viewvc?rev=721244&view=rev
Log:
Fix SshAction to properly exit

Modified:
    geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/SshAction.java
    geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml

Modified: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/SshAction.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/SshAction.java?rev=721244&r1=721243&r2=721244&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/SshAction.java
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/SshAction.java
Thu Nov 27 09:19:56 2008
@@ -22,6 +22,8 @@
 import com.google.code.sshd.ClientChannel;
 import com.google.code.sshd.ClientSession;
 import com.google.code.sshd.SshClient;
+import com.google.code.sshd.common.util.NoCloseInputStream;
+import com.google.code.sshd.common.util.NoCloseOutputStream;
 import org.apache.geronimo.gshell.clp.Argument;
 import org.apache.geronimo.gshell.clp.Option;
 import org.apache.geronimo.gshell.command.CommandAction;
@@ -128,18 +130,32 @@
         // Create the client from prototype
         SshClient client = container.getBean(SshClient.class);
         log.debug("Created client: {}", client);
+        client.start();;
 
-        ClientSession session = client.connect(hostname, port);
-        io.info(messages.getMessage("info.connected"));
-
-        session.authPassword(username, password);
-
-        ClientChannel channel = session.createChannel("shell");
-        channel.setIn(io.inputStream);
-        channel.setOut(io.outputStream);
-        channel.setErr(io.errorStream);
-        channel.open();
-        channel.waitFor(ClientChannel.CLOSED, 0);
+        try {
+            ClientSession session = client.connect(hostname, port);
+            try {
+                io.info(messages.getMessage("info.connected"));
+
+                session.authPassword(username, password);
+                int ret = session.waitFor(ClientSession.WAIT_AUTH | ClientSession.CLOSED
| ClientSession.AUTHED, 0);
+                if ((ret & ClientSession.AUTHED) == 0) {
+                    io.err.println("Authentication failed");
+                    return Result.FAILURE;
+                }
+
+                ClientChannel channel = session.createChannel("shell");
+                channel.setIn(new NoCloseInputStream(io.inputStream));
+                channel.setOut(new NoCloseOutputStream(io.outputStream));
+                channel.setErr(new NoCloseOutputStream(io.errorStream));
+                channel.open();
+                channel.waitFor(ClientChannel.CLOSED, 0);
+            } finally {
+                session.close();
+            }
+        } finally {
+            client.stop();
+        }
 
         io.verbose(messages.getMessage("verbose.disconnected"));
 

Modified: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml?rev=721244&r1=721243&r2=721244&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml
Thu Nov 27 09:19:56 2008
@@ -45,7 +45,7 @@
         </gshell:command-bundle>
     </gshell:plugin>
 
-    <bean name="sshClient" class="com.google.code.sshd.SshClient" factory-method="setUpDefaultClient"
init-method="start" destroy-method="stop">
+    <bean name="sshClient" class="com.google.code.sshd.SshClient" factory-method="setUpDefaultClient"
scope="prototype">
     </bean>
 
     <bean name="sshServer" class="com.google.code.sshd.SshServer" factory-method="setUpDefaultServer"
scope="prototype">



Mime
View raw message