Java Code Examples for com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent#setHeaders()
The following examples show how to use
com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent#setHeaders() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FunctionConfiguration.java From blog-tutorials with MIT License | 8 votes |
@Bean public Function<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> processXmlOrder() { return value -> { try { ObjectMapper objectMapper = new XmlMapper(); Order order = objectMapper.readValue(value.getBody(), Order.class); logger.info("Successfully deserialized XML order '{}'", order); // ... processing Order order.setProcessed(true); APIGatewayProxyResponseEvent responseEvent = new APIGatewayProxyResponseEvent(); responseEvent.setStatusCode(201); responseEvent.setHeaders(Map.of("Content-Type", "application/xml")); responseEvent.setBody(objectMapper.writeValueAsString(order)); return responseEvent; } catch (IOException e) { e.printStackTrace(); return new APIGatewayProxyResponseEvent().withStatusCode(500); } }; }
Example 2
Source File: SimpleHttpHandler.java From blog-tutorials with MIT License | 7 votes |
@Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) { System.out.println(input.getBody()); APIGatewayProxyResponseEvent responseEvent = new APIGatewayProxyResponseEvent(); responseEvent.setBody("{\"name\": \"duke\"}"); responseEvent.setStatusCode(200); Map<String, String> headers = new HashMap(); headers.put("X-Custom-Header", "Hello World from Serverless!"); responseEvent.setHeaders(headers); return responseEvent; }
Example 3
Source File: AbstractMicronautLambdaRuntime.java From micronaut-aws with Apache License 2.0 | 5 votes |
/** * * @param status HTTP Status of the response * @param body Body of the response * @param contentType HTTP Header Content-Type value * @return a {@link APIGatewayProxyResponseEvent} populated with the supplied status, body and content type */ protected APIGatewayProxyResponseEvent respond(HttpStatus status, String body, String contentType) { APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent(); Map<String, String> headers = new HashMap<>(); headers.put(HttpHeaders.CONTENT_TYPE, contentType); response.setHeaders(headers); response.setBody(body); response.setStatusCode(status.getCode()); logn(LogLevel.TRACE, "response: " + status.getCode() + " content type: " + headers.get(HttpHeaders.CONTENT_TYPE) + " message " + body); return response; }