コード例 #1
0
  /**
   * Parses the response body and extracts a specific value from it (identified by the provided
   * path)
   */
  public Object evaluate(String path, Stash stash) throws IOException {
    if (response == null) {
      return null;
    }

    if (parsedResponse == null) {
      // special case: api that don't support body (e.g. exists) return true if 200, false if 404,
      // even if no body
      // is_true: '' means the response had no body but the client returned true (caused by 200)
      // is_false: '' means the response had no body but the client returned false (caused by 404)
      if ("".equals(path) && HttpHead.METHOD_NAME.equals(response.getRequestLine().getMethod())) {
        return isError() == false;
      }
      return null;
    }

    return parsedResponse.evaluate(path, stash);
  }
コード例 #2
0
 /**
  * Returns the body properly parsed depending on the content type. Might be a string or a json
  * object parsed as a map.
  */
 public Object getBody() throws IOException {
   if (parsedResponse != null) {
     return parsedResponse.evaluate("");
   }
   return body;
 }