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

com.cisco.oss.foundation.logging.transactions.HttpResponse Maven / Gradle / Ivy

package com.cisco.oss.foundation.logging.transactions;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;

public class HttpResponse {

  private String body;
  private int status;
  private Map headers;

  public HttpResponse(Response response) {
    this.body = (String) response.getEntity();
    this.status = response.getStatus();
    this.headers = convertMultiMapHeaders(response.getMetadata());
  }

  public HttpResponse(String body, int status, Map headers) {
    this.body = body;
    this.status = status;
    this.headers = headers;
  }

  private Map convertMultiMapHeaders(MultivaluedMap multivaluedMap) {
    Map headersResult = new HashMap<>();

    for (Entry> item : multivaluedMap.entrySet()) {
      if (item.getValue() != null && item.getValue().get(0) != null) {
        headersResult.put(item.getKey(), (String) item.getValue().get(0) );
      }
    }

    //multivaluedMap.forEach((key, val) -> headersResult.put(key, (String) ((List)val).get(0) ) );

    return headersResult ;
  }

  public String getBody() {
    return body;
  }
  public void setBody(String body) {
    this.body = body;
  }
  public int getStatus() {
    return status;
  }
  public void setStatus(int status) {
    this.status = status;
  }
  public Map getHeaders() {
    return headers;
  }
  public void setHeaders(Map headers) {
    this.headers = headers;
  }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy