所有
我在Groovy脚本中遇到HTTPBuilder类的问题,同时尝试将我的请求以XML格式发送到WSDL。我做错了什么?
以下是我的代码:
import groovyx.net.http.HTTPBuilder.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
def baseURL = "http://server:port"
def pathIn = "/folder1/folder2"
/* Groovy Utilities Declaration */
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
/* Request - modified - Holder Setup */
def modRequest = context.expand('${Groovy Script - Modify Request#Result}')
def modRequestHolder = groovyUtils.getXmlHolder("modRequest")
/* Define few variables for httpbuilder */
def httpWSDL = new HTTPBuilder(baseURL)
def respReturn = null
// Post the request against the WSDL using (httpbuilder.request(Method POST, ContentType XML); set uri.path to the path after base url of wsdl & body to requestholder.xml
// perform a POST request, expecting XML response
httpWSDL.request(POST, XML){ req ->
uri.path = pathIn
body = modRequestHolder.xml
// response handler for a success response code
response.success = { resp, reader ->
ret = reader.getXML()
println 'Response data: -----'
println respReturn
println '--------------------'
}
}
以下是例外情况:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 26: unable to resolve class HTTPBuilder @ line 26, column 24.
def httpWSDL = new HTTPBuilder(baseURL) ^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class HTTPBuilder @ line 26, column 24.
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:146)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:222)
at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:232)
at org.codehaus.groovy.control.ResolveVisitor.transformConstructorCallExpression(ResolveVisitor.java:969)
at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:646)
at org.codehaus.groovy.control.ResolveVisitor.transformDeclarationExpression(ResolveVisitor.java:1010)
at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:638)
at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitExpressionStatement(ClassCodeExpressionTransformer.java:139)
at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:40)
at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:35)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:163)
at org.codehaus.groovy.control.ResolveVisitor.visitBlockStatement(ResolveVisitor.java:1240)
at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:101)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:112)
at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitConstructorOrMethod(ClassCodeExpressionTransformer.java:50)
at org.codehaus.groovy.control.ResolveVisitor.visitConstructorOrMethod(ResolveVisitor.java:166)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:123)
at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1055)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1183)
at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:141)
at org.codehaus.groovy.control.CompilationUnit$10.call(CompilationUnit.java:632)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:912)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:574)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:523)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)
at groovy.lang.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)
at groovy.lang.GroovyShell.parse(GroovyShell.java:643)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:138)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:89)
at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SourceFile:79)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:138)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStep(AbstractTestCaseRunner.java:213)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runCurrentTestStep(WsdlTestCaseRunner.java:47)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:139)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:47)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:129)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source) 1 error
注意:HTTPBuilder JAR文件安装在ext& lib文件夹(我在阅读了几个论坛后这样做了)。其中一些人建议我导入REST Client。我该怎么做呢?另外,我正在研究的wsdl是一个SOAP服务。我还需要导入REST插件吗?
我对SOAPUI& Groovy并找到了解决方法。
任何人都可以帮助我,这将是伟大的。提前谢谢!
答案 0 :(得分:0)
我认为如果您复制/ext
或/lib
文件夹中的所有必需邮箱,您的代码必须正常运行。我认为问题是你在*
上使用import
作为路径类,而不是路径包,更确切地说是这样:
import groovyx.net.http.HTTPBuilder.*
应该是:
import groovyx.net.http.HTTPBuilder
由于groovyx.net.http.HTTPBuilder
直接是一个类,因此您无法将*
添加到最后,这就是您的groovy script
投掷org.codehaus.groovy.syntax.SyntaxException: unable to resolve class HTTPBuilder
希望这有帮助,