Class CloudHttp
java.lang.Object
com.codename1.cloud.CloudHttp
Helpers shared by the REST clients: JSON bodies and the response handlers.
UTF-8 conversion is
com.codename1.util.StringUtil, URL encoding
com.codename1.io.Util#encodeUriComponent(String) and JSON member reads
com.codename1.mapping.JsonValues.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceWhat#retryOn401(CloudHttpTransport.Handler, Reauthenticator)does when a request is refused with 401: refresh the credentials, then send the same request again without another retry. -
Method Summary
Modifier and TypeMethodDescriptionstatic CloudHttpTransport.HandlerbytesHandler(AsyncResource<byte[]> out) A handler that completesoutwith the body of a 2xx response.static CloudHttpTransport.HandlerdoneHandler(AsyncResource<Boolean> out) A handler that completesoutwith true on a 2xx response.static booleanfailed(AsyncResource<?> out, int status, byte[] body) Completesoutwith an error whenstatusis not a 2xx code.static CloudHttpTransport.HandlerjsonHandler(AsyncResource<Map<String, Object>> out) A handler that completesoutwith the parsed JSON object of a 2xx response.parseJson(byte[] body) Parses a JSON response.parseJsonArray(byte[] body) Parses a JSON array response into a list of objects.static CloudHttpTransport.HandlerretryOn401(CloudHttpTransport.Handler handler, CloudHttp.Reauthenticator auth) Wraps a handler so that a 401 response refreshes the credentials and resends the request once.static CloudHttpTransport.HandlerrowsHandler(AsyncResource<List<Map<String, Object>>> out) A handler that completesoutwith the rows of a 2xx JSON array response.static byte[]Serializes a map or list to JSON bytes.
-
Method Details
-
toJson
Serializes a map or list to JSON bytes.
Parameters
value: aMaporList
Returns
the UTF-8 JSON
-
parseJson
-
parseJsonArray
-
failed
Completes
outwith an error whenstatusis not a 2xx code.Parameters
-
out: the result to fail -
status: the HTTP status -
body: the response body
Returns
true when the status was an error and
outwas failed -
-
jsonHandler
A handler that completes
outwith the parsed JSON object of a 2xx response.Parameters
out: the result
Returns
the handler
-
bytesHandler
A handler that completes
outwith the body of a 2xx response.Parameters
out: the result
Returns
the handler
-
doneHandler
A handler that completes
outwith true on a 2xx response.Parameters
out: the result
Returns
the handler
-
rowsHandler
A handler that completes
outwith the rows of a 2xx JSON array response.Parameters
out: the result
Returns
the handler
-
retryOn401
public static CloudHttpTransport.Handler retryOn401(CloudHttpTransport.Handler handler, CloudHttp.Reauthenticator auth) Wraps a handler so that a 401 response refreshes the credentials and resends the request once. Any other status, and a 401 whose refresh fails, reaches
handlerunchanged.Parameters
handler: the handler of the original requestauth: refreshes the credentials and resends
Returns
the wrapping handler
-