How to get the HTTP REST request method

In the event of an exception in my Java REST application, I would like to record various information about the HTTP request call.

I can get request URI and HTTP headers using context injection

@Context private UriInfo uriInfo; @Context private HttpHeaders headers; 

But how can I get the HTTP method (GET, PUT, ...)?

+6
source share
2 answers

I use jersey. I do not know if this applies to you, but ...:

 import javax.servlet.http.HttpServletRequest; @Context final HttpServletRequest request 

The Request class has a getMethod() method. It returns the used HTTP method.

+12
source

Usually you limit the stop methods to one http method

  @GET @Produces("text/plain") public String getClichedMessage() { // Return some cliched textual content return "Hello World"; } 
0
source

All Articles