How to solve No signature of method: static java.lang.String.parseString() is applicable for argument types: (String) values: [testowy]</faultstring>

huangapple go评论69阅读模式
英文:

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[&quot;//invoiceId&quot;] )
def header1 = String.parseString( holder[&quot;//header1&quot;] )
def header2 = String.parseString( holder[&quot;//header2&quot;] )
def invoiceNumber = String.parseString( holder[&quot;//invoiceNumber&quot;] )
def invoiceOrder = Integer.parseInt( holder[&quot;//invoiceOrder&quot;] )


def totalValue = Float.parseFloat( holder[&quot;//totalValue&quot;] )
def categoryId = Integer.parseInt( holder[&quot;//categoryId&quot;] )
def categoryName = String.parseString( holder[&quot;//categoryName&quot;] )
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[&quot;//categoryName&quot;]

然而,我怀疑这可能是有问题的,因为XmlHolder是一个映射,get()方法返回一个Object,所以不清楚会返回什么。但是有一个返回String的方法,这可能是您想要的:

def categoryName = holder.getNodeValue(&quot;//categoryName&quot;)

这个方法似乎接受一个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[&quot;//categoryName&quot;]

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(&quot;//categoryName&quot;)

That method seems to take an xpath expression and return the contents of an XML node as a String.

huangapple
  • 本文由 发表于 2023年1月8日 23:54:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75049200.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定