Package me.geso.mech2

Class Mech2Result

java.lang.Object
me.geso.mech2.Mech2Result

public class Mech2Result extends Object
HTTP request result.

It contains HttpRequest object and HttpResponse object.

Author:
tokuhirom
  • 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

      public <T> Mech2JSONResult<T> toJSONResult(Class<T> valueType)
      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

      public <T> Mech2JSONResult<T> toJSONResult(com.fasterxml.jackson.core.type.TypeReference<T> klass)
      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

      public <T> T parseJSON(Class<T> valueType) throws IOException
      Parse JSON from content-body using jackson.
      Parameters:
      valueType - type of json value
      Returns:
      parsed result
      Throws:
      IOException
    • orDie

      public Mech2Result orDie() throws Mech2FailException
      throw exception if the response doesn't have 2xx response.
      Throws:
      Mech2FailException
    • getResponseBodyAsString

      public String getResponseBodyAsString() throws org.apache.http.ParseException, IOException
      Get the HTTP response as String.
      Returns:
      string representation of content body
      Throws:
      org.apache.http.ParseException
      IOException
    • getResponseBodyAsByteArray

      public byte[] getResponseBodyAsByteArray() throws IOException
      Get the HTTP response as byte array.
      Returns:
      response body as byte array
      Throws:
      IOException
    • getStatusCode

      public int getStatusCode()
      Shorthand for mech.getResponse().getStatusLine().getStatusCode()
      Returns:
      status code.
    • getContentType

      public org.apache.http.entity.ContentType getContentType()
      Get ContentType object from the response.
      Returns:
      content type object.