Hi,
I try to develop a web service that by an ssh client get any
information from a host.
For the ssh client I use a .jar named Ganymed SSH2
the client work perfectly if I use it from a normal standalone java
main, but cause any problems if I use it from a web service.
In each one program i use the same IP User and Password but under web
service tomcat made this log
_________________________________________________________________________
143.225.250.102 viola wertCreato l'oggetto SshClient!!!! 1Creata
un'istanza di connessione
Questo è l'errore generato ---> The connection could not be fully established.
java.io.IOException: The connection could not be fully established.
at ch.ethz.ssh2.Connection.connect(Connection.java:464)
at ch.ethz.ssh2.Connection.connect(Connection.java:418)
at PerformWS_pkg.SshClient.getDataString(SshClient.java:41)
at
PerformWS_pkg.PerformWSSoapBindingImpl.outputStr(PerformWSSoapBindingImpl.java:22)
at
PerformWS_pkg.PerformWSSoapBindingSkeleton.outputStr(PerformWSSoapBindingSkeleton.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:388)
at
org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:283)
at
org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
at
org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:453)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at
org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: Cannot establish TCP connection to
143.225.250.102:22
at
ch.ethz.ssh2.transport.TransportManager.<init>(TransportManager.java:82)
at ch.ethz.ssh2.Connection.connect(Connection.java:454)
... 47 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at
ch.ethz.ssh2.transport.TransportManager.<init>(TransportManager.java:78)
... 48 more
- Cannot serialize session attribute PerformWS for session
7EB894C840B0E67C9447EF2542D4B530
______________________________________________________________
Thanks a lot
Raffo
package PerformWS_pkg;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;
public class SshClient
{
String hostname = "127.0.0.1";
String username = " ";
String password = " ";
private StringBuffer dati_trasmessi=new StringBuffer();
StringTokenizer st;
String line;
public SshClient(String host, String user, String pass)
{
hostname=host;
username=user;
password=pass;
}
//public String getDataString(){ return new String("CIAOCIAO");}
public String getDataString()
{
try
{
/* Create a connection instance */
Connection conn = new Connection(hostname);
System.out.println(" 1Creata un'istanza di connessione ");
/* Now connect */
conn.connect();
System.out.println(" 2Connessione ");
/* Authenticate */
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if (isAuthenticated == false)
throw new IOException("Authentication failed.");
System.out.println(" 3autenticazione effettuata ");
/* Create a session */
Session sess = conn.openSession();
System.out.println(" 4Session creata ");
sess.execCommand("ps -ef");
//System.out.println("Here is some information about the remote host:");
InputStream stdout = new StreamGobbler(sess.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
System.out.println(" 5prima del while ");
while (true)
{
line=br.readLine();
if (line == null) break;
st=new StringTokenizer(line);
while(st.hasMoreTokens())
{
dati_trasmessi.append(st.nextToken()+" ,");
}
dati_trasmessi.append(" |");
}
/* Show exit status, if available (otherwise "null") */
//System.out.println("ExitCode: " + sess.getExitStatus());
/* Close this session */
sess.close();
System.out.println(" 6Session chiusa ");
/* Close the connection */
conn.close();
}
catch (IOException e)
{
//e.printStackTrace(System.err);
System.out.println("Questo è l'errore generato ---> "+e.getMessage());
e.printStackTrace();
System.exit(2);
}
return dati_trasmessi.toString();
}
}
package PerformWS_pkg;
import java.util.*;
public class ssh_client_main {
public static void main(String[] args) {
String host= args[0];
String user= args[1];
String pass= args[2];
SshClient sshClient=new SshClient(host,user,pass);
String message=sshClient.getDataString();
StringTokenizer st=new StringTokenizer(message);
while(st.hasMoreTokens())
{
//System.out.println(st.nextToken("|"));
System.out.println(st.nextToken());
}
}
}
/**
* FeatWSSoapBindingImpl.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.2.1 Jun 14, 2005 (09:15:57 EDT) WSDL2Java emitter.
*/
package PerformWS_pkg;
public class PerformWSSoapBindingImpl implements PerformWS
{
public java.lang.String outputStr(java.lang.String in0, java.lang.String in1, java.lang.String in2) throws java.rmi.RemoteException
{
String message="Nn è successo niente";
System.out.print(in0+" "+in1+" "+in2);
SshClient sshClient=new SshClient(in0,in1,in2);
//Saluti saluti =new Saluti(in0,in1,in2);
//SshExec2 sshClient=new SshExec2(in0,in1,in2);
System.out.print("Creato l'oggetto SshClient!!!!");
//message=saluti.getDataString();
message=sshClient.getDataString();
//message=sshClient.getInput();
System.out.print("Ottenuto l'output --> "+message);
return message;
}
}