• Post Reply Bookmark Topic Watch Topic
  • New Topic

Date Validation in JAX-RPC web service  RSS feed

Shyam Viji
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am facing issue in validating xsd:date type element in Java web service.
We are provided with the wsdl and related xsd; we develop the Java web service on top of it(Top down approach) in JAX-RPC style. One of the inputs to it is, date whose schema definition type is xsd:date. In the Java layer(on reaching the SOAPBindingImpl java class), its associated data type is java.util.Calendar.

The problem here is, when we enter a date eg: 2010-01-32 in the input xml, it is manipulated to 2010-02-01 when it reaches the Java layer. We are not able to validate the date at this point as the Calendar object is auto manipulated and we never know if it is really Feb1st or manipulated value.

In standalone java, we could set the Calendar object’s Lenient flag to false which will prevent auto manipulation.
Calendar cal = Calendar.getInstance();
cal.setLenient(false); // default value is true
cal.getTime(); // Exception is thrown here – IllegalArgumentException DAY_OF_MONTH

The same strategy, when applied here- the Leniency has no effect as the Calendar object’s value is Feb1st before setting this flag. So we are not able to validate this.

Workaround would be either to change xsd:date to xsd:string, get the String value, covert to Date and validate or forcing the web service consumer to validate the date before invoking the web service.
But before proceeding with this, I want to know if there is any way to validate the date in java or this is really a limitation with JAX-RPC web services.

Your valuable inputs are appreciated.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!