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
pull/9151/merge
Brian Clozel 8 years ago
parent 4a47c1eff8
commit c84204bc81

@ -321,11 +321,6 @@
<artifactId>mariadb-java-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>

@ -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);
}

@ -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

Loading…
Cancel
Save