Jersey 2.*. Custom InjectionResolver and "A HTTP GET method ... should not consume any entity"
Asked Answered
B

0

7

I have followed Michal's guide from his answer to this question [1] on implementing custom annotation for injecting arbitrary things into resource methods. This (gist) [2] contains a minimalistic testbed adapted from the jersey-quickstart-grizzly2 archetype. I will refer to it in the following text.

I encountered a few problems:

  1. My resolver is parametrized type (or at least it would make things much more cleaner, in my opinion) and thus I can not bind it in my binder the way Michal suggests.

    // Instead of the suggested:
    // bind(MyInjectionResolver.class).to(new TypeLiteral<InjectionResolver<MyAnnotation>>() {}).in(Singleton.class);
    // I do:
    bind(myInjectionResolverObject).to(new TypeLiteral<InjectionResolver<MyAnnotation>>() {});
    
  2. When I use MyAnnotation in the resource method, I get the following warning on server start-up (but the server still starts):

    WARNING: The following warnings have been detected: WARNING: A HTTP GET method, public java.lang.String com.example.MyResource.get02(java.lang.Integer,java.lang.String), should not consume any entity.
    
  3. When I request the resource (curl -X GET http://localhost:8080/myresource/01/aa), I get 02: value = aa; providedValue = null instead of the expected 02: value = aa; providedValue = 123.

  4. The MyResolver.resolve method is never executed (but MyBinder.configure is executed).

  5. (This does not concern the testbed application, but I encounter the problem in a slightly more complicated code: the resource method is never executed and the server responds with 500 No content to map to Object due to end of input)

Any ideas as to what I might be doing wrong?

Bertrando answered 28/8, 2013 at 12:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.