有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java soapui 2.0.2甚至为最简单的表达式提供了NumberFormatException

我有一个web服务,我为它生成一个示例请求,然后替换所有的?最简单的情况是0。它很好用。然后我替换其中一个值,如下所示:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://interfaces.mypackage.foo.com">
       <soapenv:Header/>
       <soapenv:Body>
          <int:getCheckResults>
             <criteria>
               <startTm>
                 <time>${=0}</time>
               </startTm>
             </criteria>
          </int:getCheckResults>
       </soapenv:Body>
    </soapenv:Envelope>     

(我尝试这样做的原因是,最终,当接口需要一个长的ms值时,我希望传递这样的可读日期):

    <startTm>
      <time>${= new java.util.SimpleDateFormat("MM/dd/yyyy hh:mm z").parse("01/01/2012 04:00 GMT"}</time>
    </startTm>

它总是给我相同的答案,而不是调用服务-这过去是可行的,但我不确定现在有什么不同,也许它在旧版本的SoapUI中工作

    <soapenv:Fault>
       <faultcode>soapenv:Server.generalException</faultcode>
       <faultstring>java.lang.NumberFormatException: For input string: "" Message being parsed:</faultstring>
    </soapenv:Fault>

救命


共 (2) 个答案

  1. # 1 楼答案

    我抛弃了SOAPUI 2.0.2版,安装了最新的4.5.0,现在一切正常。天知道怎么了

    希望这对其他人有帮助

  2. # 2 楼答案

    我建议您使用上下文变量和Groovy脚本

    在这个SOAP请求之前运行的Groovy脚本中,添加如下内容(我没有把代码放进去,但我想你明白我的意思了):

    import java.text.SimpleDateFormat
    Date today
    String formattedDate
    SimpleDateFormat formatter
    Locale currentLocale
    currentLocale = new Locale("en", "US")  
    formatter = new SimpleDateFormat("yyyy-MM-dd", currentLocale)
    today = new Date()
    formattedDate = formatter.format(today)
    log.info(formattedDate)
    context.setProperty("formattedDate", formattedDate)
    

    然后在SOAP请求中输入以下内容:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://interfaces.mypackage.foo.com">
       <soapenv:Header/>
       <soapenv:Body>
          <int:getCheckResults>
             <criteria>
               <startTm>
                 <time>${formattedDate}</time>
               </startTm>
             </criteria>
          </int:getCheckResults>
       </soapenv:Body>
    </soapenv:Envelope>