类 Netty4ClientHttpRequestFactory
- java.lang.Object
- org.springframework.http.client.Netty4ClientHttpRequestFactory
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.
- 从以下版本开始:
- 4.1.2
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Brian Clozel, Mark Paluch
字段概要
字段 修饰符和类型 字段 说明 static int
DEFAULT_MAX_RESPONSE_SIZE
The default maximum response size.
构造器概要
构造器 构造器 说明 Netty4ClientHttpRequestFactory()
Create a newNetty4ClientHttpRequestFactory
with a defaultNioEventLoopGroup
.Netty4ClientHttpRequestFactory(io.netty.channel.EventLoopGroup eventLoopGroup)
Create a newNetty4ClientHttpRequestFactory
with the givenEventLoopGroup
.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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.
字段详细资料
DEFAULT_MAX_RESPONSE_SIZE
public static final int DEFAULT_MAX_RESPONSE_SIZE
The default maximum response size.- 另请参阅:
setMaxResponseSize(int)
, 常量字段值
构造器详细资料
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.
方法详细资料
setMaxResponseSize
public void setMaxResponseSize(int maxResponseSize)
Set the default maximum response size.By default this is set to
DEFAULT_MAX_RESPONSE_SIZE
.- 从以下版本开始:
- 4.1.5
- 另请参阅:
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.- 另请参阅:
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.- 另请参阅:
ReadTimeoutHandler
afterPropertiesSet
public void afterPropertiesSet()
从接口复制的说明: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.
- 指定者:
afterPropertiesSet
在接口中InitializingBean
createRequest
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException
从接口复制的说明: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()
.- 指定者:
createRequest
在接口中ClientHttpRequestFactory
- 参数:
uri
- the URI to create a request forhttpMethod
- the HTTP method to execute- 返回:
- the created request
- 抛出:
IOException
- in case of I/O errors
createAsyncRequest
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException
从接口复制的说明: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()
.- 指定者:
createAsyncRequest
在接口中AsyncClientHttpRequestFactory
- 参数:
uri
- the URI to create a request forhttpMethod
- the HTTP method to execute- 返回:
- the created request
- 抛出:
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.
- 参数:
config
- the channel configuration
destroy
public void destroy() throws InterruptedException
从接口复制的说明:DisposableBean
Invoked by the containingBeanFactory
on destruction of a bean.- 指定者:
destroy
在接口中DisposableBean
- 抛出:
InterruptedException