Groovy SOAPUI - ssh(端口22)然后端口转发3306以访问数据库

时间:2016-11-09 14:12:43

标签: groovy soapui

我希望通过ssh(端口22)然后移植到3306端口来访问数据库 - SOAP UI groovy。这是我到目前为止我无法成功运行此代码。

package mypackage
import groovy.sql.Sql
import java.sql.*
import com.jcraft.jsch.JSch
import com.jcraft.jsch.Session


// ssh login
def sshHost = 'test'
def sshUser = 'test'
def sshPass = 'test'
def sshPort = 22

// database login
def targetHost = '127.0.0.1'
def targetUser = 'test'
def targetPass = 'test'
def targetPort = '3306'

JSch jsch = new JSch();
Session session = jsch.getSession(sshUser, sshHost, sshPort);
session.setPassword(sshPass);
session.setConfig("StrictHostKeyChecking", "no");
System.out.println("Establishing Connection...");
session.connect();
int assinged_port=session.setPortForwardingL(0, targetHost, targetPort);

Connection con = null;
def driver = 'org.mariadb.jdbc.Driver'
def connectionString = 'jdbc:mariadb://localhost:3306/db'
con = DriverManager.getConnection(connectionString, targetUser, targetPass);
Statement st = con.createStatement();
String sql = "select * company "
st.execute(sql);

以下是我得到的错误:

  

org.codehaus.groovy.control.MultipleCompilationErrorsException:启动失败:Script23.groovy:4:无法解析类com.jcraft.jsch.JSch @ line 4,第1列.import com.jcraft.jsch.JSch ^ org .codehaus.groovy.syntax.SyntaxException:无法在org.codehaus的org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:146)解析类com.jcraft.jsch.JSch @第4行第1列.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1145)在org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:141)在org.codehaus.groovy.control.CompilationUnit $ 10.call(CompilationUnit。的java:632)处org.codehaus.groovy.control在org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:574 org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:912)) .boilationUnit.compile(CompilationUnit.java:523)在groovy.la的groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279) ng.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)at groovy.lang.GroovyShell.parseClass(GroovyShell.java:613)at groovy.lang.GroovyShell.parse(GroovyShell.java:625)at groovy.lang.GroovyShell.parse (GroovyShell.java:652)在groovy.lang.GroovyShell.parse(GroovyShell.java:643)在com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:138)在com.eviware。位于com.eviware.soapui.impl的com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)上的soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:89)。 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor)中的wsdl.panels.teststeps.GroovyScriptStepDesktopPanel $ RunAction $ 1.run(GroovyScriptStepDesktopPanel.java:250) .java:617)在java.lang.Thread.run(Thread.java:745)Script23.groovy:5:无法解析类com.jcraft.jsch.Session @ line 5,第1列。import com.jcraft.jsch.Session ^ org.codehaus.groovy.syntax.SyntaxException:无法解析类com.jcraft.jsch.Session @ line 5,第1列。在org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:146)在org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1145)在org.codehaus.groovy.control.ResolveVisitor。 startResolving在组织(ResolveVisitor.java:141)在org.codehaus.groovy.control.CompilationUnit $ 10.call(CompilationUnit.java:632)在org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:912)。在groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)的org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:523)上的codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:574) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)at groovy.lang.GroovyShell.parseClass(GroovyShell.java:613 )在groovy.lang.GroovyShell.parse(GroovyShell.java:625)在groovy.lang.GroovyShell.parse(GroovyShell.java:652)在groovy.lang.GroovyShell.parse(GroovyShell.java:643)在com.eviware .soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:138)com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:89)at com.eviware.soapui.impl .wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)位于java.util.concurrent的com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel $ RunAction $ 1.run(GroovyScriptStepDesktopPanel.java:250)。 ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)at java.lang.Thread.run(Thread.java:745)2 errors

1 个答案:

答案 0 :(得分:0)

这是一个微不足道的错误。

  

意外令牌:包@第2行,第1列。包mypackage ^

将语句package mypackage从第2行移至第1行。

UPDATE1:修复上述建议的更改后,OP更新了不同错误的问题。所以添加其他信息。

jsh及其依赖库需要在SOAPUI_HOME / bin / ext目录下复制并重启soapui工具。