|
| 1 | +package com.amazonaws.services.lambda.runtime; |
| 2 | + |
| 3 | +import java.util.HashMap; |
| 4 | +import java.util.Map; |
| 5 | + |
| 6 | +/** |
| 7 | + * Maps the output expected by the Lambda Proxy Integration. |
| 8 | + */ |
| 9 | +public class LambdaProxyOutput { |
| 10 | + private int statusCode = 200; |
| 11 | + |
| 12 | + private Map<String,String> headers = new HashMap<String,String>(); |
| 13 | + |
| 14 | + private String body = ""; |
| 15 | + |
| 16 | + /** |
| 17 | + * Creates an output with status code 200 (OK), |
| 18 | + * no headers and an empty body |
| 19 | + */ |
| 20 | + public LambdaProxyOutput() { |
| 21 | + |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * Creates an output with the provided status |
| 26 | + * code, no headers and an empty body |
| 27 | + * @param statusCode The response status code |
| 28 | + */ |
| 29 | + public LambdaProxyOutput(int statusCode) { |
| 30 | + this.statusCode = statusCode; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Creates an output with the provided parameters |
| 35 | + * @param statusCode The response status code |
| 36 | + * @param headers The headers |
| 37 | + * @param body The response body |
| 38 | + */ |
| 39 | + public LambdaProxyOutput(int statusCode, Map<String,String> headers, String body) { |
| 40 | + this.statusCode = statusCode; |
| 41 | + this.headers = headers; |
| 42 | + this.body = body; |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Gets the response status code |
| 47 | + */ |
| 48 | + public int getStatusCode() { |
| 49 | + return statusCode; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Sets the status code of this response |
| 54 | + * @param statusCode The status code to set |
| 55 | + */ |
| 56 | + public void setStatusCode(int statusCode) { |
| 57 | + this.statusCode = statusCode; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Gets the headers of this response |
| 62 | + */ |
| 63 | + public Map<String, String> getHeaders() { |
| 64 | + return headers; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Sets the headers of this response |
| 69 | + * @param headers The headers to set |
| 70 | + */ |
| 71 | + public void setHeaders(Map<String, String> headers) { |
| 72 | + this.headers = headers; |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Appends a header to this response |
| 77 | + * @param header The header name |
| 78 | + * @param value The header value |
| 79 | + */ |
| 80 | + public void addHeader(String header, String value) { |
| 81 | + this.headers.put(header, value); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Gets the response body |
| 86 | + */ |
| 87 | + public String getBody() { |
| 88 | + return body; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Sets the response body |
| 93 | + * @param body The response body |
| 94 | + */ |
| 95 | + public void setBody(String body) { |
| 96 | + this.body = body; |
| 97 | + } |
| 98 | +} |
0 commit comments