All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hubspot.horizon.ning.internal.NingHttpRequestConverter Maven / Gradle / Ivy

There is a newer version: 0.3.1
Show newest version
package com.hubspot.horizon.ning.internal;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hubspot.horizon.Header;
import com.hubspot.horizon.HttpRequest;
import com.ning.http.client.Request;
import com.ning.http.client.RequestBuilder;

public final class NingHttpRequestConverter {
  private final ObjectMapper mapper;

  public NingHttpRequestConverter(ObjectMapper mapper) {
    this.mapper = mapper;
  }

  public Request convert(HttpRequest request) {
    RequestBuilder ningRequest = new RequestBuilder(request.getMethod().name());
    ningRequest.setUrl(request.getUrl().toString());

    byte[] body = request.getBody(mapper);
    if (body != null) {
      ningRequest.setBody(body);
    }

    for (Header header : request.getHeaders()) {
      String name = header.getName();

      if ("Host".equalsIgnoreCase(name)) {
        ningRequest.setVirtualHost(header.getValue());
      } else {
        ningRequest.addHeader(name, header.getValue());
      }
    }

    return ningRequest.build();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy