public class Mech2Result extends Object
It contains HttpRequest object and HttpResponse object.
| Modifier and Type | Method and Description |
|---|---|
org.apache.http.entity.ContentType |
getContentType()
Get ContentType object from the response.
|
org.apache.http.HttpRequest |
getRequest()
Get HttpRequest object.
|
org.apache.http.HttpResponse |
getResponse()
Get HttpResponse object.
|
String |
getResponseBodyAsString()
Get the HTTP response as String.
|
int |
getStatusCode()
Shorthand for
mech.getResponse().getStatusLine().getStatusCode() |
boolean |
isJSONResponse()
Returns true if Content-Type of response is "application/json".
|
boolean |
isSuccess()
Returns true if the HttResponse has 2xx status code.
|
Mech2Result |
orDie()
throw exception if the response doesn't have 2xx response.
|
<T> T |
parseJSON(Class<T> valueType)
Parse JSON from content-body using jackson.
|
<T> T |
parseJSON(com.fasterxml.jackson.core.type.TypeReference<T> valueType)
Parse JSON from content-body using jackson.
|
<T> Mech2JSONResult<T> |
toJSONResult(Class<T> valueType)
Convert the result to Mech2JSONResult object.
|
<T> Mech2JSONResult<T> |
toJSONResult(com.fasterxml.jackson.core.type.TypeReference<T> klass)
Convert the result to Mech2JSONResult object.
|
public org.apache.http.HttpRequest getRequest()
public org.apache.http.HttpResponse getResponse()
public boolean isSuccess()
public boolean isJSONResponse()
public <T> Mech2JSONResult<T> toJSONResult(Class<T> valueType)
valueType - public <T> Mech2JSONResult<T> toJSONResult(com.fasterxml.jackson.core.type.TypeReference<T> klass)
klass - public <T> T parseJSON(com.fasterxml.jackson.core.type.TypeReference<T> valueType)
throws com.fasterxml.jackson.core.JsonParseException,
com.fasterxml.jackson.databind.JsonMappingException,
IOException
valueType - com.fasterxml.jackson.core.JsonParseExceptioncom.fasterxml.jackson.databind.JsonMappingExceptionIOExceptionpublic <T> T parseJSON(Class<T> valueType) throws com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException, IOException
valueType - com.fasterxml.jackson.core.JsonParseExceptioncom.fasterxml.jackson.databind.JsonMappingExceptionIOExceptionpublic Mech2Result orDie() throws Mech2FailException
Mech2FailExceptionpublic String getResponseBodyAsString() throws org.apache.http.ParseException, IOException
org.apache.http.ParseExceptionIOExceptionpublic int getStatusCode()
mech.getResponse().getStatusLine().getStatusCode()public org.apache.http.entity.ContentType getContentType()
Copyright © 2015. All rights reserved.