public class Netty4ClientHttpRequestFactory extends Object implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory, InitializingBean, DisposableBean
ClientHttpRequestFactory implementation that
uses Netty 4 to create requests.
Allows to use a pre-configured EventLoopGroup instance - useful for sharing
across multiple clients.
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MAX_RESPONSE_SIZE
The default maximum response size.
|
| Constructor and Description |
|---|
Netty4ClientHttpRequestFactory()
Create a new
Netty4ClientHttpRequestFactory with a default
NioEventLoopGroup. |
Netty4ClientHttpRequestFactory(io.netty.channel.EventLoopGroup eventLoopGroup)
Create a new
Netty4ClientHttpRequestFactory with the given
EventLoopGroup. |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied
(and satisfied BeanFactoryAware and ApplicationContextAware).
|
protected void |
configureChannel(io.netty.channel.socket.SocketChannelConfig config)
Template method for changing properties on the given
SocketChannelConfig. |
AsyncClientHttpRequest |
createAsyncRequest(URI uri,
HttpMethod httpMethod)
Create a new asynchronous
AsyncClientHttpRequest for the specified URI
and HTTP method. |
ClientHttpRequest |
createRequest(URI uri,
HttpMethod httpMethod)
Create a new
ClientHttpRequest for the specified URI and HTTP method. |
void |
destroy()
Invoked by a BeanFactory on destruction of a singleton.
|
void |
setConnectTimeout(int connectTimeout)
Set the underlying connect timeout (in milliseconds).
|
void |
setMaxResponseSize(int maxResponseSize)
Set the default maximum response size.
|
void |
setReadTimeout(int readTimeout)
Set the underlying URLConnection's read timeout (in milliseconds).
|
void |
setSslContext(io.netty.handler.ssl.SslContext sslContext)
Set the SSL context.
|
public static final int DEFAULT_MAX_RESPONSE_SIZE
setMaxResponseSize(int),
Constant Field Valuespublic Netty4ClientHttpRequestFactory()
Netty4ClientHttpRequestFactory with a default
NioEventLoopGroup.public Netty4ClientHttpRequestFactory(io.netty.channel.EventLoopGroup eventLoopGroup)
Netty4ClientHttpRequestFactory with the given
EventLoopGroup.
NOTE: the given group will not be shutdown by this factory; doing so becomes the responsibility of the caller.
public void setMaxResponseSize(int maxResponseSize)
By default this is set to DEFAULT_MAX_RESPONSE_SIZE.
HttpObjectAggregator.HttpObjectAggregator(int)public void setSslContext(io.netty.handler.ssl.SslContext sslContext)
SslHandler in the channel pipeline.
By default this is not set.
public void setConnectTimeout(int connectTimeout)
ChannelConfig.setConnectTimeoutMillis(int)public void setReadTimeout(int readTimeout)
ReadTimeoutHandlerprotected void configureChannel(io.netty.channel.socket.SocketChannelConfig config)
SocketChannelConfig.
The default implementation sets the connect timeout based on the set property.
config - the channel configurationpublic void afterPropertiesSet()
InitializingBeanThis method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet in interface InitializingBeanpublic ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException
ClientHttpRequestFactoryClientHttpRequest for the specified URI and HTTP method.
The returned request can be written to, and then executed by calling
ClientHttpRequest.execute().
createRequest in interface ClientHttpRequestFactoryuri - the URI to create a request forhttpMethod - the HTTP method to executeIOException - in case of I/O errorspublic AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException
AsyncClientHttpRequestFactoryAsyncClientHttpRequest for the specified URI
and HTTP method.
The returned request can be written to, and then executed by calling
AsyncClientHttpRequest.executeAsync().
createAsyncRequest in interface AsyncClientHttpRequestFactoryuri - the URI to create a request forhttpMethod - the HTTP method to executeIOException - in case of I/O errorspublic void destroy()
throws InterruptedException
DisposableBeandestroy in interface DisposableBeanInterruptedException