|
12 | 12 | import org.springframework.http.client.ClientHttpRequestExecution; |
13 | 13 | import org.springframework.http.client.ClientHttpRequestInterceptor; |
14 | 14 | import org.springframework.http.client.ClientHttpResponse; |
15 | | -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; |
16 | 15 | import org.springframework.scheduling.annotation.EnableAsync; |
17 | 16 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
18 | 17 | import org.springframework.web.client.RestTemplate; |
|
25 | 24 | * Configures the {@link RestTemplate} used for all outbound calls to the SAP |
26 | 25 | * S/4HANA Business Partner OData service. |
27 | 26 | * |
28 | | - * <p>Three interceptors are attached: |
| 27 | + * <p>Two interceptors are attached: |
29 | 28 | * <ol> |
30 | 29 | * <li><b>SapAuthInterceptor</b> — stamps the required {@code APIKey} header |
31 | 30 | * (sandbox) or {@code Authorization: Bearer} (production tenant).</li> |
32 | | - * <li><b>IdentityEncodingInterceptor</b> — forces {@code Accept-Encoding: identity} |
33 | | - * so bodies are not gzip-compressed in transit. In production this is |
34 | | - * optional; here it keeps Keploy-captured YAML mocks human-readable, |
35 | | - * which matters for demo-grade visibility and for diff-reviewing |
36 | | - * contract changes in pull requests.</li> |
37 | 31 | * <li><b>CorrelationIdInterceptor</b> — propagates the inbound request's |
38 | 32 | * correlation id into the outbound SAP call so traces chain across |
39 | 33 | * the hop.</li> |
@@ -77,13 +71,17 @@ public RestTemplate sapRestTemplate(RestTemplateBuilder builder) { |
77 | 71 | + "Outbound SAP calls will fail with 401."); |
78 | 72 | } |
79 | 73 |
|
80 | | - HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(); |
81 | | - factory.setConnectTimeout((int) Duration.ofSeconds(connectTimeoutSeconds).toMillis()); |
82 | | - factory.setConnectionRequestTimeout((int) Duration.ofSeconds(connectTimeoutSeconds).toMillis()); |
83 | | - |
| 74 | + // Spring Boot auto-selects HttpClient5 when httpclient5 is on the |
| 75 | + // classpath (see pom.xml). Setting connect+read timeouts via the |
| 76 | + // RestTemplateBuilder plumbs them through to the underlying |
| 77 | + // HttpClient5 RequestConfig (connect) and SocketConfig (soTimeout == |
| 78 | + // read timeout), which is the only API surface that still exists in |
| 79 | + // Spring 6 — HttpComponentsClientHttpRequestFactory.setReadTimeout |
| 80 | + // was removed with the HttpClient5 migration. |
84 | 81 | return builder |
85 | 82 | .rootUri(baseUrl) |
86 | | - .requestFactory(() -> factory) |
| 83 | + .setConnectTimeout(Duration.ofSeconds(connectTimeoutSeconds)) |
| 84 | + .setReadTimeout(Duration.ofSeconds(readTimeoutSeconds)) |
87 | 85 | .additionalInterceptors( |
88 | 86 | new SapAuthInterceptor(apiKey, bearerToken), |
89 | 87 | new CorrelationIdInterceptor() |
|
0 commit comments