From c84204bc819fb8cd39c82d1d964263a4414bceef Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Fri, 12 May 2017 15:54:15 +0200 Subject: [PATCH] Remove Netty4 auto-configuration in RestTemplate This commit removes the automatic configuration of the Netty request factory in RestTemplateBuilder, for the following reasons: * as of Spring 5, `Netty4ClientHttpRequestFactory` is now deprecated * there are quite a few issues logged in Spring Framework (duplicate headers, such as SPR-15446 and SPR-15476) * by default, the `Netty4ClientHttpRequestFactory` is adding a "Connection: close" request header to all outgoing requests, which means that the underlying HTTP connection won't be reused between requests (which is a performance problem) In that case, using any other request factory is a better choice for Spring Boot 2.0+. Note that the `RestTemplateBuilder` still allows to provide it manually with the request factory to use. Developers can still choose this option and will be aware of its deprecation status. Fixes gh-9150 --- spring-boot/pom.xml | 5 ----- .../boot/web/client/RestTemplateBuilder.java | 2 -- .../web/client/RestTemplateBuilderTests.java | 19 ------------------- 3 files changed, 26 deletions(-) diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index c76835bf48..2cc17dee87 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -321,11 +321,6 @@ mariadb-java-client test - - io.netty - netty-all - test - org.postgresql postgresql diff --git a/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java b/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java index c3df825a52..dc224ee9e1 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java @@ -72,8 +72,6 @@ public class RestTemplateBuilder { "org.springframework.http.client.OkHttp3ClientHttpRequestFactory"); candidates.put("com.squareup.okhttp.OkHttpClient", "org.springframework.http.client.OkHttpClientHttpRequestFactory"); - candidates.put("io.netty.channel.EventLoopGroup", - "org.springframework.http.client.Netty4ClientHttpRequestFactory"); REQUEST_FACTORY_CANDIDATES = Collections.unmodifiableMap(candidates); } diff --git a/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java b/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java index daa38124ed..a2036f6ce7 100644 --- a/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java @@ -31,7 +31,6 @@ import org.springframework.http.client.BufferingClientHttpRequestFactory; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; -import org.springframework.http.client.Netty4ClientHttpRequestFactory; import org.springframework.http.client.OkHttp3ClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.http.client.support.BasicAuthorizationInterceptor; @@ -465,24 +464,6 @@ public class RestTemplateBuilderTests { .isEqualTo(1234); } - @Test - public void connectTimeoutCanBeConfiguredOnNetty4RequestFactory() { - ClientHttpRequestFactory requestFactory = this.builder - .requestFactory(Netty4ClientHttpRequestFactory.class) - .setConnectTimeout(1234).build().getRequestFactory(); - assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout")) - .isEqualTo(1234); - } - - @Test - public void readTimeoutCanBeConfiguredOnNetty4RequestFactory() { - ClientHttpRequestFactory requestFactory = this.builder - .requestFactory(Netty4ClientHttpRequestFactory.class).setReadTimeout(1234) - .build().getRequestFactory(); - assertThat(ReflectionTestUtils.getField(requestFactory, "readTimeout")) - .isEqualTo(1234); - } - @Test public void connectTimeoutCanBeConfiguredOnOkHttp3RequestFactory() { ClientHttpRequestFactory requestFactory = this.builder