Spring for Android

org.springframework.http.client
Class SimpleClientHttpRequestFactory

java.lang.Object
  extended by org.springframework.http.client.SimpleClientHttpRequestFactory
All Implemented Interfaces:
ClientHttpRequestFactory

public class SimpleClientHttpRequestFactory
extends java.lang.Object
implements ClientHttpRequestFactory

ClientHttpRequestFactory implementation that uses standard J2SE facilities.

Since:
1.0
Author:
Arjen Poutsma, Roy Clarkson
See Also:
HttpURLConnection

Constructor Summary
SimpleClientHttpRequestFactory()
           
 
Method Summary
 ClientHttpRequest createRequest(java.net.URI uri, HttpMethod httpMethod)
          Create a new ClientHttpRequest for the specified URI and HTTP method.
protected  java.net.HttpURLConnection openConnection(java.net.URL url, java.net.Proxy proxy)
          Opens and returns a connection to the given URL.
protected  void prepareConnection(java.net.HttpURLConnection connection, java.lang.String httpMethod)
          Template method for preparing the given HttpURLConnection.
 void setBufferRequestBody(boolean bufferRequestBody)
          Indicates whether this request factory should buffer the request body internally.
 void setChunkSize(int chunkSize)
          Sets 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 setProxy(java.net.Proxy proxy)
          Sets the Proxy to use for this request factory.
 void setReadTimeout(int 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 Detail

SimpleClientHttpRequestFactory

public SimpleClientHttpRequestFactory()
Method Detail

setProxy

public void setProxy(java.net.Proxy proxy)
Sets the Proxy to use for this request factory.


setBufferRequestBody

public void setBufferRequestBody(boolean bufferRequestBody)
Indicates 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).

See Also:
setChunkSize(int), HttpURLConnection.setFixedLengthStreamingMode(int)

setChunkSize

public void setChunkSize(int chunkSize)
Sets 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)

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)

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)

createRequest

public ClientHttpRequest createRequest(java.net.URI uri,
                                       HttpMethod httpMethod)
                                throws java.io.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:
java.io.IOException - in case of I/O errors

openConnection

protected java.net.HttpURLConnection openConnection(java.net.URL url,
                                                    java.net.Proxy proxy)
                                             throws java.io.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:
java.io.IOException - in case of I/O errors

prepareConnection

protected void prepareConnection(java.net.HttpURLConnection connection,
                                 java.lang.String httpMethod)
                          throws java.io.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:
java.io.IOException - in case of I/O errors

Spring for Android