Search code examples
javajaxbsaxunmarshallingwildfly-10

Wildfly 10 UnmarshalException in empty date tags in the response


We are migrating our application from Jboss 6 to Wildfly 10, most the web services are running ok, but we are facing a problem with empty date tags in the response from an external web service:

java.security.PrivilegedActionException: javax.xml.bind.UnmarshalException
- with linked exception:
[com.sun.istack.SAXParseException2; lineNumber: 1; columnNumber: 784; ]


Caused by: java.lang.IllegalArgumentException: 
at org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl$Parser.parseBigInteger(Unknown Source)
at org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl$Parser.parse(Unknown Source)
at org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl.<init>(Unknown Source)
at org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl.newXMLGregorianCalendar(Unknown Source)
at __redirected.__DatatypeFactory.newXMLGregorianCalendar(__DatatypeFactory.java:180)
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$12.parse(RuntimeBuiltinLeafInfoImpl.java:592)
... 158 more

The line and column are the start of the following element

...<ADATE><date />...

As you can see date is empty and causes the parser to fail (I assume that based on the evidence)

This is a fragment of the WSDL definition for that XML element:

   <xsd:element name="ADATE">
      <xsd:complexType>
            <xsd:sequence>
               <xsd:element name="date" minOccurs="1" maxOccurs="100" type="xsd:date"/>
            </xsd:sequence>
      </xsd:complexType>
   </xsd:element>

We have generated our client classes with Apache CXF 3.1.6 as: wsdl2java -frontend jaxws21 ....

  • When using SEIStub implementation the call works for the webservice.
  • When using the same code inside of Wildfly it does not work throwing the described exception.
  • Is this all info needed?

Is there any way another JAXB implementation that can be configured in Wildfly 10?, how?

Thanks


Solution

  • We created an extension of the XmlAdapter and we declared the class in the package-info.java (from the response folder -> "sysrpc", an old cxf) as following:

    package XXX; 
    
    import javax.xml.bind.annotation.adapters.XmlAdapter;
    import javax.xml.datatype.DatatypeFactory;
    import javax.xml.datatype.XMLGregorianCalendar;
    
    import java.util.Date;
    
    
    public class XMLGregorianCalendarXmlAdapter extends XmlAdapter<String, XMLGregorianCalendar>{
    
    @Override
    public XMLGregorianCalendar unmarshal(String v) throws Exception {
        if(v==null ||  v.trim().isEmpty()) {
            return null;
        }
        return DatatypeFactory.newInstance().newXMLGregorianCalendar(v);
    }
    
    @Override
    public String marshal(XMLGregorianCalendar v) throws Exception {
        return v==null ? null : /*do something with the XMLGregorianCalendar */;
    }
    
    }
    

    Then in the package-info.java of the generated classes from wsdl2java command

    @javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters
    ({
       @javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(value=XXX.XMLGregorianCalendarXmlAdapter.class,type=javax.xml.datatype.XMLGregorianCalendar.class),
       @javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(value=XXX.XMLGregorianCalendarXmlAdapter.class,type=javax.xml.datatype.XMLGregorianCalendar.class)
    })
    @javax.xml.bind.annotation.XmlSchema(namespace = "urn:external-web-service:SYSRPC")
    package YYYY.sysrpc;
    

    To debug the communication with an external web service:

    in the standalone.xml (located in $WILDFLY_HOME/standalone/configuration)

    add

    <property name="org.apache.cxf.logging.enabled" value="true"/>
    

    At the end of the system-properties tag