From d9d8a79c3075d90e3d21eda5ce26d34de1618c42 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 2 Feb 2015 16:15:42 -0500 Subject: [PATCH] Update Netty4ClientHttpRequestFactory buffer size This change deprecates the maxRequestSize property and adds maxResponseSize instead. The latter is required to create Netty's HttpObjectAggregator and aggregates responses. The maxRequestSize property is already removed in the master branch and will not be available starting with 4.2. Issue: SPR-12623 --- .../http/client/Netty4ClientHttpRequest.java | 4 +-- .../Netty4ClientHttpRequestFactory.java | 27 +++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java index 92ea05d3201..2b59c454eff 100644 --- a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,7 +65,7 @@ class Netty4ClientHttpRequest extends AbstractAsyncClientHttpRequest implements this.bootstrap = bootstrap; this.uri = uri; this.method = method; - this.body = new ByteBufOutputStream(Unpooled.buffer(maxRequestSize)); + this.body = new ByteBufOutputStream(Unpooled.buffer(1024, maxRequestSize)); } diff --git a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java index fc3f5783ec4..eff6f50f50c 100644 --- a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,6 +43,7 @@ import org.springframework.util.Assert; * across multiple clients. * * @author Arjen Poutsma + * @author Rossen Stoyanchev * @since 4.1.2 */ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, @@ -51,9 +52,16 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, /** * The default maximum request size. * @see #setMaxRequestSize(int) + * @deprecated */ public static final int DEFAULT_MAX_REQUEST_SIZE = 1024 * 1024 * 10; + /** + * The default maximum response size. + * @see #setMaxResponseSize(int) + */ + public static final int DEFAULT_MAX_RESPONSE_SIZE = 1024 * 1024 * 10; + private final EventLoopGroup eventLoopGroup; @@ -61,6 +69,8 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, private int maxRequestSize = DEFAULT_MAX_REQUEST_SIZE; + private int maxResponseSize = DEFAULT_MAX_REQUEST_SIZE; + private SslContext sslContext; private volatile Bootstrap bootstrap; @@ -94,11 +104,24 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, * Set the default maximum request size. *

By default this is set to {@link #DEFAULT_MAX_REQUEST_SIZE}. * @see HttpObjectAggregator#HttpObjectAggregator(int) + * @deprecated as of 4.1.5 this property is no longer supported; + * effectively renamed to {@link #setMaxResponseSize(int)}. */ public void setMaxRequestSize(int maxRequestSize) { this.maxRequestSize = maxRequestSize; } + /** + * Set the default maximum response size. + *

By default this is set to {@link #DEFAULT_MAX_RESPONSE_SIZE}. + * @see HttpObjectAggregator#HttpObjectAggregator(int) + * @since 4.1.5 + */ + public void setMaxResponseSize(int maxResponseSize) { + this.maxResponseSize = maxResponseSize; + } + + /** * Set the SSL context. When configured it is used to create and insert an * {@link io.netty.handler.ssl.SslHandler} in the channel pipeline. @@ -120,7 +143,7 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, pipeline.addLast(sslContext.newHandler(channel.alloc())); } pipeline.addLast(new HttpClientCodec()); - pipeline.addLast(new HttpObjectAggregator(maxRequestSize)); + pipeline.addLast(new HttpObjectAggregator(maxResponseSize)); } }); this.bootstrap = bootstrap;