开发者

Getting HttpServletRequestWrapper in Jersey

I wrote an HttpServletRequestWrapper named HTTPRequest that reads the full HTTP POST body for further use. This one is based in the code at http://natch3z.blogspot.com/2009/01/read-request-body-in-filter.html

My Jersey server application needs to get this wrapper to read the body. Unfortunately, I do开发者_运维知识库n't know how to do that.

I've tried putting

@Context HTTPRequest request;

but it does not work (Missing dependency for field).

I've tried too doing:

@Context HttpServletRequest request;

then casting to HTTPRequest, it didn't work neither ($ProxyXXX cannot be cast to HTTPRequest).

I've searched for information in the Internet but I cannot find anything regarding this. Any idea? :)

Thanks!


I don't quite understand: HTTPRequest is your objects extending the HttpServletRequestWrapper, right?

So if you want Jersey to inject it via the @Context annotation, you need to implement the ContextResolver. Actually in your case it should be easy:

@Provider
HTTPRequestContextResolver implements ContextResolver<HTTPRequest> {

@Context HttpServletRequest request;

  HTTPRequest getContext(Class<?> type) {
      return new HTTPRequest(request);
  }
}

Updated: If you already wrapped the original request in a filter, you may have a problem to get it, since Jersey wraps the original request using the dynamic proxy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜