使用属性展开

时间:2016-04-28 02:55:49

标签: groovy soapui

here

引用属性扩展

肥皂请求的一个要素定义如下 <ns:PRODUCTID>${=def list = [12, 13,12];list.join(',')}</ns:PRODUCTID>

当提交请求时,它会正确评估并发出以下请求(来自原始请求):
<ns:PRODUCTID>12,13,12</ns:PRODUCTID>

然而,如下所示,无法使其工作为动态值,我的意思是它低于错误 <ns:PRODUCTID>${=def a = (int)(Math.random()*5);def list = [];a.times {list.add((int)(Math.random()*1000))};list.join(',')}</ns:PRODUCTID>

但是,当单独运行时,相同的脚本运行完全正常。 enter image description here 错误如下:

  

启动失败:   Script16.groovy:1:期待&#39;}&#39;,发现&#39;&#39; @第1行,第94栏。      添加((INT)(的Math.random()* 1000))                                    ^   org.codehaus.groovy.syntax.SyntaxException:期待&#39;}&#39;,发现&#39;&#39; @第1行,第94栏。       在org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:139)       在org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:107)       在org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:236)       在org.codehaus.groovy.control.CompilationUnit $ 1.call(CompilationUnit.java:163)       at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:839)       在org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:544)       在org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:520)       在org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:497)       at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:306)       在groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:287)       在groovy.lang.GroovyShell.parseClass(GroovyShell.java:731)       在groovy.lang.GroovyShell.parse(GroovyShell.java:743)       在groovy.lang.GroovyShell.parse(GroovyShell.java:770)       在groovy.lang.GroovyShell.parse(GroovyShell.java:761)       在com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:148)       在com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:93)       在com.eviware.soapui.model.propertyexpansion.resolvers.EvalPropertyResolver.doEval(EvalPropertyResolver.java:191)       在com.eviware.soapui.model.propertyexpansion.resolvers.EvalPropertyResolver.resolveProperty(EvalPropertyResolver.java:170)       在com.eviware.soapui.model.propertyexpansion.PropertyExpander.expand(PropertyExpander.java:180)       在com.eviware.soapui.model.propertyexpansion.PropertyExpander.expandProperties(PropertyExpander.java:113)       at com.eviware.soapui.impl.wsdl.submit.filters.PropertyExpansionRequestFilter.filterWsdlRequest(PropertyExpansionRequestFilter.java:45)       在com.eviware.soapui.impl.wsdl.submit.filters.AbstractRequestFilter.filterAbstractHttpRequest(AbstractRequestFilter.java:37)       在com.eviware.soapui.impl.wsdl.submit.filters.AbstractRequestFilter.filterRequest(AbstractRequestFilter.java:31)       在com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport.sendRequest(HttpClientRequestTransport.java:184)       在com.eviware.soapui.impl.wsdl.WsdlSubmit.run(WsdlSubmit.java:123)       at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:471)       at java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:334)       at java.util.concurrent.FutureTask.run(FutureTask.java:166)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)       在java.lang.Thread.run(Thread.java:722)   引起:Script16.groovy:1:94:期待&#39;}&#39;,发现&#39;&#39;       在groovyjarjarantlr.Parser.match(Parser.java:211)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.closableBlock(GroovyRecognizer.java:8620)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.appendedBlock(GroovyRecognizer.java:11397)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.pathElement(GroovyRecognizer.java:11349)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.pathExpression(GroovyRecognizer.java:11464)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.postfixExpression(GroovyRecognizer.java:13175)       at org.codehaus.groovy.antlr.parser.GroovyRecognizer.unaryExpressionNotPlusMinus(GroovyRecognizer.java:13144)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.powerExpressionNotPlusMinus(GroovyRecognizer.java:12848)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.multiplicativeExpression(GroovyRecognizer.java:12780)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.additiveExpression(GroovyRecognizer.java:12450)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.shiftExpression(GroovyRecognizer.java:9664)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.relationalExpression(GroovyRecognizer.java:12355)       at org.codehaus.groovy.antlr.parser.GroovyRecognizer.equalityExpression(GroovyRecognizer.java:12279)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.regexExpression(GroovyRecognizer.java:12227)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.andExpression(GroovyRecognizer.java:12195)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.exclusiveOrExpression(GroovyRecognizer.java:12163)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.inclusiveOrExpression(GroovyRecognizer.java:12131)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.logicalAndExpression(GroovyRecognizer.java:12099)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.logicalOrExpression(GroovyRecognizer.java:12067)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.conditionalExpression(GroovyRecognizer.java:4842)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.assignmentExpression(GroovyRecognizer.java:7988)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.expression(GroovyRecognizer.java:9841)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.expressionStatementNoCheck(GroovyRecognizer.java:8314)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.expressionStatement(GroovyRecognizer.java:8739)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.statement(GroovyRecognizer.java:1274)       在org.codehaus.groovy.antlr.parser.GroovyRecognizer.compilationUnit(GroovyRecognizer.java:757)       在org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:130)       ......还有30多个   1错误   ; list.join(&#39;,&#39;)}

2 个答案:

答案 0 :(得分:2)

似乎在属性扩展中,{}中不允许使用花括号${= ... },因为${=与任何闭包,循环,方法中的任何}字符关闭..你尝试添加它。

同时尝试逃避\}内的关闭${= ... }也无济于事。

您甚至无法在}中使用String,以下代码会在 SOAPUI 中引发相同的异常:

<ns:PRODUCTID>${=return '}'}</ns:PRODUCTID>

在这里使用}的唯一方法似乎是嵌套表达式${= ... ${= ... } }。例如,以下嵌套异常有效:

<ns:PRODUCTID>${= 5 + ${= 3+4 } }</ns:PRODUCTID> 
// in raw View you will see <ns:PRODUCTID>12</ns:PRODUCTID> 

然而,它们也无法帮助,因为每个人都有来自闭包,循环,方法的}相同的问题。

似乎实现 SOAPUI 的属性扩展解析器无法处理此问题。好的捕获,也许你可以要求一个新功能。

我没有使用groovy脚本添加变通方法将结果保存在属性中,然后在请求中使用它,因为我完全确定您知道如何执行此操作:)

答案 1 :(得分:0)

我不知道语法错误在哪里。但试试这个:

(0..(Math.random() * 5 as Integer)).collect { Math.random() * 1000 as Integer }.join(',')