public class ResponseUtil extends Object
| Constructor and Description |
|---|
ResponseUtil() |
| Modifier and Type | Method and Description |
|---|---|
static String |
getMessage(org.restlet.data.Response response)
Extract the message from the response, or default a message.
|
static String |
getMessage(org.restlet.data.Status status)
Extract a meaningful message from Status object.
|
static InputStream |
getStream(org.restlet.data.Response response)
This method will extract the
InputStream present in a Response. |
static boolean |
isHttpBackoff(int code)
Check whether the HTTP status code is our backoff code.
|
static boolean |
isHttpSuccess(int code,
boolean unavailableIsSuccess)
Check http code for OK status.
|
static <T> T |
parse(org.restlet.data.Response response,
com.boomi.util.StreamUtil.Parser<T> parser)
This method will extract the
InputStream present in the Response and
will parse the InputStream to return T. |
static org.restlet.resource.Representation |
parseResponseToRepresentation(org.restlet.data.Response response)
Lazy man's tool to extract a
Representation from a Response. |
static Payload |
toErrorPayload(org.restlet.data.Response response,
Logger log)
Converts a response to a payload and logs any issues reading the stream using the provided
logger.
|
static ExtendedPayload |
toErrorPayload(org.restlet.data.Response response,
Logger log,
PayloadMetadata metadata)
Converts a response to a payload with the provided metadata and logs any issues reading the
stream using the provided logger.
|
static Payload |
toPayload(org.restlet.data.Response response)
Converts a response to a payload.
|
static ExtendedPayload |
toPayload(org.restlet.data.Response response,
PayloadMetadata metadata)
Converts a response to a payload with the provided metadata.
|
static <T> T |
unmarshallResponse(Class<T> unmarshallClass,
org.restlet.data.Response response)
Really lazy man's tool to unmarshall an object from a response.
|
static boolean |
validateResponse(org.restlet.data.Response response)
Quick and easy tool to validate a
Response status. |
static boolean |
validateResponse(org.restlet.data.Response response,
boolean unavailableIsSuccess)
Quick and easy tool to validate a
Response status. |
public static boolean validateResponse(org.restlet.data.Response response)
Response status.response - the response to validatepublic static boolean validateResponse(org.restlet.data.Response response,
boolean unavailableIsSuccess)
Response status.response - to validateunavailableIsSuccess - if resource unavailable counts as a successpublic static org.restlet.resource.Representation parseResponseToRepresentation(org.restlet.data.Response response)
throws Exception
Representation from a Response. First validates
the response to make sure the status is ok.response - which may contain a Representation.Exception - if the response is invalid.public static <T> T unmarshallResponse(Class<T> unmarshallClass, org.restlet.data.Response response) throws Exception
unmarshallClass - The class of Object we expect to find.response - which should contain the object.Exception - if errors occurred.public static boolean isHttpSuccess(int code,
boolean unavailableIsSuccess)
code - the HTTP status codeunavailableIsSuccess - if UNAVAILABLE status is ok in this casepublic static boolean isHttpBackoff(int code)
code - the HTTP status codepublic static String getMessage(org.restlet.data.Response response)
response - the responsepublic static String getMessage(org.restlet.data.Status status)
status - the status responsepublic static Payload toErrorPayload(org.restlet.data.Response response, Logger log)
toPayload(Response) variation which fails if an exception occurs while reading the
entity stream.response - the error response to convertlog - the loggerpublic static ExtendedPayload toErrorPayload(org.restlet.data.Response response, Logger log, PayloadMetadata metadata)
toPayload(Response, PayloadMetadata) variation which fails if an
exception occurs while reading the entity stream.response - the error response to convertlog - the loggermetadata - the metadatanull), null otherwisepublic static Payload toPayload(org.restlet.data.Response response) throws IOException
response - the response to convertIOException - if the response entity stream is available but cannot be readpublic static ExtendedPayload toPayload(org.restlet.data.Response response, PayloadMetadata metadata) throws IOException
response - the response to convertmetadata - the metadatanull), null otherwiseIOException - if the response entity stream is available but cannot be readpublic static <T> T parse(org.restlet.data.Response response,
com.boomi.util.StreamUtil.Parser<T> parser)
throws IOException
InputStream present in the Response and
will parse the InputStream to return T. The parsing is done by a StreamUtil.Parser
implementation which would call StreamUtil.Parser#parse(InputStream) to parse
the InputStream. The InputStream will be closed once it has been parsed.T - response - The response to parseparser - The parser implementation that will parse the underlying input streamIOExceptionpublic static InputStream getStream(org.restlet.data.Response response) throws IOException
InputStream present in a Response. It will first check
if the Response is not null and Message.isEntityAvailable() is true. Otherwise this
method will throw and IOException.response - IOException