Sandhya Srinivasan
Sandhya Srinivasan

Reputation: 1

How to get Http header values in Apache Camel- Jersey Rest API

I have an application which uses Apache Camel to build an API. It basically uses blueprint.xml to define routes and processing is done by a bean(please note its not any processor bean. Just a plain Java bean). It uses Jersey client to invoke the backend system Rest API.

My requirement is to get the http headers in the code to be able to send them to our custom logging system.

a) I tried @httpHeaders annotation but this does not inject the headers on my code. b) Since its not using any BeanProcessor i dont have an Exchange object from where i can get the header values.

Please help with a way to get header values on the code.

Upvotes: 0

Views: 1200

Answers (1)

Ori Marko
Ori Marko

Reputation: 58774

Add the request context to your class

 @Context
 private HttpServletRequest request;

and get the headers in your endpoint using request.getHeader

Returns the value of the specified request header as a String.

Upvotes: 1

Related Questions