Package org.springframework.http.client

# Class SimpleClientHttpRequestFactory

java.lang.Object
org.springframework.http.client.SimpleClientHttpRequestFactory

All Implemented Interfaces:
  `ClientHttpRequestFactory`

public class SimpleClientHttpRequestFactory extends Object implements ClientHttpRequestFactory
`ClientHttpRequestFactory` implementation that uses standard JDK facilities.

Since:
  3.0
Author:
  Arjen Poutsma, Juergen Hoeller
See Also:
  - `HttpURLConnection`
  - `HttpComponentsClientHttpRequestFactory`

## Constructor Summary

Constructors
Constructor
Description
`SimpleClientHttpRequestFactory()`

## Method Summary

Modifier and Type
Method
Description
`ClientHttpRequest`
`createRequest(URI uri, HttpMethod httpMethod)`
Create a new `ClientHttpRequest` 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 given `HttpURLConnection`.
`void`
`setBufferRequestBody(boolean bufferRequestBody)`
Deprecated, for removal: This API element is subject to removal in a future version.
since 6.1 requests are never buffered, as if this property is `false`
`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`
`setConnectTimeout(Duration connectTimeout)`
Set the underlying URLConnection's connect timeout as `Duration`.
`void`
`setOutputStreaming(boolean outputStreaming)`
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.1 requests are always streamed, as if this property is `true`
`void`
`setProxy(Proxy proxy)`
Set the `Proxy` to use for this request factory.
`void`
`setReadTimeout(int readTimeout)`
Set the underlying URLConnection's read timeout (in milliseconds).
`void`
`setReadTimeout(Duration readTimeout)`
Set the underlying URLConnection's read timeout (in milliseconds).

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### SimpleClientHttpRequestFactory

public SimpleClientHttpRequestFactory()

## Method Details

### setProxy

public void setProxy(Proxy proxy)
Set the `Proxy` to use for this request factory.

### setBufferRequestBody

@Deprecated(since="6.1", forRemoval=true) public void setBufferRequestBody(boolean bufferRequestBody)
Deprecated, for removal: This API element is subject to removal in a future version.
since 6.1 requests are never buffered, as if this property is `false`
Indicate whether this request factory should buffer the request body internally.

See Also:
  - `setChunkSize(int)`

### setChunkSize

public void setChunkSize(int chunkSize)
Set the number of bytes to write in each chunk when not buffering request bodies locally.

### 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:
  - `URLConnection.setConnectTimeout(int)`

### setConnectTimeout

public void setConnectTimeout(Duration connectTimeout)
Set the underlying URLConnection's connect timeout as `Duration`. A timeout value of 0 specifies an infinite timeout.

Default is the system's default timeout.

Since:
  6.1
See Also:
  - `URLConnection.setConnectTimeout(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.

Default is the system's default timeout.

See Also:
  - `URLConnection.setReadTimeout(int)`

### setReadTimeout

public void setReadTimeout(Duration 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.

Since:
  6.1
See Also:
  - `URLConnection.setReadTimeout(int)`

### setOutputStreaming

@Deprecated(since="6.1", forRemoval=true) public void setOutputStreaming(boolean outputStreaming)
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.1 requests are always streamed, as if this property is `true`
Set if the underlying URLConnection can be set to 'output streaming' mode. Default is `true`.

When output streaming is enabled, authentication and redirection cannot be handled automatically. If output streaming is disabled, the `HttpURLConnection.setFixedLengthStreamingMode(int)` and `HttpURLConnection.setChunkedStreamingMode(int)` methods of the underlying connection will never be called.

Parameters:
  `outputStreaming` - if output streaming is enabled

### createRequest

public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException
Description copied from interface: `ClientHttpRequestFactory`
Create a new `ClientHttpRequest` 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 interface `ClientHttpRequestFactory`
Parameters:
  `uri` - the URI to create a request for
  `httpMethod` - the HTTP method to execute
Returns:
  the created request
Throws:
  `IOException` - in case of I/O errors

### openConnection

protected HttpURLConnection openConnection(URL url, @Nullable 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.

Parameters:
  `url` - the URL to open a connection to
  `proxy` - the proxy to use, may be `null`
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 given `HttpURLConnection`.

The default implementation prepares the connection for input and output, and sets the HTTP method.

Parameters:
  `connection` - the connection to prepare
  `httpMethod` - the HTTP request method (`GET`, `POST`, etc.)
Throws:
  `IOException` - in case of I/O errors