X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.support%2Fsrc%2Forg%2Fargeo%2Fslc%2Fjsch%2FSshShell.java;fp=org.argeo.slc.support%2Fsrc%2Forg%2Fargeo%2Fslc%2Fjsch%2FSshShell.java;h=0000000000000000000000000000000000000000;hb=ecc22e604e47533c79de9cecdcdeacbc752cbff1;hp=2ec2b72a19602b8c18e7840738a95974a8eb2a8a;hpb=e07ded4632e53f8b8869763bc1f1f4091361e76e;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.support/src/org/argeo/slc/jsch/SshShell.java b/org.argeo.slc.support/src/org/argeo/slc/jsch/SshShell.java deleted file mode 100644 index 2ec2b72a1..000000000 --- a/org.argeo.slc.support/src/org/argeo/slc/jsch/SshShell.java +++ /dev/null @@ -1,125 +0,0 @@ -package org.argeo.slc.jsch; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.slc.SlcException; -import org.springframework.core.io.Resource; -import org.springframework.util.StringUtils; - -import com.jcraft.jsch.Channel; -import com.jcraft.jsch.Session; - -public class SshShell extends AbstractJschTask { - private final static Log log = LogFactory.getLog(SshShell.class); - private Resource input; - - @Override - void run(Session session) { - try { - final Channel channel = session.openChannel("shell"); - - // Enable agent-forwarding. - // ((ChannelShell)channel).setAgentForwarding(true); - - // channel.setInputStream(System.in); - // channel.setInputStream(input.getInputStream()); - /* - * // a hack for MS-DOS prompt on Windows. - * channel.setInputStream(new FilterInputStream(System.in){ public - * int read(byte[] b, int off, int len)throws IOException{ return - * in.read(b, off, (len>1024?1024:len)); } }); - */ - - // channel.setOutputStream(System.out); - - /* - * // Choose the pty-type "vt102". - * ((ChannelShell)channel).setPtyType("vt102"); - */ - - /* - * // Set environment variable "LANG" as "ja_JP.eucJP". - * ((ChannelShell)channel).setEnv("LANG", "ja_JP.eucJP"); - */ - - // Writer thread - final BufferedWriter writer = new BufferedWriter( - new OutputStreamWriter(channel.getOutputStream())); - - // channel.connect(); - channel.connect(3 * 1000); - - // while (!channel.isConnected()) - // try { - // Thread.sleep(500); - // } catch (InterruptedException e1) { - // // silent - // } - - Thread writerThread = new Thread("Shell writer " + getSshTarget()) { - - @Override - public void run() { - - if (log.isDebugEnabled()) - log.debug("Start writing to shell"); - - BufferedReader reader = null; - try { - reader = new BufferedReader(new InputStreamReader(input - .getInputStream())); - String line = null; - while ((line = reader.readLine()) != null) { - if (!StringUtils.hasText(line)) - continue; - writer.write(line); - writer.newLine(); - } - writer.append("exit"); - writer.newLine(); - writer.flush(); - // channel.disconnect(); - } catch (IOException e) { - throw new SlcException("Cannot write to shell on " - + getSshTarget(), e); - } finally { - IOUtils.closeQuietly(reader); - } - } - }; - writerThread.start(); - - BufferedReader execIn = null; - try { - execIn = new BufferedReader(new InputStreamReader(channel - .getInputStream())); - String line = null; - while ((line = execIn.readLine()) != null) { - if (!line.trim().equals("")) - log.info(line); - } - } catch (Exception e) { - throw new SlcException("Cannot read from shell on " - + getSshTarget(), e); - } finally { - IOUtils.closeQuietly(execIn); - } - - } catch (Exception e) { - throw new SlcException("Cannot use SSH shell on " + getSshTarget(), - e); - } - } - - public void setInput(Resource input) { - this.input = input; - } - -}