Jersey: what does “couldn't find grammar element” mean?

后端 未结 1 1072
说谎
说谎 2021-01-18 05:29

After upgrading Jersey from version 1.15 to 1.17 it started to log the following messages:

Apr 2, 2013 5:13:06 PM com.sun.jersey.server.wadl.generators.Abstr         


        
相关标签:
1条回答
  • 2021-01-18 06:29

    I had the same "info" message as well. I didn't manage to fix it (yet) for basic java types (Boolean, String...) but for my own custom classes if I add the @XmlRootElement annotation and a default no-param constructor the message dissapears.

    Digging into jersey source code I noticed the class "WadlGeneratorJAXBGrammarGenerator" the following code :

    Object parameterClassInstance = null;
    try {
        Constructor<?> defaultConstructor = type.getDeclaredConstructor();
        defaultConstructor.setAccessible(true);
        parameterClassInstance = defaultConstructor.newInstance();
    } catch (InstantiationException ex) {
        LOGGER.log(Level.FINE, null, ex);
    } catch (IllegalAccessException ex) {
        LOGGER.log(Level.FINE, null, ex);
    } catch (IllegalArgumentException ex) {
        LOGGER.log(Level.FINE, null, ex);
    } catch (InvocationTargetException ex) {
        LOGGER.log(Level.FINE, null, ex);
    } catch (SecurityException ex) {
        LOGGER.log(Level.FINE, null, ex);
    } catch (NoSuchMethodException ex) {
        //getting here for Boolean/String and some other primitive data type
        LOGGER.log(Level.FINE, null, ex);
    }
    
    if (parameterClassInstance==null) {
        return null;
    }
    

    So basically there is no default constructor for String, Boolean and few others then it throws a NoSuchMethodException therefore it return nulls and log the info message.

    So still no idea why it happens but in my case the solution was to disable the wadl generation since I was not using it. Just add the following param to your web.xml

      <init-param>
             <param-name>com.sun.jersey.config.feature.DisableWADL</param-name>
             <param-value>true</param-value>
         </init-param>
    
    0 讨论(0)
提交回复
热议问题