3 Replies Latest reply on Aug 22, 2012 8:57 AM by peterfry

    jaxb version used by JBoss AS 7.1Final (date issue/timezone issue)

    peterfry

      I seem to be re-encountering an issue in JBoss AS 7.0 that we first encountered in JBoss 5.

       

      A previous developer described the problem thus:

       

      JAXB 2.1.x DatatypeConverter implementation does not correctly apply timezone offset when printing xs:dateTime string representation of a java.util.Date. The complementary method in DatatypeConverter that parses the string representation into a java.util.Date does apply the current timezone offset. The issue has manifested itself now because we are in BST (GMT + 1).

       

      JAXB 2.1.x DatatypeConverter.printDateTime() outputs:

       

      "1970-01-01T00:00:00Z"

       

      JAXB 2.2.x DatatypeConverter.printDateTime() outputs:

       

      "1970-01-01T00:00:00+01:00"

       

       

      Solution is to ensure that JAXB 2.2.1 version of jaxb-api.jar is present in JBoss server's endorsed library folder for both the web service client jboss instance and the web service

      server instance.

       

      I have replicated the issue with the following client code

       

       

                  XMLGregorianCalendar cal = null;

                  try {

                    cal = DatatypeFactory.newInstance()

                      .newXMLGregorianCalendar(

                          new GregorianCalendar(1970,0,1));

                  } catch (DatatypeConfigurationException e) {

                    // TODO Auto-generated catch block

                    e.printStackTrace();

                  }

       

       

       

       

       

       

      service.doSomething( cal )

       

      In the webservice implementation the string received in the SOAP payload is:

       

      1970-01-01T00:00:00Z

       

      Which corresponds to the JAXB 2.1 behaviour .

       

      What I can't fathom is that the modules repository for the JBoss 7.0 only has the JAXB 2.2 implementation.

       

      With JBoss 5.0 we had to put JAXB 2.2 in the endorsed directory (specified via the system property java.endorsed.dirs) .

       

      Do we have to do a similar thing with JBoss 7.0? Why do we have to do this even though the version in the modules repository is JAXB 2.2?

        • 1. Re: jaxb version used by JBoss AS 7.0Final (date issue/timezone issue)
          peterfry

          I have a few test cases that all seem to be pointing at the jboss-jaxb-api_2.2_spec-1.0.3.Final.jar file .


          If I run


              public static void main( String[] args )
              {
                  GregorianCalendar testCal = new GregorianCalendar();
                  testCal.clear();
                  testCal.set( 1970, 0, 1 );
                  Date testDate = testCal.getTime();
                  System.out.println( "test printing dateTime " + DatatypeConverter.printDateTime( testCal ) );
              }


          Without any jvm arguments it prints:

           

          test printing dateTime 1970-01-01T00:00:00Z

           

          If I pass a JVM argument of -Djava.endorsed.dirs=c:\a_directory_only_containing_jaxb-api.jar , where manifest has the information:

           

          Specification-Title: Java Architecture for XML Binding
          Specification-Version: 2.2.1
          Specification-Vendor: Sun Microsystems, Inc.
          Extension-Name: javax.xml.bind

           

          it prints:

           

          test printing dateTime 1970-01-01T00:00:00+01:00

          If I pass a jvm argument of -Djava.endorsed.dirs=c:\a_directory_only_containing_jboss-jaxb-api_2.2_spec-1.0.3.Final.jar

           

          It prints:

           

          test printing dateTime 1970-01-01T00:00:00Z

           

          So I think the jboss 7.1 version of jaxb is wrong? 

           

          I tried just replacing it to see the version of JAXB from SUN ( 2.2.1) solves the web service problem but I get errors when trying to make web service calls (I can attach those if anybody has ideas )

          • 2. Re: jaxb version used by JBoss AS 7.0Final (date issue/timezone issue)
            peterfry

            Just tried with jaxb-ri-2.2.6 (putting the api, impl and the xjc jar in the endorsed directory) and get

             

            test printing dateTime 1970-01-01T00:00:00+01:00

            • 3. Re: jaxb version used by JBoss AS 7.0Final (date issue/timezone issue)
              peterfry

              This only seems to be a problem when using a DateConverter i.e.

               

              <bindings version="2.1"
                        xmlns="http://java.sun.com/xml/ns/jaxb"
                        xmlns:xs="http://www.w3.org/2001/XMLSchema">
                        xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
                        xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
                        xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
                <globalBindings>              
                   <javaType name="java.util.Date" xmlType="xs:date"            
                         parseMethod="uk.co.abusiness.webservices.DateConverter.parseDate"            
                         printMethod="uk.co.abusiness.webservices.DateConverter.printDate"/>          
                   <javaType name="java.util.Date" xmlType="xs:time"            
                         parseMethod="uk.co.abusiness.webservices.DateConverter.parseTime"            
                         printMethod="uk.co.abusiness.webservices.DateConverter.printTime"/>          
                   <javaType name="java.util.Date" xmlType="xs:dateTime"            
                         parseMethod="uk.co.abusiness.webservices.DateConverter.parseDateTime"            
                         printMethod="uk.co.abusiness.webservices.DateConverter.printDateTime"/>
                   <serializable uid="1" />
                </globalBindings>
              </bindings>

               

              And specifically the printDate, printDateTime, printTime methods. Previously we had followed the various suggestions on the internet and implemented:

               

                      Calendar cal = new GregorianCalendar();
                      cal.setTime( dt );
                      return DatatypeConverter.printDateTime( cal );

               

              It seemed the calls to DatatypeConverter introduced the problem.

               

              Our resolution was to use the JAXB 2.2.1 implementations of the printDate, printDateTime and printTime methods directly/inline (the reference implementation includes the source).