Jersey 2.*. Custom InjectionResolver and “A HTTP GET method … should not consume any entity”

旧城冷巷雨未停 提交于 2019-12-07 04:38:03

问题


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?

来源:https://stackoverflow.com/questions/18488622/jersey-2-custom-injectionresolver-and-a-http-get-method-should-not-consu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!