THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
title | Outdated documentation |
---|
6.3. Programmatically connect to the console
A connection to the kernel Karaf console can also be done programmatically.
The following code is a simplified version of the code from the client library.
Code Block | ||
---|---|---|
| ||
import org.apache.geronimo.gshell.remote.crypto.CryptoContextsshd.ClientChannel; import org.apache.geronimo.gshell.remote.client.RshClientsshd.ClientSession; import org.apache.geronimo.gshell.remote.client.RemoteExecuteExceptionsshd.SshClient; import org.apache.geronimosshd.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.tcp.SpringTcpTransportFactory; import org.apache.geronimo.gshell.whisper.stream.StreamFeeder; import org.apache.geronimo.gshell.layout.NotFoundException; import org.apache.geronimo.gshell.ExitNotification; future.ConnectFuture; public class Main { public static void main(String[] args) throws Exception { RshClientString clienthost = null"localhost"; tryint { port = 8101; String user CryptoContext context = new CryptoContext("RSAkaraf", null); String password = "karaf"; List<ClientMessageHandler> handlers = new LinkedList<ClientMessageHandler>(); SshClient client = null; handlers.add(new EchoHandler());try { client = new RshClient(context, new Locator(), handlersSshClient.setUpDefaultClient(); client.initializestart(); ConnectFuture future = client.connect(addresshost, new URI("tcp://0.0.0.0:0")port); clientfuture.loginawait(user, password); StreamFeederClientSession outputFeedersession = new StreamFeeder(client.getInputStream(), System.out); future.getSession(); session.authPassword(user, password); ClientChannel channel = outputFeedersession.createThreadcreateChannel().start()"shell"); clientchannel.openShellsetIn(System.in); channel.setOut(System.out.println("Connected"); clientchannel.execute(args[0]setErr(System.err); } catch channel.open(ExitNotification e) {; Systemchannel.exitwaitFor(ClientChannel.CLOSED, 0); } catch (Throwable t) { t.printStackTrace(); System.exit(1); } finally { try { client.closeShell(); client.closestop(); } catch (Throwable t) { } } System.exit(0); } private static class Locator implements TransportFactoryLocator { SpringTcpTransportFactory factory = new SpringTcpTransportFactory(); public TransportFactory locate(URI arg0) throws TransportException { return factory; } } } |
You can find a more complete example at the following location.
Wiki Markup |
---|
{scrollbar} |