3 Replies Latest reply on Jan 14, 2016 8:52 PM by bwallis42

    Wildfly Module with JAXB annotations - annotations are not processed

    bwallis42

      How can I get annotated classes that are imported from a module to be processed correctly in the importing war deployment?

       

      I have a module that contains some classes that have JAXB annotations in them. This module is imported into a war file via a dependencies line in its MANIFEST.MF and the JAXB annotated classes are used, from code that runs in the war, for unmarshalling an xml file. This fails with an exception

       

      Error unmarshalling JAXB object, message 'unexpected element (uri:"", local:"user"). Expected elements are (none)'
      

       

      which suggests that the annotated class for the root element has not been processed and so is unknown to the jaxb unmarshaller.

       

      This code was working prior to porting from jboss AS6.1 to Wildfly 10. In doing the port I moved the login module to a wildfly module, it used to be in a deployed jar on the jboss 6.1 (not EAP!) server where it would share the global classloader with the war.

       

      I am running Wildfly 10.0.0.CR4 under java 8 (1.8.0_51).

       

      The annotated class for the root element is as follows

       

      
      @XmlAccessorType(XmlAccessType.FIELD)
      @XmlType(
               name = "",
               propOrder = { "schemaVersion", "userID", "password", "givenName", "familyName", "doctorId", "userRoles", "userProfile","userValidity" }
              )
      @XmlRootElement(name = "user", namespace = "")
      public class User implements java.io.Serializable
      {
      ...
      }
      

       

      This and other similarly annotated classes are packaged inside a jar that is deployed as a module on the server with the following module descriptor

       

      <?xml version="1.0" encoding="UTF-8"?>
      <module xmlns="urn:jboss:module:1.1" name="au.com.infomedix.CPFLoginModule">
          <resources>
              <resource-root path="CPFLoginModule-4.1-SNAPSHOT.jar" />
          </resources>
          <dependencies>
              <module name="org.picketbox" />
              <module name="javax.security.jacc.api" />
              <module name="javax.ejb.api" />
              <module name="org.jboss.as.naming" />
              <module name="javax.api" />
              <module name="javax.servlet.api" />
              <module name="org.slf4j" />
              <module name="com.sun.xml.bind" services="export" export="true" />
          </dependencies>
      </module>
      

       

      This module is providing a loginmodule that uses a stateless session EJB in our application to authenticate the credentials. The login module is invoked as expected and the call to the session bean is performed. During the authentication process in the session bean an XML file is read and unmarshalled using code like this (this is running within our WAR application, not in the module).

       

      
      private static Class[] userJaxbClasses = new Class[]
          {
                  UserDoctorID.class,
                  User.class,
                  UserRole.class,
                  UserProfile.class
          };
      
      ...
      
      JAXBContext context = JAXBContext.newInstance(userJaxbClasses);
      Unmarshaller um = context.createUnmarshaller();
      return (User) um.unmarshal(is);
      

       

      The war file has a manifest.mf file with the following in it so that it can see the 4 classes listed in userJaxbClasses.

       

      Dependencies: org.infinispan, org.apache.xalan, au.com.infomedix.CPFLo
      ginModule annotations
      

       

      When the unmarshal is called, I get the exception

       

      12:54:06,145 DEBUG [jaxb.JAXBValidationErrorHandler] (default task-16) Error unmarshalling JAXB object, message 'unexpected element (uri:"", local:"user"). Expected elements are (none)', col '62', line number ='1', offSet '-1'
      12:54:06,146 ERROR [user.XmlFileUserStore] (default task-16) Error reading user XML file stream for resource system.xml: java.lang.RuntimeException: javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"user"). Expected elements are (none)
        at au.com.infomedix.cpfuser.session.UserSessionUtility.unmarshal(UserSessionUtility.java:378)
      ...