I am exposing my java application as REST api using apache cxf.
How can I get the header details sent by api caller in my java application @GET method
Apache CXF implements the JAX-RS specification. So you can inject HttpHeaders
in your resource class or resource methods using @Context
:
@Context
HttpHeaders httpHeaders;
Then you can use the HttpHeaders
API to get the header values:
HttpHeaders#getHeaderString(String)
HttpHeaders#getRequestHeaders()
HttpHeaders#getHeaderString(String)
If you need the value of a standard HTTP header, consider using the constants available in the HttpHeaders
API:
// Get the value of the Authorization header
String authorizationHeader = httpHeaders.getHeaderString(HttpHeaders.AUTHORIZATION);
See the Apache CXF documentation about context types for further details.