Axis2
  1. Axis2
  2. AXIS2-4075

AXIS2 1.4.1 does not support java.util.Date type

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Incomplete
    • Affects Version/s: 1.4.1
    • Fix Version/s: None
    • Component/s: adb
    • Labels:
      None
    • Environment:
      windows xp sp2 + tomcat 5.5 + java 1.5 + axis2 1.4.1

      Description

      Hi, I found that the axis2 1.4.1 does not support java.util.Date type.

      1)WSDL
      AXIS2 1.4.1 should map java.util.Date to xs:date in the WSDL, rahter than xs:dateTime(see the attached wsdl).

      2)deserialize and serialize ISO xml DATE string
      AXIS2 1.4.1 can not construct a java.util.Date object from a ISO xml date string, for example, "2001-01-01". It threw an exception, "date string can not be less than 19 charactors". (more detail can be found in the attached exception.txt).

      1. 1_5_1_DateService.wsdl
        4 kB
        MH
      2. DateService.aar
        1 kB
        yong yang
      3. DateService.java
        0.1 kB
        yong yang
      4. DateService.wsdl
        4 kB
        yong yang
      5. exception.txt
        3 kB
        yong yang

        Issue Links

          Activity

          Hide
          Amila Chinthaka Suriarachchi added a comment -

          fixed in the trunk

          Show
          Amila Chinthaka Suriarachchi added a comment - fixed in the trunk
          Hide
          MH added a comment - - edited

          I think this is the bug:

          org.apache.axis2.databinding.typemapping.SimpleTypeMapper:

          public static Object makeCalendar(String source)

          { return ConverterUtil.convertToDateTime(source); }

          public static Object makeDate(String source)

          { return ConverterUtil.convertToDateTime(source).getTime(); }

          Method makeDate should use existing method ConverterUtil.convertToDate instead of ConverterUtil.convertToDateTime.

          Show
          MH added a comment - - edited I think this is the bug: org.apache.axis2.databinding.typemapping.SimpleTypeMapper: public static Object makeCalendar(String source) { return ConverterUtil.convertToDateTime(source); } public static Object makeDate(String source) { return ConverterUtil.convertToDateTime(source).getTime(); } Method makeDate should use existing method ConverterUtil.convertToDate instead of ConverterUtil.convertToDateTime.
          MH made changes -
          Attachment 1_5_1_DateService.wsdl [ 12439258 ]
          Hide
          MH added a comment - - edited

          I have tested (on 1.5.1) the attached DataService.java using the POJO way - axis creates WSDL on the fly. The date is mapped to xs:date (hundred percent sure - attached file: 1_5_1_DateService.wsdl ). That's fine.
          Then I generate a client, run it with Date argument and I get "date string can not be less than 19 charactors" exception. It looks like you can't use POJO style webservice with java.util.Date. If I use soapUI and create an INVALID request with "2001-01-01T00:00:00Z" instead of "2001-01-01" then the service works.

          Show
          MH added a comment - - edited I have tested (on 1.5.1) the attached DataService.java using the POJO way - axis creates WSDL on the fly. The date is mapped to xs:date (hundred percent sure - attached file: 1_5_1_DateService.wsdl ). That's fine. Then I generate a client, run it with Date argument and I get "date string can not be less than 19 charactors" exception. It looks like you can't use POJO style webservice with java.util.Date. If I use soapUI and create an INVALID request with "2001-01-01T00:00:00Z" instead of "2001-01-01" then the service works.
          Hide
          Mauro Molinari added a comment -

          So, it seems to be a problem with java2wsdl.

          I use contract first approach, so I'm writing my own WSDLs and using wsdl2java. As I said, my case, every xs:date is mapped to java.util.Date, while every xs:dateTime is mapped to java.util.Calendar. At runtime, Axis2 takes care of the conversions, in both directions.

          So, manually changing the WSDLs, as Lucas suggests, seems to be the correct workaround for this. However, I would have said the change were required for both requests and responses.

          Show
          Mauro Molinari added a comment - So, it seems to be a problem with java2wsdl. I use contract first approach, so I'm writing my own WSDLs and using wsdl2java. As I said, my case, every xs:date is mapped to java.util.Date, while every xs:dateTime is mapped to java.util.Calendar. At runtime, Axis2 takes care of the conversions, in both directions. So, manually changing the WSDLs, as Lucas suggests, seems to be the correct workaround for this. However, I would have said the change were required for both requests and responses.
          Hide
          Lucas Moten added a comment -

          I have this problem in my environment under 1.4.x, and unless it was overhauled with Date vs Calendar I'd assume that 1.5.1 is the exact same issue. Perhaps the following may be helpful (either in determining the cause, or for workarounds)

          I have objects that use the java 'Date' data type. When I run java2wsdl, the wsdls generate with dateTime for both requests and responses. Then wsdl2java for client stubs are performed. I believe the dateTime however gets converted to a Calendar data type which doesn't work. So, I have to manually alter the generated WSDLs such that one direction is overridden to xsd:date, and the other direction is xsd:dateTime. While not optimal, for fields that truly are only dates this is doable. For fields where time is important, I have no solution but perhaps not using java.util.Date and instead using java.util.Calendar may give greater request vs response consistency. I believe this is consistent with MH's and Mauro's comment in that I'm getting xs:date on responses, and have to populate xs:dateTime on requests.

          Show
          Lucas Moten added a comment - I have this problem in my environment under 1.4.x, and unless it was overhauled with Date vs Calendar I'd assume that 1.5.1 is the exact same issue. Perhaps the following may be helpful (either in determining the cause, or for workarounds) I have objects that use the java 'Date' data type. When I run java2wsdl, the wsdls generate with dateTime for both requests and responses. Then wsdl2java for client stubs are performed. I believe the dateTime however gets converted to a Calendar data type which doesn't work. So, I have to manually alter the generated WSDLs such that one direction is overridden to xsd:date, and the other direction is xsd:dateTime. While not optimal, for fields that truly are only dates this is doable. For fields where time is important, I have no solution but perhaps not using java.util.Date and instead using java.util.Calendar may give greater request vs response consistency. I believe this is consistent with MH's and Mauro's comment in that I'm getting xs:date on responses, and have to populate xs:dateTime on requests.
          Hide
          Mauro Molinari added a comment -

          Are you sure that parameter isn't defined in WSDL as xs:dateTime instead of xs:date? If so, consider that Axis2 maps xs:dateTime to Calendar, while xs:date to Date.

          I've worked with Axis2 1.5 and dates with no problems.

          Show
          Mauro Molinari added a comment - Are you sure that parameter isn't defined in WSDL as xs:dateTime instead of xs:date? If so, consider that Axis2 maps xs:dateTime to Calendar, while xs:date to Date. I've worked with Axis2 1.5 and dates with no problems.
          Hide
          MH added a comment - - edited

          Tested on Axis 1.5.1
          Problem 1) was fixed - java.util.Date is mapped to xs:date
          The problem 2) still exists on Axis 1.5.1: correct xs:date in request (e.g. "2001-01-01") causes exception "date string can not be less than 19 charactors".

          This is a serious problem. Please reopen.

          Show
          MH added a comment - - edited Tested on Axis 1.5.1 Problem 1) was fixed - java.util.Date is mapped to xs:date The problem 2) still exists on Axis 1.5.1: correct xs:date in request (e.g. "2001-01-01") causes exception "date string can not be less than 19 charactors". This is a serious problem. Please reopen.
          Andreas Veithen made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Incomplete [ 4 ]
          Hide
          Andreas Veithen added a comment -

          No feedback from reporter.

          Show
          Andreas Veithen added a comment - No feedback from reporter.
          Andreas Veithen made changes -
          Link This issue is related to AXIS2-4370 [ AXIS2-4370 ]
          Hide
          Amila Chinthaka Suriarachchi added a comment -

          This already has fixed. please have a look at with a nightly build.

          Show
          Amila Chinthaka Suriarachchi added a comment - This already has fixed. please have a look at with a nightly build.
          yong yang made changes -
          Attachment DateService.java [ 12391808 ]
          yong yang made changes -
          Field Original Value New Value
          Attachment exception.txt [ 12391805 ]
          Attachment DateService.wsdl [ 12391806 ]
          Attachment DateService.aar [ 12391807 ]
          yong yang created issue -

            People

            • Assignee:
              Unassigned
              Reporter:
              yong yang
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development