0

I'm running via SoapUI a webservice. With the following request,

<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>

i'm obtaining this response:

<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>

The attribute "contractNo" is type "Long", and it can't have a null value. I was trying to validate the value of "contractNo", but it seems that this unmarshalling error fires before the validation of this attribute.

Is there a way to trap this unmarshalling error , in order to show a different message?

Thanks in advance!!!

(...three hours later + a horrible headache ...)

SOLUTION

In the class "Contract" i put this:

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

XMLLongAdapter.class was built based on this post --> Marshaling a long primitive type using JAXB

And that is, i can validate the null entry for the attribute "contractNo"

I hope it helps.

Javi
  • 19
  • 1
  • 7

0 Answers0