Skip to content

Commit 0f15f15

Browse files
tinomthomaspedja4
authored andcommitted
BAEL-1756 (eugenp#4349)
1 parent db23324 commit 0f15f15

3 files changed

Lines changed: 21 additions & 44 deletions

File tree

‎spring-rest/src/main/java/org/baeldung/config/RestClientConfig.java‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
import org.baeldung.interceptors.RestTemplateLoggingInterceptor;
6+
import org.baeldung.interceptors.RestTemplateHeaderModifierInterceptor;
77
import org.springframework.context.annotation.Bean;
88
import org.springframework.context.annotation.Configuration;
9-
import org.springframework.http.client.BufferingClientHttpRequestFactory;
109
import org.springframework.http.client.ClientHttpRequestInterceptor;
11-
import org.springframework.http.client.SimpleClientHttpRequestFactory;
1210
import org.springframework.util.CollectionUtils;
1311
import org.springframework.web.client.RestTemplate;
1412

@@ -17,13 +15,13 @@ public class RestClientConfig {
1715

1816
@Bean
1917
public RestTemplate restTemplate() {
20-
RestTemplate restTemplate = new RestTemplate(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()));
18+
RestTemplate restTemplate = new RestTemplate();
2119

2220
List<ClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors();
2321
if (CollectionUtils.isEmpty(interceptors)) {
2422
interceptors = new ArrayList<ClientHttpRequestInterceptor>();
2523
}
26-
interceptors.add(new RestTemplateLoggingInterceptor());
24+
interceptors.add(new RestTemplateHeaderModifierInterceptor());
2725
restTemplate.setInterceptors(interceptors);
2826
return restTemplate;
2927
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.baeldung.interceptors;
2+
3+
import java.io.IOException;
4+
5+
import org.springframework.http.HttpRequest;
6+
import org.springframework.http.client.ClientHttpRequestExecution;
7+
import org.springframework.http.client.ClientHttpRequestInterceptor;
8+
import org.springframework.http.client.ClientHttpResponse;
9+
10+
public class RestTemplateHeaderModifierInterceptor implements ClientHttpRequestInterceptor {
11+
12+
@Override
13+
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
14+
ClientHttpResponse response = execution.execute(request, body);
15+
response.getHeaders().add("Foo", "bar");
16+
return response;
17+
}
18+
}

‎spring-rest/src/main/java/org/baeldung/interceptors/RestTemplateLoggingInterceptor.java‎

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)