public class RestDataSource extends java.lang.Object implements IODataSource
IODataSource
that can read from and write to an HTTP URL resource.
Attention: it is advised not to use this class directly, but rather construct it by creating a
RestClient
and build the RestDataSource with the RestClient.createRestDataSource()
method.
Constructor and Description |
---|
RestDataSource() |
Modifier and Type | Method and Description |
---|---|
void |
addFormParam(java.lang.String key,
java.lang.String value)
Add a single form parameter to the request.
|
void |
addHeader(java.lang.String field,
java.lang.String value)
Adds a single HTTP header to the request.
|
void |
addQueryParam(java.lang.String key,
java.lang.String value)
Add a single query parameter to the request.
|
int |
getConnectTimeout()
Gets the connect timeout for the HTTP connection, in milliseconds.
|
java.lang.String |
getConsumerKey()
Gets the consumer key to use for creating the OAuth 1.0 signature that is sent along with the request, by setting
the
Authorization request header. |
java.lang.String |
getConsumerSecret()
Gets the consumer secret to use for creating the OAuth 1.0 signature that is sent along with the request, by
setting the
Authorization request header. |
java.lang.String |
getContentType()
Gets the Content-Type request header that will be set on the HTTP connection.
|
java.lang.String |
getDataString()
Gets the entity to use for the HTTP connection.
|
MultiValuedMap<java.lang.String,java.lang.String> |
getFormParams()
Returns a list of form parameters that will be sent along with the request.
|
MultiValuedMap<java.lang.String,java.lang.String> |
getHeaders()
Returns a list of HTTP headers which will be sent along with the request.
|
java.lang.String |
getHost()
Returns the complete host address of the URL to use for the HTTP connection.
|
java.io.InputStream |
getInputStream()
Returns an InputStream that is able to read data from an HTTP URL that will be constructed
with the settings defined on this data source.
|
java.lang.String |
getMethod()
Returns the request method to use for the HTTP connection.
|
MultiValuedMap<java.lang.String,byte[]> |
getMultipartByteFields()
Returns a list of multipart binary fields that will be sent along with the request as part of the multipart
form data.
|
MultiValuedMap<java.lang.String,java.lang.String> |
getMultipartStringFields()
Returns a list of multipart form fields that will be sent along with the request as part of the multipart form
data.
|
java.io.OutputStream |
getOutputStream()
Returns an OutputStream that is able to write data to an HTTP URL that will be constructed
with the settings defined on this data source.
|
java.lang.String |
getPath()
Returns the entire path of the URL to use for the HTTP connection.
|
MultiValuedMap<java.lang.String,java.lang.String> |
getQueryParams()
Returns a list of query parameters that will be sent along with the request.
|
int |
getReadTimeout()
Gets the read timeout for the HTTP connection, in milliseconds.
|
int |
getResponseCode()
Gets the status code from an HTTP response message.
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getResponseHeaders()
Gets the response header fields from an HTTP response message.
|
java.lang.String |
getResponseMessage()
Gets the HTTP response message, if any, returned along with the response
code from a server.
|
void |
setConnectTimeout(int connectTimeout)
Sets the connect timeout for the HTTP connection, in milliseconds.
|
void |
setConsumerKey(java.lang.String consumerKey)
Sets the consumer key to use for creating the OAuth 1.0 signature that is sent along with the request, by setting
the
Authorization request header. |
void |
setConsumerSecret(java.lang.String consumerSecret)
Sets the consumer secret to use for creating the OAuth 1.0 signature that is sent along with the request, by
setting the
Authorization request header. |
void |
setContentType(java.lang.String contentType)
Sets the Content-Type request header for the HTTP connection.
|
void |
setDataString(java.lang.String dataString)
Sets the entity to use for the HTTP connection.
|
void |
setFormParams(MultiValuedMap<java.lang.String,java.lang.String> formParams)
Sets the list of form parameters to be sent along with the request.
|
void |
setHeaders(MultiValuedMap<java.lang.String,java.lang.String> headers)
Sets the list of HTTP headers to be sent along with the request.
|
void |
setHost(java.lang.String host)
Sets the complete host address of the URL to use for the HTTP connection.
|
void |
setMethod(java.lang.String method)
Sets the request method to use for the HTTP connection.
|
void |
setMultipartByteFields(MultiValuedMap<java.lang.String,byte[]> multipartByteFields)
Sets the list of multipart binary fields that will be sent along with the request as part of the multipart form
data.
|
void |
setMultipartStringFields(MultiValuedMap<java.lang.String,java.lang.String> multipartStringFields)
Sets the list of multipart form fields that will be sent along with the request as part of the multipart form
data.
|
void |
setPath(java.lang.String path)
Sets the entire path of the URL to use for the HTTP connection.
|
void |
setQueryParams(MultiValuedMap<java.lang.String,java.lang.String> queryParams)
Sets the list of query parameters to be sent along with the request.
|
void |
setReadTimeout(int readTimeout)
Sets the read timeout for the HTTP connection, in milliseconds.
|
public java.io.InputStream getInputStream() throws java.io.IOException
getInputStream
in interface InputDataSource
java.io.IOException
- when the HTTP connection could not be established or the InputStream could not be createdpublic java.io.OutputStream getOutputStream() throws java.io.IOException
getOutputStream
in interface OutputDataSource
java.io.IOException
- when the HTTP connection could not be established or the OutputStream could not be createdpublic java.lang.String getHost()
public void setHost(java.lang.String host)
host
- the complete host address of the URLpublic java.lang.String getPath()
public void setPath(java.lang.String path)
path
if it is missing.path
- the entire path of the URLpublic java.lang.String getMethod()
HttpURLConnection.getRequestMethod()
public void setMethod(java.lang.String method)
method
- the request method for the HTTP connectionHttpURLConnection.setRequestMethod(String)
public int getReadTimeout()
URLConnection.getReadTimeout()
public void setReadTimeout(int readTimeout)
readTimeout
- an int that specifies the timeout value to be used in millisecondsURLConnection.setReadTimeout(int)
public int getConnectTimeout()
URLConnection.getConnectTimeout()
public void setConnectTimeout(int connectTimeout)
connectTimeout
- an int that specifies the timeout value to be used in millisecondsURLConnection.setConnectTimeout(int)
public java.lang.String getDataString()
public void setDataString(java.lang.String dataString)
dataString
will be written to the OutputStream
of the HTTP connection. Please note, when specifying both a data string and form parameters, the data string
will be appended with an ampersand, followed by the encoded list of form parameters.dataString
- the entity for the HTTP connectionpublic java.lang.String getConsumerKey()
Authorization
request header.public void setConsumerKey(java.lang.String consumerKey)
Authorization
request header. Setting the consumer secret
is
mandatory when setting the consumer key.consumerKey
- the consumer key used for calculating the OAuth 1.0 signaturepublic java.lang.String getConsumerSecret()
Authorization
request header.public void setConsumerSecret(java.lang.String consumerSecret)
Authorization
request header. Setting the consumer secret has no effect when the
consumer key
is not set.consumerSecret
- the consumer secret used for calculating the OAuth 1.0 signaturepublic void addQueryParam(java.lang.String key, java.lang.String value)
key
- the key of the query parametervalue
- the value of the query parameterpublic MultiValuedMap<java.lang.String,java.lang.String> getQueryParams()
public void setQueryParams(MultiValuedMap<java.lang.String,java.lang.String> queryParams)
queryParams
- the list of query parameters to be sent with the requestpublic void addFormParam(java.lang.String key, java.lang.String value)
key
- the key of the form parametervalue
- the value of the form parameterpublic MultiValuedMap<java.lang.String,java.lang.String> getFormParams()
public void setFormParams(MultiValuedMap<java.lang.String,java.lang.String> formParams)
formParams
- the list of form parameters to be sent with the requestpublic java.lang.String getContentType()
public void setContentType(java.lang.String contentType)
data string
or form parameters
were set.
In case the content type header was not set, it will by default be set to
application/x-www-form-urlencoded
.contentType
- the Content-Type request header for the HTTP connectionpublic void addHeader(java.lang.String field, java.lang.String value)
setContentType(String)
),
so to avoid complications you should only set headers here if you haven't set them via any other methodsfield
- The name of the HTTP header field (e.g. "Accept")value
- The header value to send with the requestpublic MultiValuedMap<java.lang.String,java.lang.String> getHeaders()
addHeader(String, String)
or setHeaders(MultiValuedMap)
,
not those defined in any other way (e.g. by setContentType(String)
)public void setHeaders(MultiValuedMap<java.lang.String,java.lang.String> headers)
headers
- the list of headers to be sent with the requestpublic MultiValuedMap<java.lang.String,java.lang.String> getMultipartStringFields()
public void setMultipartStringFields(MultiValuedMap<java.lang.String,java.lang.String> multipartStringFields)
multipartStringFields
- the list of multipart form fields to be sent with the requestpublic MultiValuedMap<java.lang.String,byte[]> getMultipartByteFields()
public void setMultipartByteFields(MultiValuedMap<java.lang.String,byte[]> multipartByteFields)
multipartByteFields
- the list of multipart binary fields to be sent with the requestpublic java.util.Map<java.lang.String,java.util.List<java.lang.String>> getResponseHeaders()
URLConnection.getHeaderFields()
public int getResponseCode()
HttpURLConnection.getResponseCode()
public java.lang.String getResponseMessage()
null
HttpURLConnection.getResponseMessage()