Top Description Fields Constructors Methods
org.springframework.http.client

public Class SimpleClientHttpRequestFactory

extends Object
implements ClientHttpRequestFactory
Class Inheritance
All Implemented Interfaces
org.springframework.http.client.ClientHttpRequestFactory
Imports
java.io.IOException, java.net.HttpURLConnection, .Proxy, .URI, .URL, .URLConnection, java.time.Duration, org.springframework.http.HttpMethod, org.springframework.lang.Nullable, org.springframework.util.Assert

ClientHttpRequestFactory implementation that uses standard JDK facilities.
Authors
Arjen Poutsma, Juergen Hoeller
Since
3.0
See Also
java.net.HttpURLConnection, HttpComponentsClientHttpRequestFactory

Field Summary

Modifier and TypeField and Description
private int
private int
private static final int
private Proxy
private int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ClientHttpRequest
createRequest(URI
the URI to create a request for
uri
,
HttpMethod
the HTTP method to execute
httpMethod
)

Implements org.springframework.http.client.ClientHttpRequestFactory.createRequest.

Create a new ClientHttpRequest for the specified URI and HTTP method.
protected HttpURLConnection

Returns:

the opened connection
openConnection
(URL
the URL to open a connection to
url
,
Proxy
the proxy to use, may be null
proxy
)

Opens and returns a connection to the given URL.

protected void
prepareConnection(HttpURLConnection
the connection to prepare
connection
,
String
the HTTP request method (GET, POST, etc.)
httpMethod
)

Template method for preparing the given HttpURLConnection.

public void
setBufferRequestBody(boolean bufferRequestBody)

Deprecated for removal since 6.1. since 6.1 requests are never buffered, as if this property is false
Indicate whether this request factory should buffer the request body internally.
public void
setChunkSize(int chunkSize)

Set the number of bytes to write in each chunk when not buffering request bodies locally.

public void
setConnectTimeout(int connectTimeout)

Set the underlying URLConnection's connect timeout (in milliseconds).

public void
setConnectTimeout(Duration connectTimeout)

Set the underlying URLConnection's connect timeout as Duration.

public void
setOutputStreaming(boolean
if output streaming is enabled
outputStreaming
)

Deprecated for removal since 6.1. 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.
public void
setProxy(Proxy proxy)

Set the Proxy to use for this request factory.

public void
setReadTimeout(int readTimeout)

Set the underlying URLConnection's read timeout (in milliseconds).

public void
setReadTimeout(Duration readTimeout)

Set the underlying URLConnection's read timeout (in milliseconds).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

chunkSizeback to summary
private int chunkSize
connectTimeoutback to summary
private int connectTimeout
DEFAULT_CHUNK_SIZEback to summary
private static final int DEFAULT_CHUNK_SIZE
proxyback to summary
private Proxy proxy
Annotations
@Nullable
readTimeoutback to summary
private int readTimeout

Constructor Detail

SimpleClientHttpRequestFactoryback to summary
public SimpleClientHttpRequestFactory()

Method Detail

createRequestback to summary
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException

Implements org.springframework.http.client.ClientHttpRequestFactory.createRequest.

Doc from org.springframework.http.client.ClientHttpRequestFactory.createRequest.

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().

Parameters
uri:URI

the URI to create a request for

httpMethod:HttpMethod

the HTTP method to execute

Returns:ClientHttpRequest

the created request

Annotations
@Override
Exceptions
IOException:
in case of I/O errors
openConnectionback to summary
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.

Parameters
url:URL

the URL to open a connection to

proxy:Proxy

the proxy to use, may be null

Returns:HttpURLConnection

the opened connection

Exceptions
IOException:
in case of I/O errors
prepareConnectionback to summary
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:HttpURLConnection

the connection to prepare

httpMethod:String

the HTTP request method (GET, POST, etc.)

Exceptions
IOException:
in case of I/O errors
setBufferRequestBodyback to summary
public void setBufferRequestBody(boolean bufferRequestBody)

Deprecated

for removal since 6.1.

since 6.1 requests are never buffered, as if this property is false

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 to false, so as not to run out of memory. This will result in a ClientHttpRequest that either streams directly to the underlying HttpURLConnection (if the Content-Length is known in advance), or that will use "Chunked transfer encoding" (if the Content-Length is not known in advance).

Annotations
@Deprecated
since:6.1
forRemoval:true
See Also
setChunkSize(int), HttpURLConnection#setFixedLengthStreamingMode(int)
setChunkSizeback to summary
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 to false, and the Content-Length is not known in advance.

See Also
setBufferRequestBody(boolean)
setConnectTimeoutback to summary
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)
setConnectTimeoutback to summary
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)
setOutputStreamingback to summary
public void setOutputStreaming(boolean outputStreaming)

Deprecated

for removal since 6.1.

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 and HttpURLConnection#setChunkedStreamingMode methods of the underlying connection will never be called.

Parameters
outputStreaming:boolean

if output streaming is enabled

Annotations
@Deprecated
since:6.1
forRemoval:true
setProxyback to summary
public void setProxy(Proxy proxy)

Set the Proxy to use for this request factory.

setReadTimeoutback to summary
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)
setReadTimeoutback to summary
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)