Example #1
0
 /**
  * Set a new cookie
  *
  * @param name Cookie name
  * @param value Cookie value
  * @param maxAge Cookie duration (-1 for a transient cookie and 0 for a cookie that expires now)
  * @param path Cookie path
  * @param domain Cookie domain
  * @param secure Whether the cookie is secured (for HTTPS requests)
  * @param httpOnly Whether the cookie is HTTP only (i.e. not accessible from client-side
  *     JavaScript code)
  */
 public void setCookie(
     String name,
     String value,
     int maxAge,
     String path,
     String domain,
     boolean secure,
     boolean httpOnly) {
   cookies.add(new Cookie(name, value, maxAge, path, domain, secure, httpOnly));
 }
  private Object success(Class<?> clazz, HttpInputMessage inputMessage)
      throws JsonParseException, IOException {

    // Note, parsing code used from ektorp project
    JsonParser jp = objectMapper.getJsonFactory().createJsonParser(inputMessage.getBody());
    if (jp.nextToken() != JsonToken.START_OBJECT) {
      throw new RuntimeException("Expected data to start with an Object");
    }
    Map<String, Integer> fields = readHeaderFields(jp);

    List result;
    if (fields.containsKey(TOTAL_ROWS_FIELD_NAME)) {
      int totalRows = fields.get(TOTAL_ROWS_FIELD_NAME);
      if (totalRows == 0) {
        return Collections.emptyList();
      }
      result = new ArrayList(totalRows);
    } else {
      result = new ArrayList();
    }

    ParseState state = new ParseState();

    Object first = parseFirstRow(jp, state, clazz);
    if (first == null) {
      return Collections.emptyList();
    } else {
      result.add(first);
    }

    while (jp.getCurrentToken() != null) {
      skipToField(jp, state.docFieldName, state);
      if (atEndOfRows(jp)) {
        return result;
      }
      result.add(jp.readValueAs(clazz));
      endRow(jp, state);
    }
    return result;
  }