How to obtain the HTTP method of a REST request

advertisements

In case of an exception in my Java REST application I would like to log various information on causing HTTP request.

I can obtain the URI of the request and the HTTP headers via context injection

@Context
private UriInfo uriInfo;

@Context
private HttpHeaders headers;

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


I use Jersey. Don't know if this applies for you but ... :

import javax.servlet.http.HttpServletRequest;    

@Context final HttpServletRequest request

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