Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the HTTP method of a REST request

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, ...)?

like image 944
Oliver Avatar asked Mar 01 '13 10:03

Oliver


1 Answers

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.

like image 69
Samuel EUSTACHI Avatar answered Oct 28 '22 01:10

Samuel EUSTACHI