Search code examples
javarestcxfpostman

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


Solution

  • 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.