use of info.xiancloud.nettyhttpserver.http.bean.BadRequestException in project xian by happyyangyuan.
the class DefaultExceptionHandler method exceptionCaught.
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
LOG.error("Exception caught", cause);
HttpResponseStatus status = (cause instanceof BadRequestException) ? BAD_REQUEST : INTERNAL_SERVER_ERROR;
String content = StringUtil.getExceptionStacktrace(cause);
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, status, Unpooled.copiedBuffer(content, CharsetUtil.UTF_8));
response.headers().set(CONTENT_TYPE, Config.getContentType());
response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
/*ctx.writeAndFlush(response); todo 爆了异常之后,这里根本写不进去,直接查日志吧!*/
ctx.close();
LOG.warn("TODO: 16/9/10 目前是出现了异常则直接关闭,这样对长连接稳定性好像不太有利");
MsgIdHolder.clear();
}
use of info.xiancloud.nettyhttpserver.http.bean.BadRequestException in project xian by happyyangyuan.
the class RequestDecoderAux method decode.
@Override
protected void decode(ChannelHandlerContext ctx, FullHttpRequest msg, List<Object> out) throws Exception {
LOG.debug(" httpRequest ----> UnitRequest Pojo");
/*if (!HttpMethod.POST.equals(msg.method())) {
throw new BadRequestException(new IllegalArgumentException("拒绝非POST请求!"));
}*/
DecoderResult result = msg.decoderResult();
if (!result.isSuccess()) {
throw new BadRequestException(result.cause());
}
updateLongConnectionStatus(msg, ctx);
Request request = new Request(msg, MsgIdHolder.get());
offerReqQueue(ctx, request);
out.add(request);
}
Aggregations