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.
Asked
Active
Viewed 64 times
0
![](../../users/profiles/2162470.webp)
Leonid Glanz
- 1,267
- 2
- 16
- 33
![](../../users/profiles/1774086.webp)
skhaapioloir
- 23
- 6
1 Answers
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.
![](../../users/profiles/1131829.webp)
sodik
- 4,515
- 2
- 26
- 43