private void sendError ( ChannelHandlerContext ctx , HttpResponseStatus status ) { HttpResponse response = new DefaultHttpResponse ( HttpVersion . HTTP_1_1 , status ) ; response . headers ( ) . set ( HttpHeaderNames . CONTENT_TYPE , "text/plain; charset=UTF-8" ) ; ByteBuf content = Unpooled . copiedBuffer ( "Failure: " + status . toString ( ) + "\r\n" , CharsetUtil . UTF_8 ) ; ctx . write ( response ) ; // Close the connection as soon as the error message is sent. ctx . writeAndFlush ( content ) . addListener ( ChannelFutureListener . CLOSE ) ; }
Sends an Error response with status message