in src/main/java/com/amazonaws/handler/GetOrderHandler.java [51:89]
public void handleRequest(InputStream input, OutputStream output,
Context context) throws IOException {
final JsonNode event;
try {
event = objectMapper.readTree(input);
} catch (JsonMappingException e) {
writeInvalidJsonInStreamResponse(objectMapper, output, e.getMessage());
return;
}
if (event == null) {
writeInvalidJsonInStreamResponse(objectMapper, output, "event was null");
return;
}
final JsonNode pathParameterMap = event.findValue("pathParameters");
final String orderId = Optional.ofNullable(pathParameterMap)
.map(mapNode -> mapNode.get("order_id"))
.map(JsonNode::asText)
.orElse(null);
if (isNullOrEmpty(orderId)) {
objectMapper.writeValue(output,
new GatewayResponse<>(
objectMapper.writeValueAsString(ORDER_ID_WAS_NOT_SET),
APPLICATION_JSON, SC_BAD_REQUEST));
return;
}
try {
Order order = orderDao.getOrder(orderId);
objectMapper.writeValue(output,
new GatewayResponse<>(
objectMapper.writeValueAsString(order),
APPLICATION_JSON, SC_OK));
} catch (OrderDoesNotExistException e) {
objectMapper.writeValue(output,
new GatewayResponse<>(
objectMapper.writeValueAsString(
new ErrorMessage(e.getMessage(), SC_NOT_FOUND)),
APPLICATION_JSON, SC_NOT_FOUND));
}
}