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