Esempio n. 1
0
  /**
   * Generate http request entity from Spring Integration message.
   *
   * @param requestMessage
   * @param method
   * @return
   */
  private HttpEntity<?> generateRequest(Message<?> requestMessage, HttpMethod method) {
    HttpHeaders httpHeaders = new HttpHeaders();
    headerMapper.fromHeaders(requestMessage.getHeaders(), httpHeaders);

    Map<String, ?> messageHeaders = requestMessage.getHeaders();
    for (Entry<String, ?> header : messageHeaders.entrySet()) {
      if (!header.getKey().startsWith(CitrusMessageHeaders.PREFIX)
          && !MessageUtils.isSpringInternalHeader(header.getKey())
          && !httpHeaders.containsKey(header.getKey())) {
        httpHeaders.add(header.getKey(), header.getValue().toString());
      }
    }

    Object payload = requestMessage.getPayload();
    if (httpHeaders.getContentType() == null) {
      httpHeaders.setContentType(
          MediaType.parseMediaType(
              contentType.contains("charset") ? contentType : contentType + ";charset=" + charset));
    }

    if (HttpMethod.POST.equals(method) || HttpMethod.PUT.equals(method)) {
      return new HttpEntity<Object>(payload, httpHeaders);
    }

    return new HttpEntity<Object>(httpHeaders);
  }
Esempio n. 2
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. 3
0
  /**
   * Message headers consist of standard HTTP message headers and custom headers. This method
   * assumes that all header entries that were not initially mapped by header mapper implementations
   * are custom headers.
   *
   * @param httpHeaders all message headers in their pre nature.
   * @param mappedHeaders the previously mapped header entries (all standard headers).
   * @return
   */
  private Map<String, String> getCustomHeaders(
      HttpHeaders httpHeaders, Map<String, ?> mappedHeaders) {
    Map<String, String> customHeaders = new HashMap<String, String>();

    for (Entry<String, List<String>> header : httpHeaders.entrySet()) {
      if (!mappedHeaders.containsKey(header.getKey())) {
        customHeaders.put(
            header.getKey(), StringUtils.collectionToCommaDelimitedString(header.getValue()));
      }
    }

    return customHeaders;
  }