user8765332
user8765332

Reputation: 85

Get headers sent through postman in java

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

Upvotes: 0

Views: 2840

Answers (1)

cassiomolin
cassiomolin

Reputation: 131137

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:

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.

Upvotes: 1

Related Questions