JAVA WEBSERVICE:Unmarshalling Error:输入字符串:“”

时间:2017-11-08 00:52:08

标签: java unmarshalling

我正在通过SoapUI运行web服务。 通过以下请求,

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ofic="http://www.myserver.com/mywebService/">
   <soapenv:Header>
  <ofic:headerRequest>
     <timeStampRequest>2017-11-07</timeStampRequest>
     <username>xxxxxx</username>
     <password>xxxxxx</password>
  </ofic:headerRequest>
  </soapenv:Header>
   <soapenv:Body>
      <ofic:contract>
         <contractNo></contractNo>
      </ofic:contract>
   </soapenv:Body>
</soapenv:Envelope>

我收到了这个回复:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Client</faultcode>
         <faultstring>Unmarshalling Error: For input string: ""</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

属性“contractNo”的类型为“Long”,它不能为空值。我试图验证“contractNo”的值,但似乎在验证此属性之前会触发此解组错误。

有没有办法捕获此解组错误,以显示不同的消息?

提前致谢!!!

(......三个小时后......头疼得厉害......)

在“合同”课程中,我把它放在:

@NotNull(message="cannot be null")
@XmlElement(required = false,nillable=true)
@XmlJavaTypeAdapter(type=long.class, value=XMLLongAdapter.class)
protected long contractNo;

XMLLongAdapter.class是基于这篇文章构建的 - &gt; Marshaling a long primitive type using JAXB

也就是说,我可以验证属性“contractNo”的空条目

我希望它有所帮助。

0 个答案:

没有答案