0

I have to develop a Web Service in Java that use JSCH (librairie for SSH). But I get an error in calling this web service :

faultcode: soapenv:Server.userException, faultstring: java.lang.reflect.InvocationTargetException

My Java code works great, but when I call it like a Web Service, I have this error.

Here is my Java code :

import java.io.InputStream;

import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

public class SSHTest {

    public static void main(String[] args) {
        String cmd="pwd";
        System.out.println(ssh(cmd));

    }

    public static String ssh (String command1)
    {
        String host="10.0.0.20"; 
        String user="student";
        String password="xxx";
        String res="";
        try{

            java.util.Properties config = new java.util.Properties();
            config.put("StrictHostKeyChecking", "no");
            JSch jsch = new JSch();
            Session session=jsch.getSession(user, host, 22);
            session.setPassword(password);
            session.setConfig(config);
            session.connect(); // session.connect(30000) : making a connection with timeout.

            Channel channel=session.openChannel("exec");
            ((ChannelExec)channel).setCommand(command1);
            channel.setInputStream(null);
            ((ChannelExec)channel).setErrStream(System.err);

            InputStream in=channel.getInputStream();
            channel.connect();
            byte[] tmp=new byte[1024];
            while(true){
              while(in.available()>0){
                int i=in.read(tmp, 0, 1024);
                if(i<0)break;
                res += new String(tmp, 0, i);
              }
              if(channel.isClosed()){
                break;
              }
              try{Thread.sleep(1000);}catch(Exception ee){}
            }
            channel.disconnect();
            session.disconnect();
          }catch(Exception e){
            e.printStackTrace();
        }
          return res;
    }

}
Alexis Pigeon
  • 7,423
  • 11
  • 39
  • 44
Wael
  • 183
  • 1
  • 11
  • Sorry, your question does not give enough information. **How** are you calling this code as a web service? If you have some wrapper code, put a log output there to actually show the exception. – Paŭlo Ebermann Jun 15 '12 at 22:21
  • i use axis in tomcat to generate the WSDL file automaticly, so i don't have a log file and i don't use any wrapper – Wael Jun 17 '12 at 11:31

1 Answers1

0

Even I had faced the same error while developing web services. Check the version of the eclipse that you are using. How I was able to solve it.

Community
  • 1
  • 1
Anuj Balan
  • 7,629
  • 23
  • 58
  • 92