Esempio n. 1
0
 /**
  * Append Http headers to string builder.
  *
  * @param headers
  * @param builder
  */
 private void appendHeaders(HttpHeaders headers, StringBuilder builder) {
   for (Entry<String, List<String>> headerEntry : headers.entrySet()) {
     builder.append(headerEntry.getKey());
     builder.append(":");
     builder.append(StringUtils.arrayToCommaDelimitedString(headerEntry.getValue().toArray()));
     builder.append(NEWLINE);
   }
 }
Esempio n. 2
0
  /**
   * Builds request content string from request and body.
   *
   * @param request
   * @param body
   * @return
   */
  private String getRequestContent(HttpRequest request, String body) {
    StringBuilder builder = new StringBuilder();

    builder.append(request.getMethod());
    builder.append(" ");
    builder.append(request.getURI());
    builder.append(NEWLINE);

    appendHeaders(request.getHeaders(), builder);

    builder.append(NEWLINE);
    builder.append(body);

    return builder.toString();
  }
Esempio n. 3
0
  /**
   * Builds response content string from response object.
   *
   * @param response
   * @return
   * @throws IOException
   */
  private String getResponseContent(CachingClientHttpResponseWrapper response) throws IOException {
    if (response != null) {
      StringBuilder builder = new StringBuilder();

      builder.append("HTTP/1.1 ");
      builder.append(response.getStatusCode());
      builder.append(" ");
      builder.append(response.getStatusText());
      builder.append(NEWLINE);

      appendHeaders(response.getHeaders(), builder);

      builder.append(NEWLINE);
      builder.append(response.getBodyContent());

      return builder.toString();
    } else {
      return "";
    }
  }