Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAX-WS method's Decimal field is NULL when String value is passed

I have Jaxws Soap web service. My "myMethod" method have a decimal type field.

Here is my web service interface:

@WebService(name = "myWs", targetNamespace = "someNamespace")
@Local 
public interface myWsPortType {     
    @WebMethod  
    @RequestWrapper(localName = "myMethod", className = "com.example.MyMethodRequest")  
    public Result myMethod(@WebParam(name = "parameters", mode = Mode.IN) MyMethodParameters parameters); 
}

This is parameter class

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType()
public class MyMethodParameters implements java.io.Serializable {
    @FieldValidation(maxLength = 12)
    @XmlElement(name = "myField", required = false)
    private java.math.BigDecimal myField;
}

Everything works correctly when I pass Correct type of data in myField.

But, the problem is that when I call myMethod and pass String value (instead of Decimal) as parameter no exception is thrown and myField's value is null

Here's Soap Request example

<soapenv:Envelope>
   <soapenv:Header/>
   <soapenv:Body>
      <iss:myMethod>
         <parameters>
            <myField>test</myField>
         </parameters>
      </iss:myMethod>
   </soapenv:Body>
</soapenv:Envelope>

How can I make my ws throw exception when incorrect data type is passed?

like image 513
mariami Avatar asked Oct 22 '22 21:10

mariami


1 Answers

It lookls like the XSD Schema is generated just fine, what you are missing is the SchemaValidation annotation to tell JAX-WS to validate the requests and responses with the schema.

Just add @SchemaValidation to your service:

@WebService(name = "myWs", targetNamespace = "someNamespace")
@SchemaValidation
@Local 
public interface myWsPortType { ... }
like image 108
Aviram Segal Avatar answered Nov 02 '22 07:11

Aviram Segal