|
| 1 | +package com.amazonaws.services.lambda.runtime.events; |
| 2 | + |
| 3 | +import java.io.Serializable; |
| 4 | +import java.util.Map; |
| 5 | + |
| 6 | +/** |
| 7 | + * Class that represents an APIGatewayProxyResponseEvent object |
| 8 | + */ |
| 9 | +public class APIGatewayProxyResponseEvent implements Serializable, Cloneable { |
| 10 | + |
| 11 | + private static final long serialVersionUID = 2263167344670024172L; |
| 12 | + |
| 13 | + private Integer statusCode; |
| 14 | + |
| 15 | + private Map<String, String> headers; |
| 16 | + |
| 17 | + private String body; |
| 18 | + |
| 19 | + /** |
| 20 | + * default constructor |
| 21 | + */ |
| 22 | + public APIGatewayProxyResponseEvent() {} |
| 23 | + |
| 24 | + /** |
| 25 | + * @return The HTTP status code for the request |
| 26 | + */ |
| 27 | + public Integer getStatusCode() { |
| 28 | + return statusCode; |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * @param statusCode The HTTP status code for the request |
| 33 | + */ |
| 34 | + public void setStatusCode(Integer statusCode) { |
| 35 | + this.statusCode = statusCode; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * @param statusCode The HTTP status code for the request |
| 40 | + * @return APIGatewayProxyResponseEvent object |
| 41 | + */ |
| 42 | + public APIGatewayProxyResponseEvent withStatusCode(Integer statusCode) { |
| 43 | + this.setStatusCode(statusCode); |
| 44 | + return this; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @return The Http headers return in the response |
| 49 | + */ |
| 50 | + public Map<String, String> getHeaders() { |
| 51 | + return headers; |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * @param headers The Http headers return in the response |
| 56 | + */ |
| 57 | + public void setHeaders(Map<String, String> headers) { |
| 58 | + this.headers = headers; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @param headers The Http headers return in the response |
| 63 | + * @return APIGatewayProxyResponseEvent |
| 64 | + */ |
| 65 | + public APIGatewayProxyResponseEvent withHeaders(Map<String, String> headers) { |
| 66 | + this.setHeaders(headers); |
| 67 | + return this; |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @return The response body |
| 72 | + */ |
| 73 | + public String getBody() { |
| 74 | + return body; |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * @param body The response body |
| 79 | + */ |
| 80 | + public void setBody(String body) { |
| 81 | + this.body = body; |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * @param body The response body |
| 86 | + * @return APIGatewayProxyResponseEvent object |
| 87 | + */ |
| 88 | + public APIGatewayProxyResponseEvent withBody(String body) { |
| 89 | + this.setBody(body); |
| 90 | + return this; |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Returns a string representation of this object; useful for testing and debugging. |
| 95 | + * |
| 96 | + * @return A string representation of this object. |
| 97 | + * |
| 98 | + * @see Object#toString() |
| 99 | + */ |
| 100 | + @Override |
| 101 | + public String toString() { |
| 102 | + StringBuilder sb = new StringBuilder(); |
| 103 | + sb.append("{"); |
| 104 | + if (getStatusCode() != null) |
| 105 | + sb.append("statusCode: ").append(getStatusCode()).append(","); |
| 106 | + if (getHeaders() != null) |
| 107 | + sb.append("headers: ").append(getHeaders().toString()).append(","); |
| 108 | + if (getBody() != null) |
| 109 | + sb.append("body: ").append(getBody()); |
| 110 | + sb.append("}"); |
| 111 | + return sb.toString(); |
| 112 | + } |
| 113 | + |
| 114 | + @Override |
| 115 | + public boolean equals(Object obj) { |
| 116 | + if (this == obj) |
| 117 | + return true; |
| 118 | + if (obj == null) |
| 119 | + return false; |
| 120 | + |
| 121 | + if (obj instanceof APIGatewayProxyResponseEvent == false) |
| 122 | + return false; |
| 123 | + APIGatewayProxyResponseEvent other = (APIGatewayProxyResponseEvent) obj; |
| 124 | + if (other.getStatusCode() == null ^ this.getStatusCode() == null) |
| 125 | + return false; |
| 126 | + if (other.getStatusCode() != null && other.getStatusCode().equals(this.getStatusCode()) == false) |
| 127 | + return false; |
| 128 | + if (other.getHeaders() == null ^ this.getHeaders() == null) |
| 129 | + return false; |
| 130 | + if (other.getHeaders() != null && other.getHeaders().equals(this.getHeaders()) == false) |
| 131 | + return false; |
| 132 | + if (other.getBody() == null ^ this.getBody() == null) |
| 133 | + return false; |
| 134 | + if (other.getBody() != null && other.getBody().equals(this.getBody()) == false) |
| 135 | + return false; |
| 136 | + return true; |
| 137 | + } |
| 138 | + |
| 139 | + @Override |
| 140 | + public int hashCode() { |
| 141 | + final int prime = 31; |
| 142 | + int hashCode = 1; |
| 143 | + |
| 144 | + hashCode = prime * hashCode + ((getStatusCode() == null) ? 0 : getStatusCode().hashCode()); |
| 145 | + hashCode = prime * hashCode + ((getHeaders() == null) ? 0 : getHeaders().hashCode()); |
| 146 | + hashCode = prime * hashCode + ((getBody() == null) ? 0 : getBody().hashCode()); |
| 147 | + return hashCode; |
| 148 | + } |
| 149 | + |
| 150 | + @Override |
| 151 | + public APIGatewayProxyResponseEvent clone() { |
| 152 | + try { |
| 153 | + return (APIGatewayProxyResponseEvent) super.clone(); |
| 154 | + } catch (CloneNotSupportedException e) { |
| 155 | + throw new IllegalStateException("Got a CloneNotSupportedException from Object.clone()", e); |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | +} |
0 commit comments