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

Resteasy-link annotations do not work on supertypes

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 3.0.11.Final, 3.0.13.Final
    • None

      I am trying to implement a web service using the automatic link generation features of resteasy-links. If I put the service definition into a single class, everything works as expected. However, if I create an interface with the jaxrs annotations (e.g. Path, GET, etc.) and resteasy-link annotations (e.g. AddLinks, LinkResource, etc.), the automatic link generation will no longer work.

      I have tracked this down to the RestUtils class which uses Method.getAnnotation and Method.isAnnotationPresent to determine whether and how the links should be injected. However, these calls will return null and false respectively, if an annotation is declared on a supertype.

      I understand that this behavior might be intentional for AddLinks and LinkResource(s) - which is why this might not be a bug. However, as far as I understand jaxrs (which probably does not mean much), it should be possible to define the Path, GET, etc. annotations on supertypes. With the current implementation, this does not work since even these annotations are only searched on the method that will receive the dispatch from the framework servlet. This, in turn, forces developers to replicate the jaxrs definitions made in the interface (or base class) also in the service implementation.

      I have been playing around with fixing this in my own code by replacing the getAnnotation and isAnnotationPresent calls in the RestUtils class with a traversal of the inheritance hieararchy. I am attaching this "fix", but it seems somewhat wasteful to do the traversal multiple times for every call. Anyway, I think that it shows the idea. Thanks for all the work you do.

              rsigal@redhat.com Ronald Sigal
              handte Marcus Handte (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated: