private static void sendError(final ChannelHandlerContext ctx, final HttpResponseStatus status, final String message) {
logger.warn("Invalid request - responding with {} and {}", status, message);
final FullHttpResponse response = new DefaultFullHttpResponse(
HTTP_1_1, status, Unpooled.copiedBuffer("{\"message\": \"" + message + "\"}", CharsetUtil.UTF_8));
response.headers().set(CONTENT_TYPE, "application/json");
// Close the connection as soon as the error message is sent.
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
}
}