1

We invoke a backend call using JAX-RPC. I have generated the JAX-RPC client using RAD8.5 and with WSDL/XSD files provided by our backend. Our client application gives us a String date value formatted as yyyyMMdd (20130720). The backend application requires this value formatted as yyyy-MM-ddZ.

Using the JAX-RPC generated objects it requires a Calendar object for this input. So I create a Calendar object converted to UTC (code below) and pass it in. The resulting XML is missing the "Z" on the end of my date. 2013-07-20.

So my question is, using JAX-RPC how do I get it to include the "Z" on the end of my date to meet the requirement of my backend? Is there something I need to do to the Calendar object or anything I to my JAX-RPC implementation?

Code for calendar creation

    String requestedDate = "20130720"; //This is a parameter in a method.
    Calendar requestedDateCal = Calendar.getInstance();
    int year = 0;
    int month = 0;
    int day = 0;

    year = Integer.parseInt((String) requestedDate.substring(0, 4));
    month = Integer.parseInt((String) requestedDate.substring(4, 6));
    day = Integer.parseInt((String) requestedDate.substring(6, 8));

    requestedDateCal = DateTimeUtils.convertToGMTCalendar(year, month, day, 0, 0, 0, 0);

Code For convertToGMTCalendar()

    Calendar localCalendar = convertToLocalCalendar(year, month, date, hour, minute, second, utcOffset);
    TimeZone gmtTimeZone = TimeZone.getTimeZone("UTC");
    Calendar gmtCalendar = Calendar.getInstance(gmtTimeZone);
    gmtCalendar.setTimeInMillis(localCalendar.getTimeInMillis());
    return gmtCalendar;

Code for convertToLocalCalendar()

    TimeZone aTimeZone =
        TimeZone.getTimeZone(TimeZoneConversion.GMT.getTimeZoneString() + Integer.toString(utcOffset));

    Calendar localCalendar = Calendar.getInstance();
    localCalendar.clear();

    localCalendar.setTimeZone(aTimeZone);
    localCalendar.set(year, month - 1, date, hour, minute, second);

    return localCalendar;
John
  • 73
  • 7
  • "The backend application requires this value formatted as yyyy-MM-ddZ" - any chance you can fix it? That's a really strange format, as a date doesn't *have* a time zone or an offset from UTC. I can't remember ever seeing a format like that. – Jon Skeet Jul 17 '13 at 19:19
  • I agree and I would love to but unfortunately I can't. At least not in the time frame that I have. They also have a format in the XSD for a date without a timezone. I plan on bring it up to that team to see if we can change it but these schemas are so old I doubt that they'll budge.The problem I'm having is if I don't send it with a "Z", they will throw a validation error back at me. Originally we were using XMLBeans and it was putting it there for us, but we're trying to move off of that. – John Jul 17 '13 at 19:25
  • Check Filip's answer, here: http://stackoverflow.com/questions/6143224/how-do-i-represent-dates-without-the-timezone-using-apache-cxf – Mohamed Ennahdi El Idrissi Jul 10 '15 at 12:45

0 Answers0