SOAPUI:HTTPBuilder - 无法解析 class - 异常

SOAPUI: HTTPBuilder - unable to resolve class - exception

全部,

我的 Groovy 脚本中的 HTTPBuilder class 在尝试 POST 我的 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.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 客户端。我该怎么做呢?另外,我正在处理的 wsdl 是一个 SOAP 服务。我还需要导入 REST 插件吗?

我对 SOAPUI 和 Groovy 非常陌生,正在寻找自己的出路。

如果有人能帮助我,那就太好了。提前致谢!

我认为如果您将所有需要的 jar 复制到 /ext/lib 文件夹中,您的代码一定能正常工作。我认为问题在于您在 import 上使用 * 作为路径 class 而不是路径包,更准确地说是:

import groovyx.net.http.HTTPBuilder.*

应该是:

import groovyx.net.http.HTTPBuilder

由于 groovyx.net.http.HTTPBuilder 直接是 class 你不能在末尾添加 *,这就是你的 groovy script 抛出 org.codehaus.groovy.syntax.SyntaxException: unable to resolve class HTTPBuilder[ 的原因=20=]

希望这对您有所帮助,