CloudPlugs REST Library  1.0.0
for Java
Response Class Reference

An instance of this class is a HTTP response received by the server or a generic error response. More...

Public Member Functions

 Response (int status, String msg, String body)
 
boolean isCompleted ()
 
boolean isSuccess ()
 
boolean isPartial ()
 
boolean isFailed ()
 
boolean isMultiple ()
 
int getStatus ()
 
String getMsg ()
 
String getBody ()
 
Object getBodyAsJson ()
 
String getBodyAsString ()
 
Response [] getMultiple ()
 
String toString ()
 

Static Public Attributes

static final int STATUS_OK = 200
 
static final int STATUS_CREATED = 201
 
static final int STATUS_PARTIAL = 206
 
static final int STATUS_MULTI = 207
 
static final int ERR_BAD_REQUEST = 400
 
static final int ERR_UNAUTHORIZED = 401
 
static final int ERR_PAYMENT_REQUIRED = 402
 
static final int ERR_FORBIDDEN = 403
 
static final int ERR_NOT_FOUND = 404
 
static final int ERR_NOT_ALLOWED = 405
 
static final int ERR_NOT_ACCEPTABLE = 406
 
static final int ERR_INTERNAL = 500
 
static final int ERR_NOT_IMPLEMENTED = 501
 
static final int ERR_BAD_GATEWAY = 502
 
static final int ERR_UNAVAILABLE = 503
 

Detailed Description

An instance of this class is a HTTP response received by the server or a generic error response.

Constructor & Destructor Documentation

◆ Response()

Response ( int  status,
String  msg,
String  body 
)

Create a new HTTP response.

Parameters
statusthe received HTTP status code or an integer less that zero for unknown response
msgthe message of the status code
bodythe received body of this response

Member Function Documentation

◆ getBody()

String getBody ( )

HTTP body getter.

Returns
the HTTP body of this response or null for empty body

◆ getBodyAsJson()

Object getBodyAsJson ( )

HTTP body getter as JSON instance.

Returns
the response body as a JSON instance, it can be an instance of org.json.JSONObject, org.json.JSONArray, java.lang.Number, java.lang.Boolean, java.lang.String or null for empty body

◆ getBodyAsString()

String getBodyAsString ( )

HTTP body getter as a decoded JSON string value.

Returns
the response body as a decoded JSON string value or null for empty body
Exceptions
RestExceptionif the response body is not null and if it is a JSON string value

◆ getMsg()

String getMsg ( )

HTTP status message getter.

Returns
the HTTP status message of this response

◆ getMultiple()

Response [] getMultiple ( )

Helper method to obtain an array of more responses.

Returns
the multiple responses (or an array containing this response if it is not multiple)
Exceptions
RestExceptionon error when decoding the JSON body of this response

◆ getStatus()

int getStatus ( )

HTTP status code getter.

Returns
the HTTP status code of this response

◆ isCompleted()

boolean isCompleted ( )
Returns
true if the corresponding request was really sent to server

◆ isFailed()

boolean isFailed ( )
Returns
true if the corresponding request was not successful (in other words failed or partially failed)

◆ isMultiple()

boolean isMultiple ( )
Returns
true if the body of this response contains multiple values (array of JSON)

◆ isPartial()

boolean isPartial ( )
Returns
true if the corresponding request has been partially successful and partially failed

◆ isSuccess()

boolean isSuccess ( )
Returns
true if the corresponding request was successful

◆ toString()

String toString ( )

Member Data Documentation

◆ ERR_BAD_GATEWAY

final int ERR_BAD_GATEWAY = 502
static

◆ ERR_BAD_REQUEST

final int ERR_BAD_REQUEST = 400
static

◆ ERR_FORBIDDEN

final int ERR_FORBIDDEN = 403
static

◆ ERR_INTERNAL

final int ERR_INTERNAL = 500
static

◆ ERR_NOT_ACCEPTABLE

final int ERR_NOT_ACCEPTABLE = 406
static

◆ ERR_NOT_ALLOWED

final int ERR_NOT_ALLOWED = 405
static

◆ ERR_NOT_FOUND

final int ERR_NOT_FOUND = 404
static

◆ ERR_NOT_IMPLEMENTED

final int ERR_NOT_IMPLEMENTED = 501
static

◆ ERR_PAYMENT_REQUIRED

final int ERR_PAYMENT_REQUIRED = 402
static

◆ ERR_UNAUTHORIZED

final int ERR_UNAUTHORIZED = 401
static

◆ ERR_UNAVAILABLE

final int ERR_UNAVAILABLE = 503
static

◆ STATUS_CREATED

final int STATUS_CREATED = 201
static

Successful HTTP status code for creation requests

◆ STATUS_MULTI

final int STATUS_MULTI = 207
static

Another partial successful HTTP status code

◆ STATUS_OK

final int STATUS_OK = 200
static

Successful HTTP status code for generic requests

◆ STATUS_PARTIAL

final int STATUS_PARTIAL = 206
static

Partial successful HTTP status code