Package me.geso.mech2
Class Mech2Result
java.lang.Object
me.geso.mech2.Mech2Result
HTTP request result.
It contains HttpRequest object and HttpResponse object.
- Author:
- tokuhirom
-
Method Summary
Modifier and TypeMethodDescriptionorg.apache.http.entity.ContentTypeGet ContentType object from the response.org.apache.http.HttpRequestGet HttpRequest object.org.apache.http.HttpResponseGet HttpResponse object.byte[]Get the HTTP response as byte array.Get the HTTP response as String.intShorthand formech.getResponse().getStatusLine().getStatusCode()booleanReturns true if Content-Type of response is "application/json".booleanReturns true if the HttResponse has 2xx status code.orDie()throw exception if the response doesn't have 2xx response.<T> TparseJSON(com.fasterxml.jackson.core.type.TypeReference<T> valueType) Parse JSON from content-body using jackson.<T> TParse JSON from content-body using jackson.<T> Mech2JSONResult<T>toJSONResult(com.fasterxml.jackson.core.type.TypeReference<T> klass) Convert the result to Mech2JSONResult object.<T> Mech2JSONResult<T>toJSONResult(Class<T> valueType) Convert the result to Mech2JSONResult object.
-
Method Details
-
getRequest
public org.apache.http.HttpRequest getRequest()Get HttpRequest object.- Returns:
- request
-
getResponse
public org.apache.http.HttpResponse getResponse()Get HttpResponse object.- Returns:
- response
-
isSuccess
public boolean isSuccess()Returns true if the HttResponse has 2xx status code. False otherwise.- Returns:
- true if response code is 2XX, false otherwise.
-
isJSONResponse
public boolean isJSONResponse()Returns true if Content-Type of response is "application/json". Otherwise, returns false.- Returns:
- true if the response's content-type is json-ish, false otherwise.
-
toJSONResult
Convert the result to Mech2JSONResult object. It contains this object and JSON type information.- Parameters:
valueType- type of JSON value- Returns:
- result object with JSON type information.
-
toJSONResult
Convert the result to Mech2JSONResult object. It contains this object and JSON type information.- Parameters:
klass- type of JSON value- Returns:
- result object with JSON type information
-
parseJSON
public <T> T parseJSON(com.fasterxml.jackson.core.type.TypeReference<T> valueType) throws IOException Parse JSON from content-body using jackson.- Parameters:
valueType- type of json value- Returns:
- parsed result
- Throws:
IOException
-
parseJSON
Parse JSON from content-body using jackson.- Parameters:
valueType- type of json value- Returns:
- parsed result
- Throws:
IOException
-
orDie
throw exception if the response doesn't have 2xx response.- Throws:
Mech2FailException
-
getResponseBodyAsString
Get the HTTP response as String.- Returns:
- string representation of content body
- Throws:
org.apache.http.ParseExceptionIOException
-
getResponseBodyAsByteArray
Get the HTTP response as byte array.- Returns:
- response body as byte array
- Throws:
IOException
-
getStatusCode
public int getStatusCode()Shorthand formech.getResponse().getStatusLine().getStatusCode()- Returns:
- status code.
-
getContentType
public org.apache.http.entity.ContentType getContentType()Get ContentType object from the response.- Returns:
- content type object.
-