T - the type of the data that is expected from the REST endpoint.public class RestSource<T> extends InputStreamDataReader<T> implements WritableDataReader<T>
| Type | Property and Description |
|---|---|
javafx.beans.property.ReadOnlyIntegerProperty |
responseCode
Gets the status code from an HTTP response message.
|
javafx.beans.property.ReadOnlyStringProperty |
responseMessage
Gets the HTTP response message, if any, returned along with the response
code from a server.
|
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
METHOD_GET |
static java.lang.String |
METHOD_POST |
protected boolean |
requestMade |
| Constructor and Description |
|---|
RestSource()
Create a new RestSource
|
RestSource(java.lang.String host,
InputStreamConverter<T> converter)
Create a new RestSource and specifies the endpoint and the converter
|
| Modifier and Type | Method and Description |
|---|---|
java.io.InputStream |
createInputStream()
Create the InputStream for this request.
|
protected void |
createRequest() |
T |
get()
Obtain the next entity of data.
|
java.lang.String |
getConsumerKey()
Return the consumer key (used with oauth) for this request
|
java.lang.String |
getConsumerSecret()
Return the consumer secret (if used with oauth) for this request
|
java.lang.String |
getContentType() |
java.lang.String |
getDataString()
Return the datastring that will be send with this request
|
MultiValuedMap |
getFormParams()
Return a
MultiValuedMap for the form parameters in this request. |
java.util.Map<java.lang.String,java.lang.String> |
getQueryParams()
Return the query parameters as a
Map |
java.lang.String |
getRequestMethod()
Return the request method for this request.
|
java.util.Map<java.lang.String,java.lang.String> |
getRequestProperties()
Return the request properties as a
Map |
int |
getResponseCode()
Gets the value of the property responseCode.
|
java.lang.String |
getResponseMessage()
Gets the value of the property responseMessage.
|
int |
getTimeout()
Get the timeout value specified for this instance
|
boolean |
next()
Check if more data is available on this DataReader.
|
javafx.beans.property.ReadOnlyIntegerProperty |
responseCodeProperty()
Gets the status code from an HTTP response message.
|
javafx.beans.property.ReadOnlyStringProperty |
responseMessageProperty()
Gets the HTTP response message, if any, returned along with the response
code from a server.
|
void |
setConsumerKey(java.lang.String consumerKey)
Set the consumer key for this request.
|
void |
setConsumerSecret(java.lang.String consumerSecret)
Set the consumer secret
|
void |
setContentType(java.lang.String contentType)
Set the contentType for this request.
|
void |
setDataString(java.lang.String dataString)
Explicitly set the datastring for this request.
|
void |
setFormParams(java.util.Map<java.lang.String,java.lang.String> formParams)
Set the form parameters as a
Map. |
void |
setFormParams(MultiValuedMap formParams)
Set the form parameters as a
MultiValuedMap |
void |
setHost(java.lang.String host)
Set the host parameter for this endpoint.
|
void |
setPath(java.lang.String path)
Explicitly sets the path for this resource.
|
void |
setQueryParams(java.util.Map<java.lang.String,java.lang.String> queryParams)
Set the query parameters as a
Map |
void |
setRequestMethod(java.lang.String requestMethod)
Set the request method for this request as a
String
(e.g. |
void |
setRequestProperties(java.util.Map<java.lang.String,java.lang.String> requestProperties)
Set the request properties as a
Map |
void |
setTimeout(int timeout)
Set the timeout value for this instance.
|
void |
writeBack()
Initiates the writeback call.
|
getConverter, getInputStream, setConverter, setInputStreamiteratorpublic javafx.beans.property.ReadOnlyIntegerProperty responseCodeProperty
getResponseCode()public javafx.beans.property.ReadOnlyStringProperty responseMessageProperty
getResponseMessage()public static final java.lang.String METHOD_GET
public static final java.lang.String METHOD_POST
protected boolean requestMade
public RestSource()
public RestSource(java.lang.String host,
InputStreamConverter<T> converter)
host - the host parameter of the endpointconverter - the Converter that will be used to convert the
raw data into Java objects of type T.public void setHost(java.lang.String host)
host - the host parameter for this endpoint.public void setPath(java.lang.String path)
path - the path. If null, the path will be the empty Stringprotected void createRequest()
throws java.io.IOException
java.io.IOExceptionpublic T get() throws java.io.IOException
DataReaderget in interface DataReader<T>get in class InputStreamDataReader<T>java.io.IOException - in case an exception occurs while reading datapublic boolean next()
DataReadernext in interface DataReader<T>next in class InputStreamDataReader<T>public java.io.InputStream createInputStream()
throws java.io.IOException
errorStream of the URL
connection instead and no IOException will be thrown. This allows the
coupled Converter to continue parsing the response from the server.
In case no requestMethod is specified via setRequestMethod,
a POST request will be created in case form parameters or a dataString
are supplied; a GET request will be created in the other cases.InputStreamjava.io.IOException - in case the InputStream cannot be created
successfully.public java.lang.String getConsumerKey()
public void setConsumerKey(java.lang.String consumerKey)
consumerKey - the consumerKey to setpublic java.lang.String getConsumerSecret()
public void setConsumerSecret(java.lang.String consumerSecret)
consumerSecret - the consumerSecret to setpublic java.util.Map<java.lang.String,java.lang.String> getRequestProperties()
Mappublic void setRequestProperties(java.util.Map<java.lang.String,java.lang.String> requestProperties)
MaprequestProperties - the requestProperties to setpublic java.util.Map<java.lang.String,java.lang.String> getQueryParams()
Mappublic void setQueryParams(java.util.Map<java.lang.String,java.lang.String> queryParams)
MapqueryParams - the queryParams to set. If null, this call is ignoredpublic MultiValuedMap getFormParams()
MultiValuedMap for the form parameters in this request.public void setFormParams(java.util.Map<java.lang.String,java.lang.String> formParams)
Map. This is a convenience method,
as form parameters can also be passed as a MultiValuedMapformParams - the formParams to setpublic void setFormParams(MultiValuedMap formParams)
MultiValuedMapformParams - the formParams to setpublic java.lang.String getDataString()
public void setDataString(java.lang.String dataString)
dataString - the dataString to setpublic java.lang.String getRequestMethod()
public void setRequestMethod(java.lang.String requestMethod)
String
(e.g. "POST", "GET")requestMethod - the requestMethod to setpublic void writeBack()
WritableDataReaderwriteBack in interface WritableDataReader<T>public int getTimeout()
public void setTimeout(int timeout)
timeout - the timeout valuepublic java.lang.String getContentType()
public void setContentType(java.lang.String contentType)
contentType - the contentType to setpublic int getResponseCode()
public javafx.beans.property.ReadOnlyIntegerProperty responseCodeProperty()
getResponseCode()public java.lang.String getResponseMessage()
public javafx.beans.property.ReadOnlyStringProperty responseMessageProperty()
getResponseMessage()