开发者

Jersey Guice Accessing Post Parameters

开发者 https://www.devze.com 2023-01-27 17:41 出处:网络
I have a Jersey client that is hooked up using Guice. Really hooked up :) The resources are also created using Guice.

I have a Jersey client that is hooked up using Guice. Really hooked up :)

The resources are also created using Guice.

Something like:

@Inject
class TestResource {
  @Inject DataFatcher fetcher, 
  ...
  ...
}

Now, DataFetcher object is create开发者_运维百科d using Guice and has deep nested guice-created objects using composition. Now, some of these object need access to parameters passed over using POST.

I have a HttpServletModule that does that for me. I I thought that does the right work.


HttpServletModule.java

Map<String, String[]> providerRequestParametersMap(HttpServletRequest reuquest) {
  request.getParametersMap()
}

Now, unfortunately, It looks like Jersey, has already intercepter the request and removed the POST parameters from the request parameters Map. So, this Map of mine is empty.

How, can I get access to the POST Parameters in Guice ? I do not want to Inject the Form of MultivaledMap in the Resource directly, since that will need to be passed down all the way from the Resource which will mess up my design.

Any tips greatly appreciated. I can think of creating a Filter that intercepts the HttpServletRequest before the Jersey filters kicks in. Hoping that there is a better,easier solution :).


The easiest solution is probably a servlet Filter that does what you suggest: intercepting the HttpServletRequest before it's handled by Jersey and setting data in a request-scoped object.

If you're using Guice Servlet, filtering is at least a few keystrokes less setup than it is in web.xml.

If you'd prefer a Jersey-only solution, you could use a ContainerRequestFilter. This gives you access to ContainerRequest, which in turn provides you with a Form (a javax.ws.rs.core.MultivaluedMap).

0

精彩评论

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