Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-10319

NameBinding annotations on resources are ignored in subresources

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Rejected
    • Affects Version/s: 12.0.0.Final
    • Fix Version/s: None
    • Component/s: REST
    • Labels:
      None
    • Steps to Reproduce:
      Hide
      • Create a JAX-RS application that exposes the resource provided in the description.
      • Call GET /demo. The returned value is, as expected, "A filtered value".
      • Call GET /demo/subresource. The returned value is: "A value" instead of "A filtered value".
      Show
      Create a JAX-RS application that exposes the resource provided in the description. Call GET /demo. The returned value is, as expected, "A filtered value". Call GET /demo/subresource. The returned value is: "A value" instead of "A filtered value".

      Description

      The following JAX-RS resource exposes two resources via a GET operation: /demo and /demo/subresource. The first one via a sub-resource method, the latter via a sub-resource locator. Additionally, a response filter is binded to the JAX-RS resource class to modify the response. From the JAX-RS 2.0 spec, ยง6.5.2 Name Binding:

      Binding annotations that decorate resource classes apply to all resource methods defined in them.

      However, the binding annotation is not applying to the sub-resource locator method. This happens when the name binding annotation is on the resource class or on the sub-resource locator method. Annotating the sub-resource class or the method within works as expected, though.

      Below is the code needed to reproduce this issue:

      The resource and subresource
      @DemoNameBinding
      @Produces(MediaType.APPLICATION_JSON)
      @Path("/demo")
      public class DemoResource {
      
          @GET
          public String getDemoValue() {
              return "A value";
          }
      
          @Path("/subresource")
          public DemoSubResource getSubResource() {
              return new DemoSubResource();
          }
      
          public class DemoSubResource {
      
              @GET
              public String getDemoValue() {
                  return "A value";
              }
          }
      }
      
      The filter
      @Provider
      @DemoNameBinding
      public class SomeFilter implements ContainerResponseFilter {
      
          @Override
          public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {
              responseContext.setEntity("A filtered value");
          }
      }
      
      The binding
      @NameBinding
      @Target({ElementType.TYPE, ElementType.METHOD})
      @Retention(RetentionPolicy.RUNTIME)
      public @interface DemoNameBinding {
      }
      

        Attachments

          Activity

            People

            Assignee:
            asoldano Alessio Soldano
            Reporter:
            jestevezsanchez Javier Estevez Sanchez (Inactive)
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: