类 SimpleClientHttpRequestFactory
- java.lang.Object
- org.springframework.http.client.SimpleClientHttpRequestFactory
public class SimpleClientHttpRequestFactory extends Object implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory
ClientHttpRequestFactoryimplementation that uses standard JDK facilities.- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma, Juergen Hoeller
- 另请参阅:
HttpURLConnection,HttpComponentsClientHttpRequestFactory
构造器概要
构造器 构造器 说明 SimpleClientHttpRequestFactory()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 AsyncClientHttpRequestcreateAsyncRequest(URI uri, HttpMethod httpMethod)Create a new asynchronousAsyncClientHttpRequestfor the specified URI and HTTP method.ClientHttpRequestcreateRequest(URI uri, HttpMethod httpMethod)Create a newClientHttpRequestfor the specified URI and HTTP method.protected HttpURLConnectionopenConnection(URL url, Proxy proxy)Opens and returns a connection to the given URL.protected voidprepareConnection(HttpURLConnection connection, String httpMethod)Template method for preparing the givenHttpURLConnection.voidsetBufferRequestBody(boolean bufferRequestBody)Indicate whether this request factory should buffer the request body internally.voidsetChunkSize(int chunkSize)Set the number of bytes to write in each chunk when not buffering request bodies locally.voidsetConnectTimeout(int connectTimeout)Set the underlying URLConnection's connect timeout (in milliseconds).voidsetOutputStreaming(boolean outputStreaming)Set if the underlying URLConnection can be set to 'output streaming' mode.voidsetProxy(Proxy proxy)Set theProxyto use for this request factory.voidsetReadTimeout(int readTimeout)Set the underlying URLConnection's read timeout (in milliseconds).voidsetTaskExecutor(AsyncListenableTaskExecutor taskExecutor)Set the task executor for this request factory.
构造器详细资料
SimpleClientHttpRequestFactory
public SimpleClientHttpRequestFactory()
方法详细资料
setBufferRequestBody
public void setBufferRequestBody(boolean bufferRequestBody)
Indicate whether this request factory should buffer the request body internally.Default is
true. When sending large amounts of data via POST or PUT, it is recommended to change this property tofalse, so as not to run out of memory. This will result in aClientHttpRequestthat either streams directly to the underlyingHttpURLConnection(if theContent-Lengthis known in advance), or that will use "Chunked transfer encoding" (if theContent-Lengthis not known in advance).
setChunkSize
public void setChunkSize(int chunkSize)
Set the number of bytes to write in each chunk when not buffering request bodies locally.Note that this parameter is only used when
bufferRequestBodyis set tofalse, and theContent-Lengthis not known in advance.
setConnectTimeout
public void setConnectTimeout(int connectTimeout)
Set the underlying URLConnection's connect timeout (in milliseconds). A timeout value of 0 specifies an infinite timeout.Default is the system's default timeout.
setReadTimeout
public void setReadTimeout(int readTimeout)
Set the underlying URLConnection's read timeout (in milliseconds). A timeout value of 0 specifies an infinite timeout.Default is the system's default timeout.
setOutputStreaming
public void setOutputStreaming(boolean outputStreaming)
Set if the underlying URLConnection can be set to 'output streaming' mode. Default istrue.When output streaming is enabled, authentication and redirection cannot be handled automatically. If output streaming is disabled, the
HttpURLConnection.setFixedLengthStreamingMode(int)andHttpURLConnection.setChunkedStreamingMode(int)methods of the underlying connection will never be called.- 参数:
outputStreaming- if output streaming is enabled
setTaskExecutor
public void setTaskExecutor(AsyncListenableTaskExecutor taskExecutor)
Set the task executor for this request factory. Setting this property is required for creating asynchronous requests.- 参数:
taskExecutor- the task executor
createRequest
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException
从接口复制的说明:ClientHttpRequestFactoryCreate a newClientHttpRequestfor 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
Create a new asynchronousAsyncClientHttpRequestfor the specified URI and HTTP method.The returned request can be written to, and then executed by calling
AsyncClientHttpRequest.executeAsync().Setting the
taskExecutorproperty is required before calling this method.- 指定者:
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
openConnection
protected HttpURLConnection openConnection(URL url, Proxy proxy) throws IOException
Opens and returns a connection to the given URL.The default implementation uses the given proxy - if any - to open a connection.
- 参数:
url- the URL to open a connection toproxy- the proxy to use, may benull- 返回:
- the opened connection
- 抛出:
IOException- in case of I/O errors
prepareConnection
protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException
Template method for preparing the givenHttpURLConnection.The default implementation prepares the connection for input and output, and sets the HTTP method.
- 参数:
connection- the connection to preparehttpMethod- the HTTP request method (GET,POST, etc.)- 抛出:
IOException- in case of I/O errors