Class SimpleClientHttpRequestFactory
- All Implemented Interfaces:
ClientHttpRequestFactory
ClientHttpRequestFactory
implementation that uses standard JDK facilities.- Since:
- 3.0
- Author:
- Arjen Poutsma, Juergen Hoeller
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncreateRequest
(URI uri, HttpMethod httpMethod) Create a newClientHttpRequest
for the specified URI and HTTP method.protected HttpURLConnection
openConnection
(URL url, Proxy proxy) Opens and returns a connection to the given URL.protected void
prepareConnection
(HttpURLConnection connection, String httpMethod) Template method for preparing the givenHttpURLConnection
.void
setBufferRequestBody
(boolean bufferRequestBody) Indicate whether this request factory should buffer the request body internally.void
setChunkSize
(int chunkSize) Set the number of bytes to write in each chunk when not buffering request bodies locally.void
setConnectTimeout
(int connectTimeout) Set the underlying URLConnection's connect timeout (in milliseconds).void
setOutputStreaming
(boolean outputStreaming) Set if the underlying URLConnection can be set to 'output streaming' mode.void
Set theProxy
to use for this request factory.void
setReadTimeout
(int readTimeout) Set the underlying URLConnection's read timeout (in milliseconds).
-
Constructor Details
-
SimpleClientHttpRequestFactory
public SimpleClientHttpRequestFactory()
-
-
Method Details
-
setProxy
Set theProxy
to use for this request factory. -
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 aClientHttpRequest
that either streams directly to the underlyingHttpURLConnection
(if theContent-Length
is known in advance), or that will use "Chunked transfer encoding" (if theContent-Length
is 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
bufferRequestBody
is set tofalse
, and theContent-Length
is not known in advance.- See Also:
-
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.
- See Also:
-
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.
- See Also:
-
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.- Parameters:
outputStreaming
- if output streaming is enabled
-
createRequest
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
-
openConnection
Opens and returns a connection to the given URL.The default implementation uses the given proxy - if any - to open a connection.
- Parameters:
url
- the URL to open a connection toproxy
- the proxy to use, may benull
- Returns:
- the opened connection
- Throws:
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.
- Parameters:
connection
- the connection to preparehttpMethod
- the HTTP request method (GET
,POST
, etc.)- Throws:
IOException
- in case of I/O errors
-