@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable t) { Channel ch = ctx.channel(); // Prevent recursion when the client close the connection during a write operation. In that // scenario the sendError will be invoked, but will fail since the channel has already been closed // For an unknown reason, if (ch.attr(ATTACHMENT) != null && Error.class.isAssignableFrom(ch.attr(ATTACHMENT).get().getClass())) { return; } Throwable cause = t.getCause(); if (cause instanceof TooLongFrameException) { sendError(ctx, BAD_REQUEST, null); return; } ch.attr(ATTACHMENT).set(new Error()); if (ch.isOpen()) { sendError(ctx, INTERNAL_SERVER_ERROR, null); } if (ctx.channel().isActive()) { sendError(ctx, INTERNAL_SERVER_ERROR, null); } }
@Override public void sendError(ChannelHandlerContext ctx, HttpResponseStatus status, FullHttpRequest e) { // For websocket, we can't send an error logger.trace("Error {} for {}", status, e); if (websocketChannels.contains(ctx.channel())) { logger.debug("Error {} for {}", status, e); ctx.channel().close().addListener(ChannelFutureListener.CLOSE); } else if (e != null) { if (HttpHeaders.getHeader(e, STATIC_MAPPING, "false").equalsIgnoreCase("false")) { super.sendError(ctx, status, e); } } else { super.sendError(ctx, status, e); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable t) { Channel ch = ctx.channel(); // Prevent recursion when the client close the connection during a write operation. In that // scenario the sendError will be invoked, but will fail since the channel has already been closed // For an unknown reason, if (ch.attr(ATTACHMENT) != null && Error.class.isAssignableFrom(ch.attr(ATTACHMENT).get().getClass())) { return; } Throwable cause = t.getCause(); if (cause instanceof TooLongFrameException) { sendError(ctx, BAD_REQUEST, null); return; } ch.attr(ATTACHMENT).set(new Error()); if (ch.isOpen()) { sendError(ctx, INTERNAL_SERVER_ERROR, null); } if (ctx.channel().isActive()) { sendError(ctx, INTERNAL_SERVER_ERROR, null); } }
@Override public void sendError(ChannelHandlerContext ctx, HttpResponseStatus status, FullHttpRequest e) { // For websocket, we can't send an error logger.trace("Error {} for {}", status, e); if (websocketChannels.contains(ctx.channel())) { logger.debug("Error {} for {}", status, e); ctx.channel().close().addListener(ChannelFutureListener.CLOSE); } else if (e != null) { if (HttpHeaders.getHeader(e, STATIC_MAPPING, "false").equalsIgnoreCase("false")) { super.sendError(ctx, status, e); } } else { super.sendError(ctx, status, e); } }
@Override public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception { if (!request.decoderResult().isSuccess()) { sendError(ctx, BAD_REQUEST, request); return; sendError(ctx, METHOD_NOT_ALLOWED, request); return; break; } catch (FileNotFoundException ignore) { sendError(ctx, NOT_FOUND, request); return; sendError(ctx, NOT_FOUND, request); return;
@Override public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception { if (!request.decoderResult().isSuccess()) { sendError(ctx, BAD_REQUEST, request); return; sendError(ctx, METHOD_NOT_ALLOWED, request); return; break; } catch (FileNotFoundException ignore) { sendError(ctx, NOT_FOUND, request); return; sendError(ctx, NOT_FOUND, request); return;