public class RequestBuilder extends Object
Modifier and Type | Method and Description |
---|---|
RequestBuilder |
acceptJson()
Add accept json header to the request
|
RequestBuilder |
basicAuth(String username,
String password)
Add a basic authentication Authorization header
|
RequestBuilder |
bearer(String token)
Add an authorization bearer header, this is shorthand for
header("Authorization", "Bearer " + token) |
RequestBuilder |
body(Data body)
Sets the request body lazily.
|
RequestBuilder |
body(PropertyBusinessObject body)
Sets the request body to the JSON matching the given object
|
RequestBuilder |
body(String bodyContent)
Sets the request body
|
RequestBuilder |
cacheMode(ConnectionRequest.CachingMode cache)
Sets the caching mode for this request, see
ConnectionRequest.getCacheMode() |
RequestBuilder |
contentType(String s)
Sets the value of the content type
|
RequestBuilder |
cookiesEnabled(boolean cookiesEnabled)
Sets the cookiesEnabled parameter.
|
ConnectionRequest |
fetchAsBytes(OnComplete<Response<byte[]>> callback)
Executes the request asynchronously and writes the response to the provided
Callback
|
ConnectionRequest |
fetchAsJsonMap(OnComplete<Response<Map>> callback)
Executes the request asynchronously and writes the response to the provided
Callback
|
ConnectionRequest |
fetchAsProperties(OnComplete<Response<PropertyBusinessObject>> callback,
Class type)
Executes the request asynchronously and writes the response to the provided
Callback.
|
ConnectionRequest |
fetchAsPropertyList(OnComplete<Response<List<PropertyBusinessObject>>> callback,
Class type)
Executes the request asynchronously and writes the response to the provided
Callback.
|
ConnectionRequest |
fetchAsPropertyList(OnComplete<Response<List<PropertyBusinessObject>>> callback,
Class type,
String root)
Executes the request asynchronously and writes the response to the provided
Callback.
|
ConnectionRequest |
fetchAsString(OnComplete<Response<String>> callback)
Executes the request asynchronously and writes the response to the provided
Callback
|
Response<byte[]> |
getAsBytes()
Executes the request synchronously
|
void |
getAsBytesAsync(Callback<Response<byte[]>> callback)
Deprecated.
use
fetchAsBytes(com.codename1.util.OnComplete) instead |
Response<Map> |
getAsJsonMap()
Executes the request synchronously
|
ConnectionRequest |
getAsJsonMap(SuccessCallback<Response<Map>> callback)
Deprecated.
use
fetchAsJsonMap(com.codename1.util.OnComplete) instead |
ConnectionRequest |
getAsJsonMap(SuccessCallback<Response<Map>> callback,
FailureCallback<? extends Object> onError)
Deprecated.
use
fetchAsJsonMap(com.codename1.util.OnComplete) instead |
void |
getAsJsonMapAsync(Callback<Response<Map>> callback)
Deprecated.
use
fetchAsJsonMap(com.codename1.util.OnComplete) instead |
Response<PropertyBusinessObject> |
getAsProperties(Class type)
Executes the request synchronously
|
Response<List<PropertyBusinessObject>> |
getAsPropertyList(Class type)
Executes the request synchronously
|
Response<List<PropertyBusinessObject>> |
getAsPropertyList(Class type,
String root)
Executes the request synchronously
|
Response<String> |
getAsString()
Executes the request synchronously
|
void |
getAsStringAsync(Callback<Response<String>> callback)
Deprecated.
please use
fetchAsString(com.codename1.util.OnComplete) instead |
String |
getRequestUrl() |
RequestBuilder |
gzip()
Deprecated.
this API was implemented incorrectly
|
RequestBuilder |
header(String key,
String value)
Add a header to the request
|
RequestBuilder |
insecure(boolean insecure)
Turns off checking to make sure that SSL certificate is valid.
|
RequestBuilder |
jsonContent()
Sets both the content type and accept headers to "application/json"
|
RequestBuilder |
onError(ActionListener<NetworkEvent> error)
Invoked for exceptions or failures such as disconnect.
|
RequestBuilder |
onError(ActionListener<NetworkEvent> error,
boolean replace)
Invoked for exceptions or failures such as disconnect
|
RequestBuilder |
onErrorCode(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 callback
|
RequestBuilder |
onErrorCodeBytes(ErrorCodeHandler<byte[]> err)
In case of an error this method is invoked asynchronously to process
the error content with the byte array data
|
RequestBuilder |
onErrorCodeJSON(ErrorCodeHandler<Map> err)
In case of an error this method is invoked asynchronously to process
the error content with the JSON data
|
RequestBuilder |
onErrorCodeString(ErrorCodeHandler<String> err)
In case of an error this method is invoked asynchronously to process
the error content with the JSON data
|
RequestBuilder |
pathParam(String key,
String value)
Add a path param to the request.
|
RequestBuilder |
postParameters(Boolean postParameters)
Overrides the default behavior of methods so they can be sent using the post/get method
|
RequestBuilder |
priority(byte priority)
Sets the priority of the request.
|
RequestBuilder |
queryParam(String key,
String value)
Add a query parameter to the request
|
RequestBuilder |
queryParam(String key,
String[] values)
Add multiple query parameter values to the request using same key.
|
RequestBuilder |
readTimeout(int timeout)
Sets the request read timeout.
|
RequestBuilder |
timeout(int timeout)
Sets the request timeout
|
RequestBuilder |
useBoolean(boolean useBoolean)
Indicates if JSON should treat boolean values as Boolean.
|
RequestBuilder |
useLongs(boolean useLongs)
Indicates if JSON should treat non-decimal numeric values as Long.
|
public RequestBuilder insecure(boolean insecure)
insecure
- true to disable ssl certificate checkingpublic RequestBuilder useBoolean(boolean useBoolean)
useBoolean
- true to return Boolean objects in JSON Mapspublic RequestBuilder useLongs(boolean useLongs)
useLongs
- true to return Long objects in JSON Mapspublic RequestBuilder cacheMode(ConnectionRequest.CachingMode cache)
ConnectionRequest.getCacheMode()
cache
- the cache modepublic RequestBuilder postParameters(Boolean postParameters)
postParameters
- true to force post, false to use get method. Defaults to true for all methods other than GETpublic RequestBuilder contentType(String s)
s
- the content typepublic RequestBuilder priority(byte priority)
priority
- The priority.ConnectionRequest.setPriority(byte)
public RequestBuilder cookiesEnabled(boolean cookiesEnabled)
cookiesEnabled
- True to enable cookies. False to disable.public RequestBuilder pathParam(String key, String value)
key
- the identifier key in the request.value
- the value to replace in the urlpublic RequestBuilder queryParam(String key, String value)
key
- param keyvalue
- param valuepublic RequestBuilder queryParam(String key, String[] values)
key
- param keyvalues
- param valuespublic RequestBuilder header(String key, String value)
key
- value
- public RequestBuilder body(String bodyContent)
body
- request bodyContentpublic RequestBuilder body(Data body)
body
- Wrapper for the request body that knows how to append to an output stream.body(java.lang.String)
public RequestBuilder body(PropertyBusinessObject body)
body
- request bodypublic RequestBuilder onErrorCodeBytes(ErrorCodeHandler<byte[]> err)
err
- the content of the error responsepublic RequestBuilder onErrorCodeJSON(ErrorCodeHandler<Map> err)
err
- the content of the error responsepublic RequestBuilder onErrorCode(ErrorCodeHandler<PropertyBusinessObject> err, Class errorClass)
err
- the content of the error responseerrorClass
- the class of the business object into which the data is parsedpublic RequestBuilder onErrorCodeString(ErrorCodeHandler<String> err)
err
- the content of the error responsepublic RequestBuilder onError(ActionListener<NetworkEvent> error)
onError(com.codename1.ui.events.ActionListener)
error
- callback for a networking erroronError(com.codename1.ui.events.ActionListener, boolean)
public RequestBuilder onError(ActionListener<NetworkEvent> error, boolean replace)
error
- callback for a networking errorreplace
- If true, replaces the existing errorCallback(s) with the handler
provided.public RequestBuilder timeout(int timeout)
timeout
- request timeout in millisecondspublic RequestBuilder readTimeout(int timeout)
ConnectionRequest.isReadTimeoutSupported()
is true on this platform.timeout
- The timeout.public RequestBuilder gzip()
public RequestBuilder acceptJson()
public RequestBuilder jsonContent()
public RequestBuilder basicAuth(String username, String password)
public RequestBuilder bearer(String token)
header("Authorization", "Bearer " + token)
token
- the authorization tokenpublic ConnectionRequest fetchAsString(OnComplete<Response<String>> callback)
callback
- invoked with the result of the builder querypublic void getAsStringAsync(Callback<Response<String>> callback)
fetchAsString(com.codename1.util.OnComplete)
insteadcallback
- writes the response to this callbackpublic Response<String> getAsString()
public ConnectionRequest fetchAsBytes(OnComplete<Response<byte[]>> callback)
callback
- writes the response to this callbackpublic void getAsBytesAsync(Callback<Response<byte[]>> callback)
fetchAsBytes(com.codename1.util.OnComplete)
insteadcallback
- writes the response to this callbackpublic Response<byte[]> getAsBytes()
public ConnectionRequest fetchAsJsonMap(OnComplete<Response<Map>> callback)
callback
- writes the response to this callbackpublic ConnectionRequest fetchAsProperties(OnComplete<Response<PropertyBusinessObject>> callback, Class type)
callback
- writes the response to this callbacktype
- the class of the business object returnedpublic ConnectionRequest getAsJsonMap(SuccessCallback<Response<Map>> callback)
fetchAsJsonMap(com.codename1.util.OnComplete)
insteadcallback
- writes the response to this callbackpublic ConnectionRequest getAsJsonMap(SuccessCallback<Response<Map>> callback, FailureCallback<? extends Object> onError)
fetchAsJsonMap(com.codename1.util.OnComplete)
insteadcallback
- writes the response to this callbackonError
- the error callbackpublic void getAsJsonMapAsync(Callback<Response<Map>> callback)
fetchAsJsonMap(com.codename1.util.OnComplete)
insteadcallback
- writes the response to this callbackpublic Response<Map> getAsJsonMap()
public Response<PropertyBusinessObject> getAsProperties(Class type)
type
- the type of the business object to createpublic ConnectionRequest fetchAsPropertyList(OnComplete<Response<List<PropertyBusinessObject>>> callback, Class type, String root)
callback
- writes the response to this callbacktype
- the class of the business object returnedroot
- the root element's key of the structured contentpublic ConnectionRequest fetchAsPropertyList(OnComplete<Response<List<PropertyBusinessObject>>> callback, Class type)
callback
- writes the response to this callbacktype
- the class of the business object returnedpublic Response<List<PropertyBusinessObject>> getAsPropertyList(Class type, String root)
type
- the type of the business object to createroot
- the root element's key of the structured contentpublic Response<List<PropertyBusinessObject>> getAsPropertyList(Class type)
type
- the type of the business object to createpublic String getRequestUrl()