Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-1017

Class with no class-level but at least one @Path annotation not considered a Resource class

    Details

    • Estimated Difficulty:
      Low

      Description

      According to the documentation for RESTEasy 3.0.6.Final, under the introduction to Chapter 4:

      The @javax.ws.rs.Path annotation must exist on either the class and/or a resource method. If it exists on both the class and method, the relative path to the resource method is a concatenation of the class and method.

      This above statement implies that a class without the @Path annotation will still be considered a Resource class (please correct me if my perception of this statement is wrong) as long as this annotation still appears in at least one of the methods.

      Unfortunately, this does not appear to be the case. In the version of RESTEasy that I am using, all resource classes must have the @Path annotation on it at the class level in order to be considered a resource class. Note that, since I am using a Tomcat container, I had to import the Maven dependency resteasy-servlet-initializer. My thoughts about this bug can be proven if we were to look at line 56 of the ResteasyServletInitializer class of the aforementioned RESTEasy module:

               if (clazz.isAnnotationPresent(Path.class))
               {
                  resources.add(clazz);
               }
               else if (clazz.isAnnotationPresent(Provider.class))
               {
                  providers.add(clazz);
               }
               else
               {
                  appClasses.add(clazz);
               }
      

      I think that we should have also been searching through all the methods of the clazz to see if it had at least one method annotated with @Path while considering whether it is a resource class.

      The current workaround for this bug, whenever I have a resource class that I don't want to have a class-level @Path annotation, is to add in the class-level annotation of @Path("").

      If this is an accepted bug, then I can volunteer to submit a Git pull request for the bug fix. I can also show the output from my server's console as a result of this bug if requested, but I don't personally believe it is necessary, the source code I have shown above should be enough.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                ron_sigal Ronald Sigal
                Reporter:
                ecbrodie Evan Brodie
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: