Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
JHttpResponse.java
Go to the documentation of this file.
1 package com.griddynamics.jagger.invoker.v2;
2 
3 import org.springframework.http.HttpHeaders;
4 import org.springframework.http.HttpStatus;
5 
6 import java.io.Serializable;
7 import java.util.Map;
8 
9 import static java.util.stream.Collectors.toMap;
10 
20 public class JHttpResponse<T> implements Serializable {
21 
22  private HttpStatus status;
23  private T body;
24  private HttpHeaders headers;
25 
26  public JHttpResponse(HttpStatus status, T body, HttpHeaders headers) {
27  this.status = status;
28  this.body = body;
29  this.headers = headers;
30  }
31 
32  public HttpStatus getStatus() {
33  return status;
34  }
35 
36  public T getBody() {
37  return body;
38  }
39 
40  public HttpHeaders getHeaders() {
41  return headers;
42  }
43 
44  public Map<String, String> getCookies() {
45  return headers.get("Cookie").stream()
46  .map(cookieStr -> cookieStr.split("="))
47  .collect(toMap(cookieArr -> cookieArr[0], cookieArr -> cookieArr[1]));
48  }
49 
50  public static JHttpResponse copyOf(JHttpResponse jHttpResponse) {
51  if (jHttpResponse == null)
52  return null;
53  return new JHttpResponse(jHttpResponse.getStatus(), jHttpResponse.getBody(), jHttpResponse.getHeaders());
54  }
55 
56  @Override
57  public String toString() {
58  return "JHttpResponse{" +
59  "status=" + status +
60  ", body=" + body +
61  ", headers=" + headers +
62  '}';
63  }
64 }