Reputation: 1248
In our project, we need to pass a certain header information in all the REST calls that are sent out to other internal APIs.
One way is to change all the hundreds or even thousands of REST invocations to add this mapping before the REST call is initiated.
But, I was wondering if there is a smarter way of doing this using aspects/filters/listeners/interceptors in Spring/Java?
Example: If I make a call from REST API 1 to an endpoint, I am trying to explore a way to intercept the constructed HTTP request and add the header and fire the request.
Any suggestions about solving or any other good practices are welcome.
Thank you.
Upvotes: 3
Views: 9537
Reputation: 1248
For any person who stumbles upon this post in the future, here is what it took to make it working.
Implement a class that 'implements' ClientHttpRequestInterceptor. The method that needs to be overridden is where you can catch the request headers and modify them.
Upvotes: 8