@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { Exception e = cause instanceof Exception ? (Exception) cause : new Exception(cause); final String output = JsonUtil.toJsonString(e); ByteBuf content = Unpooled.wrappedBuffer(output.getBytes(Charsets.UTF_8)); final DefaultFullHttpResponse resp = new DefaultFullHttpResponse( HTTP_1_1, INTERNAL_SERVER_ERROR, content); resp.headers().set(CONTENT_TYPE, APPLICATION_JSON_UTF8); if (e instanceof IllegalArgumentException) { resp.setStatus(BAD_REQUEST); } else if (e instanceof FileNotFoundException) { resp.setStatus(NOT_FOUND); } else if (e instanceof IOException) { resp.setStatus(FORBIDDEN); } resp.headers().set(CONTENT_LENGTH, resp.content().readableBytes()); resp.headers().set(CONNECTION, CLOSE); ctx.write(resp).addListener(ChannelFutureListener.CLOSE); }
@Override public void setStatus(HttpResponseStatus status) { response.setStatus(status); }
public void setStatus(HttpResponseStatus status) { m_nettyhttpresp.setStatus(status); }
@Override public void setStatus(int code, String reasonPhrase) { HttpResponseStatus status = new HttpResponseStatus(code, reasonPhrase); m_nettyhttpresp.setStatus(status); }
@Override public void sendError(int arg0, String arg1) throws IOException { HttpResponseStatus status = new HttpResponseStatus(arg0, arg1); m_nettyhttpresp.setStatus(status); }
@Override public void sendError(int arg0) throws IOException { HttpResponseStatus status = new HttpResponseStatus(arg0, null); m_nettyhttpresp.setStatus(status); }
@Override public void setStatus(int code) { HttpResponseStatus status = HttpResponseStatus.valueOf(code); m_nettyhttpresp.setStatus(status); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { Exception e = cause instanceof Exception ? (Exception) cause : new Exception(cause); final String output = JsonUtil.toJsonString(e); ByteBuf content = Unpooled.wrappedBuffer(output.getBytes(Charsets.UTF_8)); final DefaultFullHttpResponse resp = new DefaultFullHttpResponse( HTTP_1_1, INTERNAL_SERVER_ERROR, content); resp.headers().set(CONTENT_TYPE, APPLICATION_JSON_UTF8); if (e instanceof IllegalArgumentException) { resp.setStatus(BAD_REQUEST); } else if (e instanceof FileNotFoundException) { resp.setStatus(NOT_FOUND); } resp.headers().set(CONTENT_LENGTH, resp.content().readableBytes()); resp.headers().set(CONNECTION, CLOSE); ctx.write(resp).addListener(ChannelFutureListener.CLOSE); }