Forum Discussion
skalaskar
14 years agoNew Contributor
Figured it out. The file needs to be saved under the following directory,
C:\Program Files\eviware\soapUI-Pro-3.0.1\lib
Once done right click on the file - > properties and then click on Unblock (if it is blocked).
Following is the the groovy script which works fine on my box,
package com.content.jsc;
import com.jcraft.jsch.*;
import java.awt.*;
import javax.swing.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.*;
public static class MyUserInfo implements UserInfo{
String password = "";
public MyUserInfo(String password) { this.password = password; }
public String getPassword(){ return password; }
public boolean promptYesNo(String str){return true;}
public String getPassphrase(){ return null; }
public boolean promptPassphrase(String message){ return true; }
public boolean promptPassword(String message){ return true; }
public void showMessage(String message){}
}
def mode = context.expand( '${#TestCase#RUN_MODE}' )
def username = "xxxxxxx"
def date = context.expand( '${#TestCase#DATE}' )
def pwd = "xxxxxxx"
def host = "xxxxxxx"
def command = "sh santosh.sh"
JSch jsch=new JSch();
session=jsch.getSession(username,host,22)
// username and password will be given via UserInfo interface.
UserInfo ui=new MyUserInfo(pwd);
session.setUserInfo(ui);
session.connect();
Channel channel=session.openChannel("exec");
log.info(mode)
((ChannelExec)channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
instream=channel.getInputStream();
channel.connect();
byte[] tmp=new byte[1024];
while(true){
while(instream.available()>0){
int i=instream.read(tmp, 0, 100);
if(i<0)break;
log.info(new String(tmp, 0, i));
}
if(channel.isClosed()){
log.info("exit-status: "+channel.getExitStatus());
if (channel.getExitStatus()!=0)
throw new Exception( "Script "+command+" Failed" );
break;
}
try{Thread.sleep(1000);}catch(Exception ee){ log.info(ee); }
}
channel.disconnect();
session.disconnect();
C:\Program Files\eviware\soapUI-Pro-3.0.1\lib
Once done right click on the file - > properties and then click on Unblock (if it is blocked).
Following is the the groovy script which works fine on my box,
package com.content.jsc;
import com.jcraft.jsch.*;
import java.awt.*;
import javax.swing.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.*;
public static class MyUserInfo implements UserInfo{
String password = "";
public MyUserInfo(String password) { this.password = password; }
public String getPassword(){ return password; }
public boolean promptYesNo(String str){return true;}
public String getPassphrase(){ return null; }
public boolean promptPassphrase(String message){ return true; }
public boolean promptPassword(String message){ return true; }
public void showMessage(String message){}
}
def mode = context.expand( '${#TestCase#RUN_MODE}' )
def username = "xxxxxxx"
def date = context.expand( '${#TestCase#DATE}' )
def pwd = "xxxxxxx"
def host = "xxxxxxx"
def command = "sh santosh.sh"
JSch jsch=new JSch();
session=jsch.getSession(username,host,22)
// username and password will be given via UserInfo interface.
UserInfo ui=new MyUserInfo(pwd);
session.setUserInfo(ui);
session.connect();
Channel channel=session.openChannel("exec");
log.info(mode)
((ChannelExec)channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
instream=channel.getInputStream();
channel.connect();
byte[] tmp=new byte[1024];
while(true){
while(instream.available()>0){
int i=instream.read(tmp, 0, 100);
if(i<0)break;
log.info(new String(tmp, 0, i));
}
if(channel.isClosed()){
log.info("exit-status: "+channel.getExitStatus());
if (channel.getExitStatus()!=0)
throw new Exception( "Script "+command+" Failed" );
break;
}
try{Thread.sleep(1000);}catch(Exception ee){ log.info(ee); }
}
channel.disconnect();
session.disconnect();
Related Content
Recent Discussions
- 4 days agoemoya