Class RequestBuilder
-
Method Summary
Modifier and TypeMethodDescriptionAdd accept json header to the requestAdd a basic authentication Authorization headerAdd an authorization bearer header, this is shorthand forheader("Authorization", "Bearer " + token)Sets the request body lazily.body(PropertyBusinessObject body) Sets the request body to the JSON matching the given objectSets the request bodySets the caching mode for this request, seecom.codename1.io.ConnectionRequest#getCacheMode()Sets the value of the content typecookiesEnabled(boolean cookiesEnabled) Sets the cookiesEnabled parameter.fetchAsBytes(OnComplete<Response<byte[]>> callback) Executes the request asynchronously and writes the response to the provided CallbackfetchAsJsonMap(OnComplete<Response<Map>> callback) Executes the request asynchronously and writes the response to the provided CallbackfetchAsProperties(OnComplete<Response<PropertyBusinessObject>> callback, Class type) Executes the request asynchronously and writes the response to the provided Callback.fetchAsPropertyList(OnComplete<Response<List<PropertyBusinessObject>>> callback, Class type) Executes the request asynchronously and writes the response to the provided Callback.fetchAsPropertyList(OnComplete<Response<List<PropertyBusinessObject>>> callback, Class type, String root) Executes the request asynchronously and writes the response to the provided Callback.fetchAsString(OnComplete<Response<String>> callback) Executes the request asynchronously and writes the response to the provided CallbackResponse<byte[]> Executes the request synchronouslyvoidgetAsBytesAsync(Callback<Response<byte[]>> callback) Executes the request asynchronously and writes the response to the provided CallbackExecutes the request synchronouslygetAsJsonMap(SuccessCallback<Response<Map>> callback) Executes the request asynchronously and writes the response to the provided CallbackgetAsJsonMap(SuccessCallback<Response<Map>> callback, FailureCallback<? extends Object> onError) Executes the request asynchronously and writes the response to the provided CallbackvoidgetAsJsonMapAsync(Callback<Response<Map>> callback) Executes the request asynchronously and writes the response to the provided CallbackgetAsProperties(Class type) Executes the request synchronouslygetAsPropertyList(Class type) Executes the request synchronouslygetAsPropertyList(Class type, String root) Executes the request synchronouslyExecutes the request synchronouslyvoidgetAsStringAsync(Callback<Response<String>> callback) Executes the request asynchronously and writes the response to the provided Callbackgzip()Sets the request to be a gzip requestAdd a header to the requestinsecure(boolean insecure) Turns off checking to make sure that SSL certificate is valid.Sets both the content type and accept headers to "application/json"onError(ActionListener<NetworkEvent> error) Invoked for exceptions or failures such as disconnect.onError(ActionListener<NetworkEvent> error, boolean replace) Invoked for exceptions or failures such as disconnectonErrorCode(ErrorCodeHandler<PropertyBusinessObject> err, Class errorClass) In case of an error this method is invoked asynchronously to process the error content with the JSON data and places it into a business object in the callbackonErrorCodeBytes(ErrorCodeHandler<byte[]> err) In case of an error this method is invoked asynchronously to process the error content with the byte array dataIn case of an error this method is invoked asynchronously to process the error content with the JSON dataIn case of an error this method is invoked asynchronously to process the error content with the JSON dataAdd a path param to the request.postParameters(Boolean postParameters) Overrides the default behavior of methods so they can be sent using the post/get methodpriority(byte priority) Sets the priority of the request.queryParam(String key, String value) Add a query parameter to the requestqueryParam(String key, String[] values) Add multiple query parameter values to the request using same key.readTimeout(int timeout) Sets the request read timeout.timeout(int timeout) Sets the request timeoutuseBoolean(boolean useBoolean) Indicates if JSON should treat boolean values as Boolean.useLongs(boolean useLongs) Indicates if JSON should treat non-decimal numeric values as Long.
-
Method Details
-
insecure
Turns off checking to make sure that SSL certificate is valid.
Parameters
insecure: true to disable ssl certificate checking
Returns
this request builder
-
useBoolean
Indicates if JSON should treat boolean values as Boolean. This values is set implicitly to true when reading property business objects
Parameters
useBoolean: true to return Boolean objects in JSON Maps
Returns
this request builder
-
useLongs
Indicates if JSON should treat non-decimal numeric values as Long. If not set, uses the current default from the static value in JSONParser.isUseLongs
Parameters
useLongs: true to return Long objects in JSON Maps
Returns
this request builder
-
cacheMode
Sets the caching mode for this request, see
com.codename1.io.ConnectionRequest#getCacheMode()Parameters
cache: the cache mode
Returns
RequestBuilder instance
-
postParameters
Overrides the default behavior of methods so they can be sent using the post/get method
Parameters
postParameters: true to force post, false to use get method. Defaults to true for all methods other than GET
Returns
RequestBuilder instance
-
contentType
Sets the value of the content type
Parameters
s: the content type
Returns
RequestBuilder instance
-
priority
Sets the priority of the request.
Parameters
priority: The priority.
Returns
RequestBuilder instance.
Since
8.0
See also
- ConnectionRequest#setPriority(byte)
-
cookiesEnabled
Sets the cookiesEnabled parameter.
Parameters
cookiesEnabled: True to enable cookies. False to disable.
Returns
RequestBuilder instance.
Since
8.0
-
pathParam
Add a path param to the request. For example if the request url is: http://domain.com/users/{id} The path param can be - key="id", value="1" When the request executes the path would be: http://domain.com/users/1
Parameters
-
key: the identifier key in the request. -
value: the value to replace in the url
Returns
RequestBuilder instance
-
-
queryParam
Add a query parameter to the request
Parameters
-
key: param key -
value: param value
Returns
RequestBuilder instance
-
-
queryParam
Add multiple query parameter values to the request using same key.
Parameters
-
key: param key -
values: param values
Returns
RequestBuilder instance
Since
8.0
-
-
header
Add a header to the request
Parameters
-
key -
value
Returns
RequestBuilder instance
-
-
body
Sets the request body
Parameters
bodyContent: request body content
Returns
RequestBuilder instance
-
body
Sets the request body lazily.
Parameters
body: Wrapper for the request body that knows how to append to an output stream.
Returns
RequestBuilder instances
Since
7.0
See also
- #body(java.lang.String)
-
body
Sets the request body to the JSON matching the given object
Parameters
body: request body
Returns
RequestBuilder instance
-
onErrorCodeBytes
In case of an error this method is invoked asynchronously to process the error content with the byte array data
Parameters
err: the content of the error response
Returns
RequestBuilder instance
-
onErrorCodeJSON
In case of an error this method is invoked asynchronously to process the error content with the JSON data
Parameters
err: the content of the error response
Returns
RequestBuilder instance
-
onErrorCode
In case of an error this method is invoked asynchronously to process the error content with the JSON data and places it into a business object in the callback
Parameters
-
err: the content of the error response -
errorClass: the class of the business object into which the data is parsed
Returns
RequestBuilder instance
-
-
onErrorCodeString
In case of an error this method is invoked asynchronously to process the error content with the JSON data
Parameters
err: the content of the error response
Returns
RequestBuilder instance
-
onError
Invoked for exceptions or failures such as disconnect. Replaces any existing callbacks previously registered with
#onError(com.codename1.ui.events.ActionListener)Parameters
error: callback for a networking error
Returns
RequestBuilder instance
See also
- #onError(com.codename1.ui.events.ActionListener, boolean)
-
onError
Invoked for exceptions or failures such as disconnect
Parameters
-
error: callback for a networking error -
replace: @param replace If true, replaces the existing errorCallback(s) with the handler provided.
Returns
RequestBuilder instance
Since
7.0
-
-
timeout
Sets the request timeout
Parameters
timeout: request timeout in milliseconds
Returns
RequestBuilder instance
-
readTimeout
Sets the request read timeout. Only used if
ConnectionRequest#isReadTimeoutSupported()is true on this platform.Parameters
timeout: The timeout.
Returns
RequestBuilder instance.
-
gzip
Sets the request to be a gzip request
Returns
RequestBuilder instance
-
acceptJson
Add accept json header to the request
Returns
RequestBuilder instance
-
jsonContent
Sets both the content type and accept headers to "application/json"
Returns
RequestBuilder instance
-
basicAuth
Add a basic authentication Authorization header
Returns
RequestBuilder instance
-
bearer
Add an authorization bearer header, this is shorthand for
header("Authorization", "Bearer " + token)Parameters
token: the authorization token
Returns
RequestBuilder instance
-
fetchAsString
Executes the request asynchronously and writes the response to the provided Callback
Parameters
callback: invoked with the result of the builder query
Returns
the ConnectionRequest instance
-
getAsStringAsync
-
getAsString
-
fetchAsBytes
Executes the request asynchronously and writes the response to the provided Callback
Parameters
callback: writes the response to this callback
Returns
the connection request instance
-
getAsBytesAsync
-
getAsBytes
Executes the request synchronously
Returns
Response Object
-
fetchAsJsonMap
Executes the request asynchronously and writes the response to the provided Callback
Parameters
callback: writes the response to this callback
Returns
returns the Connection Request object so it can be killed if necessary
-
fetchAsProperties
public ConnectionRequest fetchAsProperties(OnComplete<Response<PropertyBusinessObject>> callback, Class type) Executes the request asynchronously and writes the response to the provided Callback. This fetches JSON data and parses it into a properties business object
Parameters
-
callback: writes the response to this callback -
type: the class of the business object returned
Returns
returns the Connection Request object so it can be killed if necessary
-
-
getAsJsonMap
Executes the request asynchronously and writes the response to the provided Callback
Parameters
callback: writes the response to this callback
Returns
returns the Connection Request object so it can be killed if necessary
Deprecated
use
#fetchAsJsonMap(com.codename1.util.OnComplete)instead -
getAsJsonMap
public ConnectionRequest getAsJsonMap(SuccessCallback<Response<Map>> callback, FailureCallback<? extends Object> onError) Executes the request asynchronously and writes the response to the provided Callback
Parameters
-
callback: writes the response to this callback -
onError: the error callback
Returns
returns the Connection Request object so it can be killed if necessary
Deprecated
use
#fetchAsJsonMap(com.codename1.util.OnComplete)instead -
-
getAsJsonMapAsync
-
getAsJsonMap
-
getAsProperties
Executes the request synchronously
Parameters
type: the type of the business object to create
Returns
Response Object
-
fetchAsPropertyList
public ConnectionRequest fetchAsPropertyList(OnComplete<Response<List<PropertyBusinessObject>>> callback, Class type, String root) Executes the request asynchronously and writes the response to the provided Callback. This fetches JSON data and parses it into a properties business object
Parameters
-
callback: writes the response to this callback -
type: the class of the business object returned -
root: the root element's key of the structured content
Returns
returns the Connection Request object so it can be killed if necessary
-
-
fetchAsPropertyList
public ConnectionRequest fetchAsPropertyList(OnComplete<Response<List<PropertyBusinessObject>>> callback, Class type) Executes the request asynchronously and writes the response to the provided Callback. This fetches JSON data and parses it into a properties business object
Parameters
-
callback: writes the response to this callback -
type: the class of the business object returned
Returns
returns the Connection Request object so it can be killed if necessary
-
-
getAsPropertyList
Executes the request synchronously
Parameters
-
type: the type of the business object to create -
root: the root element's key of the structured content
Returns
Response Object
-
-
getAsPropertyList
Executes the request synchronously
Parameters
type: the type of the business object to create
Returns
Response Object
-
getRequestUrl
-