Class Netty4ClientHttpRequestFactory
- java.lang.Object
- org.springframework.http.client.Netty4ClientHttpRequestFactory
- All Implemented Interfaces:
DisposableBean
,InitializingBean
,AsyncClientHttpRequestFactory
,ClientHttpRequestFactory
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.Note that this implementation consistently closes the HTTP connection on each request.
- Since:
- 4.1.2
- Author:
- Arjen Poutsma, Rossen Stoyanchev, Brian Clozel, Mark Paluch
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_MAX_RESPONSE_SIZE
The default maximum response size.
Constructor Summary
Constructors Constructor Description Netty4ClientHttpRequestFactory()
Create a newNetty4ClientHttpRequestFactory
with a defaultNioEventLoopGroup
.Netty4ClientHttpRequestFactory(io.netty.channel.EventLoopGroup eventLoopGroup)
Create a newNetty4ClientHttpRequestFactory
with the givenEventLoopGroup
.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.protected void
configureChannel(io.netty.channel.socket.SocketChannelConfig config)
Template method for changing properties on the givenSocketChannelConfig
.AsyncClientHttpRequest
createAsyncRequest(URI uri, HttpMethod httpMethod)
Create a new asynchronousAsyncClientHttpRequest
for the specified URI and HTTP method.ClientHttpRequest
createRequest(URI uri, HttpMethod httpMethod)
Create a newClientHttpRequest
for the specified URI and HTTP method.void
destroy()
Invoked by the containingBeanFactory
on destruction of a bean.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.
Field Detail
DEFAULT_MAX_RESPONSE_SIZE
public static final int DEFAULT_MAX_RESPONSE_SIZE
The default maximum response size.- See Also:
setMaxResponseSize(int)
, Constant Field Values
Constructor Detail
Netty4ClientHttpRequestFactory
public Netty4ClientHttpRequestFactory()
Create a newNetty4ClientHttpRequestFactory
with a defaultNioEventLoopGroup
.
Netty4ClientHttpRequestFactory
public Netty4ClientHttpRequestFactory(io.netty.channel.EventLoopGroup eventLoopGroup)
Create a newNetty4ClientHttpRequestFactory
with the givenEventLoopGroup
.NOTE: the given group will not be shutdown by this factory; doing so becomes the responsibility of the caller.
Method Detail
setMaxResponseSize
public void setMaxResponseSize(int maxResponseSize)
Set the default maximum response size.By default this is set to
DEFAULT_MAX_RESPONSE_SIZE
.- Since:
- 4.1.5
- See Also:
HttpObjectAggregator(int)
setSslContext
public void setSslContext(io.netty.handler.ssl.SslContext sslContext)
Set the SSL context. When configured it is used to create and insert anSslHandler
in the channel pipeline.A default client SslContext is configured if none has been provided.
setConnectTimeout
public void setConnectTimeout(int connectTimeout)
Set the underlying connect timeout (in milliseconds). A timeout value of 0 specifies an infinite timeout.- See Also:
ChannelConfig.setConnectTimeoutMillis(int)
setReadTimeout
public void setReadTimeout(int readTimeout)
Set the underlying URLConnection's read timeout (in milliseconds). A timeout value of 0 specifies an infinite timeout.- See Also:
ReadTimeoutHandler
afterPropertiesSet
public void afterPropertiesSet()
Description copied from interface:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- Specified by:
afterPropertiesSet
in interfaceInitializingBean
createRequest
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException
Description copied from interface:ClientHttpRequestFactory
Create a newClientHttpRequest
for the specified URI and HTTP method.The returned request can be written to, and then executed by calling
ClientHttpRequest.execute()
.- Specified by:
createRequest
in interfaceClientHttpRequestFactory
- Parameters:
uri
- the URI to create a request forhttpMethod
- the HTTP method to execute- Returns:
- the created request
- Throws:
IOException
- in case of I/O errors
createAsyncRequest
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException
Description copied from interface:AsyncClientHttpRequestFactory
Create a new asynchronousAsyncClientHttpRequest
for the specified URI and HTTP method.The returned request can be written to, and then executed by calling
AsyncClientHttpRequest.executeAsync()
.- Specified by:
createAsyncRequest
in interfaceAsyncClientHttpRequestFactory
- Parameters:
uri
- the URI to create a request forhttpMethod
- the HTTP method to execute- Returns:
- the created request
- Throws:
IOException
- in case of I/O errors
configureChannel
protected void configureChannel(io.netty.channel.socket.SocketChannelConfig config)
Template method for changing properties on the givenSocketChannelConfig
.The default implementation sets the connect timeout based on the set property.
- Parameters:
config
- the channel configuration
destroy
public void destroy() throws InterruptedException
Description copied from interface:DisposableBean
Invoked by the containingBeanFactory
on destruction of a bean.- Specified by:
destroy
in interfaceDisposableBean
- Throws:
InterruptedException