jersey
  1. jersey
  2. JERSEY-1447

ClientRequestContext#getEntityAnnotations() returns no annotations

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.0-m08
    • Fix Version/s: 2.0-m10, 2.0
    • Component/s: core
    • Labels:
      None

      Description

      Javadoc says:

      Get the annotations attached to the entity.

      Attaching the annotations to an entity:

      @Provider
      public class Provider {
      }
      
      Annotation[] annotations = Provider.class.getAnnotations();
      ClientRequestFilter filter = new ClientRequestFilter(){
      	@Override
      	public void filter(ClientRequestContext context) throws IOException {
                   Annotation[] annotations = context.getEntityAnnotations();
      //annotations is an empty array!
      	}
      }
      
      Entity<String> post = Entity.entity("test", MediaType.WILDCARD_TYPE,
      				annotations);
      Client client = ClientFactory.newClient();
      Configuration config = client.configuration();
      config.register(filter);
      WebTarget target = client.target("http://localhost:8080/");
      Invocation.Builder builder = target.request();
      Invocation invocation = builder.buildPost(post); //!!send entity with attached annotations
      Response response = invocation.invoke();
      

        Activity

        Hide
        Miroslav Fuksa added a comment - - edited

        Just a note:
        We have discussed whether also annotation from entity class should be returned.
        example:

        @MyAnnotation
        public class MyEntity {
        }
        
        public final class MyFilter implements ClientRequestFilter {
        
            @Override
            public void filter(ClientRequestContext request) throws IOException {
        
              ???? request.getEntityAnnotations() // should return also MyAnnotaion?
              ...
            }
            
        }
        

        We have decided to make it in the same way as the server handles it. Server does not return class annotations. ContainerResponseContext.getEntityAnnotations returns:
        1. annotaions attached to entity in ResponseBuilder, example: Response response = Response.ok().entity("get", new Annotation[]

        {ANNOTATION}

        ).build()
        2. resource method annotations

        Therefore the client will beheave the same and ClientRequestContext.getEntityAnnotations() will not return class annotaions.

        Show
        Miroslav Fuksa added a comment - - edited Just a note: We have discussed whether also annotation from entity class should be returned. example: @MyAnnotation public class MyEntity { } public final class MyFilter implements ClientRequestFilter { @Override public void filter(ClientRequestContext request) throws IOException { ???? request.getEntityAnnotations() // should return also MyAnnotaion? ... } } We have decided to make it in the same way as the server handles it. Server does not return class annotations. ContainerResponseContext.getEntityAnnotations returns: 1. annotaions attached to entity in ResponseBuilder, example: Response response = Response.ok().entity("get", new Annotation[] {ANNOTATION} ).build() 2. resource method annotations Therefore the client will beheave the same and ClientRequestContext.getEntityAnnotations() will not return class annotaions.

          People

          • Assignee:
            Miroslav Fuksa
            Reporter:
            jan.supol
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 3 hours
              3h
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 2 hours Time Not Required
              2h