0

I have a rest web service that is implemented using spring boot starter web.
This service acts as a client to another application that requires authentication to make calls to it.
Calls made from the client to the server are using org.springframework.web.client.RestTemplate.
Is there a way to come up with a solution to add authentication headers to outbound requests at one single point before they are sent out?
I don't want to add headers in each of the requests separately.

Leonid Glanz
  • 1,267
  • 2
  • 16
  • 33

1 Answers1

0

Javadoc for RestTemplate says:

This template uses a SimpleClientHttpRequestFactory and a DefaultResponseErrorHandler as default strategies for creating HTTP connections or handling HTTP errors, respectively. These defaults can be overridden through HttpAccessor.setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory)

So I would take SimpleClientHttpRequestFactory and override its prepareConnection(..) method.

sodik
  • 4,515
  • 2
  • 26
  • 43