英文:
How to solve No signature of method: static java.lang.String.parseString() is applicable for argument types: (String) values: [testowy]</faultstring>
问题
在SOAP模拟服务中,我想要根据请求中的值生成动态响应,所以我创建了脚本,但是我遇到了错误。
我的脚本如下:
def holder = new com.eviware.soapui.support.XmlHolder(mockRequest.requestContent)
// 获取参数
def invoiceId = Integer.parseInt(holder["//invoiceId"])
def header1 = String.parseString(holder["//header1"])
def header2 = String.parseString(holder["//header2"])
def invoiceNumber = String.parseString(holder["//invoiceNumber"])
def invoiceOrder = Integer.parseInt(holder["//invoiceOrder"])
def totalValue = Float.parseFloat(holder["//totalValue"])
def categoryId = Integer.parseInt(holder["//categoryId"])
def categoryName = String.parseString(holder["//categoryName"])
requestContext.result = "$invoiceId $header1 $invoiceNumber $invoiceOrder $invoiceDate $dueDate $totalValue $categoryId $categoryName"
问题出在String.parseString
这里,我不知道为什么。
对于其他参数,一切都正常。
有人可以解释一下为什么我会得到这个错误吗?
英文:
In soap mock service i want to have dynamic response base on value in request so i create the script but i get error
<faultstring>Failed to dispatch using script; groovy.lang.MissingMethodException: No signature of method: static java.lang.String.parseString() is applicable for argument types: (String) values: [testowy]</faultstring>
My script looks that
def holder = new com.eviware.soapui.support.XmlHolder( mockRequest.requestContent )
// get arguments
def invoiceId = Integer.parseInt( holder["//invoiceId"] )
def header1 = String.parseString( holder["//header1"] )
def header2 = String.parseString( holder["//header2"] )
def invoiceNumber = String.parseString( holder["//invoiceNumber"] )
def invoiceOrder = Integer.parseInt( holder["//invoiceOrder"] )
def totalValue = Float.parseFloat( holder["//totalValue"] )
def categoryId = Integer.parseInt( holder["//categoryId"] )
def categoryName = String.parseString( holder["//categoryName"] )
requestContext.result = invoiceId header1 invoiceNumber invoiceOrder invoiceDate dueDate totalValue categoryId categoryName
The problem is with String.parseString i didint know why
for every other arguments its ok
can someone explain why i get this error
答案1
得分: 0
在JDK中没有String.parseString
方法。您想要做的是类似以下的操作:
def categoryName = holder["//categoryName"]
然而,我怀疑这可能是有问题的,因为XmlHolder
是一个映射,get()
方法返回一个Object
,所以不清楚会返回什么。但是有一个返回String的方法,这可能是您想要的:
def categoryName = holder.getNodeValue("//categoryName")
这个方法似乎接受一个XPath表达式并将XML节点的内容作为String返回。
英文:
There is no method String.parseString
in the JDK. What you want to do is something like the following:
def categoryName = holder["//categoryName"]
However, I suspect that may even be questionable because XmlHolder
is a map and get()
returns an Object
so it's unknown what that's going to return. But there is a method that returns a String which is what you're after so you might do this instead:
def categoryName = holder.getNodeValue("//categoryName")
That method seems to take an xpath expression and return the contents of an XML node as a String.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论