I am using jersey implementation of JAX-RS specification, written specific methods to handle each HTTP request types i.e. POST, GET. PUT and DELETE. But I want to know how we can handle all these requests in a single method. May be its a trivial question, please share your thoughts.
Asked
Active
Viewed 531 times
0
-
3does it make sense ? can you do all the things with your hands only or your each organ does each specific functionality ? – user3470953 Apr 24 '14 at 04:26
-
1There are valid cases for this. For instance I'm wring a way for my jersey service to handle requests for a legacy system while migrate to a new API. I need any case that isn't explicitly handled to be handled by the legacy resources. – Brill Pappin Mar 18 '16 at 19:06
1 Answers
1
First, I do not recommend this as it is smells of NIH and is almost certainly going to lead you to unmaintainable code. That being said, in Java we have the HttpServlet. From that documentation, emphasis mine -
There's almost no reason to override the service method. service handles standard HTTP requests by dispatching them to the handler methods for each HTTP request type (the doXXX methods listed above).
That is precisely what you are asking how to do, so override the service method.

Elliott Frisch
- 198,278
- 20
- 158
- 249