This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Web Services and the fly likes Date Validation in JAX-RPC web service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Date Validation in JAX-RPC web service" Watch "Date Validation in JAX-RPC web service" New topic
Author

Date Validation in JAX-RPC web service

Shyam Viji
Greenhorn

Joined: Jun 24, 2008
Posts: 5
Hi,

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.set(2010,01,32);
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Date Validation in JAX-RPC web service