Java Code Examples for io.netty.channel.ChannelHandlerContext#fireExceptionCaught()
The following examples show how to use
io.netty.channel.ChannelHandlerContext#fireExceptionCaught() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NettyMessageEncoder.java From postgres-async-driver with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") protected void encode(ChannelHandlerContext ctx, Message msg, ByteBuf out) { Encoder<Message> encoder = (Encoder<Message>) ENCODERS.get(msg.getClass()); buffer.clear(); ByteBuffer msgbuf = buffer; try { while (true) { try { encoder.write(msg, msgbuf, encoding); break; } catch (BufferOverflowException overflow) { // large clob/blob, resize buffer aggressively msgbuf = ByteBuffer.allocate(msgbuf.capacity() * 4); } } msgbuf.flip(); out.writeBytes(msgbuf); } catch (Throwable t) { // broad catch as otherwise the exception is silently dropped ctx.fireExceptionCaught(t); } }
Example 2
Source File: Http2MultiplexCodec.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
private void onHttp2GoAwayFrame(ChannelHandlerContext ctx, final Http2GoAwayFrame goAwayFrame) { try { forEachActiveStream(new Http2FrameStreamVisitor() { @Override public boolean visit(Http2FrameStream stream) { final int streamId = stream.id(); final DefaultHttp2StreamChannel childChannel = ((Http2MultiplexCodecStream) stream).channel; if (streamId > goAwayFrame.lastStreamId() && connection().local().isValidStreamId(streamId)) { childChannel.pipeline().fireUserEventTriggered(goAwayFrame.retainedDuplicate()); } return true; } }); } catch (Http2Exception e) { ctx.fireExceptionCaught(e); ctx.close(); } finally { // We need to ensure we release the goAwayFrame. goAwayFrame.release(); } }
Example 3
Source File: Decoder.java From xio with Apache License 2.0 | 6 votes |
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) { // uuid byte[] uuidBytes = new byte[36]; in.readBytes(uuidBytes); UUID id = UUID.fromString(new String(uuidBytes)); // op byte[] opBytes = new byte[4]; in.readBytes(opBytes); Message.Op op = Message.Op.fromBytes(opBytes); // payloadSize byte[] payloadSizeBytes = new byte[4]; in.readBytes(payloadSizeBytes); int payloadSize = Ints.fromByteArray(payloadSizeBytes); if (in.readableBytes() < payloadSize) { ctx.fireExceptionCaught(new DecoderException("Not enough bytes available to decode payload")); } out.add(in.readRetainedSlice(payloadSize)); out.add(new Message(id, op)); }
Example 4
Source File: ServerBootstrap.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { final ChannelConfig config = ctx.channel().config(); if (config.isAutoRead()) { // stop accept new connections for 1 second to allow the channel to recover // See https://github.com/netty/netty/issues/1328 config.setAutoRead(false); ctx.channel().eventLoop().schedule(enableAutoReadTask, 1, TimeUnit.SECONDS); } // still let the exceptionCaught event flow through the pipeline to give the user // a chance to do something with it ctx.fireExceptionCaught(cause); }
Example 5
Source File: HttpClientMetricsHandler.java From reactor-netty with Apache License 2.0 | 5 votes |
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { recorder.incrementErrorsCount(ctx.channel().remoteAddress(), path != null ? path : resolveUri(ctx)); ctx.fireExceptionCaught(cause); }
Example 6
Source File: SslBridgeHandler.java From r2dbc-mysql with Apache License 2.0 | 5 votes |
private void handleSslState(ChannelHandlerContext ctx, SslState state) { switch (state) { case BRIDGING: logger.debug("SSL event triggered, enable SSL handler to pipeline"); MySqlSslConfiguration ssl = this.ssl; this.ssl = null; if (ssl == null) { ctx.fireExceptionCaught(new IllegalStateException("The SSL bridge has used, cannot build SSL handler twice")); return; } SslProvider sslProvider = buildProvider(ssl, context.getServerVersion()); SslHandler sslHandler = sslProvider.getSslContext().newHandler(ctx.alloc()); this.sslEngine = sslHandler.engine(); ctx.pipeline().addBefore(NAME, SSL_NAME, sslHandler); break; case UNSUPPORTED: // Remove self because it is useless. (kick down the ladder!) logger.debug("Server unsupported SSL, remove SSL bridge in pipeline"); ctx.pipeline().remove(NAME); break; } // Ignore another custom SSL states because they are useless. }
Example 7
Source File: ProxyHandler.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public final void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (finished) { ctx.fireExceptionCaught(cause); } else { // Exception was raised before the connection attempt is finished. setConnectFailure(cause); } }
Example 8
Source File: SpdySessionHandler.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof SpdyProtocolException) { issueSessionError(ctx, SpdySessionStatus.PROTOCOL_ERROR); } ctx.fireExceptionCaught(cause); }
Example 9
Source File: TftpExceptionHandler.java From tftp4j with Apache License 2.0 | 5 votes |
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { try { ctx.fireChannelActive(); } catch (Throwable t) { ctx.fireExceptionCaught(t); } }
Example 10
Source File: NettyHttpClientHandler.java From ari4java with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { this.exception = cause; if (!(cause instanceof ReadTimeoutException)) { logger.error("Not a read timeout", cause); } ctx.fireExceptionCaught(cause); ctx.close(); }
Example 11
Source File: LoggingHandler.java From netty.book.kor with MIT License | 5 votes |
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (logger.isEnabled(internalLevel)) { logger.log(internalLevel, format(ctx, "EXCEPTION", cause), cause); } ctx.fireExceptionCaught(cause); }
Example 12
Source File: NettyCodecAdapter.java From dubbo3 with Apache License 2.0 | 4 votes |
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { ctx.fireExceptionCaught(cause); }
Example 13
Source File: ExceptionHandler.java From iot-dc with Apache License 2.0 | 4 votes |
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { LOGGER.error("Error: ", cause); ctx.channel().close(); ctx.fireExceptionCaught(cause); }
Example 14
Source File: NettyCodecAdapter.java From dubbo-remoting-netty4 with Apache License 2.0 | 4 votes |
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { ctx.fireExceptionCaught(cause); }
Example 15
Source File: ExceptionHandler.java From iot-dc with Apache License 2.0 | 4 votes |
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { LOGGER.error("Error: ", cause); ctx.channel().close(); ctx.fireExceptionCaught(cause); }
Example 16
Source File: LoginAuthReqHandler.java From netty-custom-protocol with MIT License | 4 votes |
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { ctx.fireExceptionCaught(cause); }
Example 17
Source File: Http2ToHttpInboundAdapter.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private void onRstStreamRead(Http2ResetFrame resetFrame, ChannelHandlerContext ctx) throws Http2Exception { ctx.fireExceptionCaught(new Http2ResetException(resetFrame.errorCode())); }
Example 18
Source File: HandlerSubscriber.java From netty-reactive-streams with Apache License 2.0 | 4 votes |
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { cancel(); ctx.fireExceptionCaught(cause); }
Example 19
Source File: ClientCodec.java From xio with Apache License 2.0 | 4 votes |
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof Message) { Message message = (Message) msg; if (currentPayload == null) { log.error("No response payload received for request id '{}': {}", message.getId(), message); ctx.fireExceptionCaught( new RuntimeException( "No response payload received for request id '" + message.getId() + "'")); reset(); return; } if (error) { log.error( "Multiple response payloads received for request id '{}': {}", message.getId(), message); ctx.fireExceptionCaught( new RuntimeException( "Multiple response payloads received for request id '" + message.getId() + "'")); reset(); return; } Request request = getRequest(getMapping(ctx.channel()), message); if (request == null) { log.error("Unexpected response received for request id '{}': {}", message.getId(), message); ctx.fireExceptionCaught( new RuntimeException( "Unexpected response received for request id '" + message.getId() + "'")); reset(); return; } Response response = new Response(message.getId(), currentPayload); request.getResponsePromise().set(response); reset(); } else { if (currentPayload != null) { error = true; return; } currentPayload = msg; } }
Example 20
Source File: MessageAggregator.java From netty-4.1.22 with Apache License 2.0 | 2 votes |
/** * Invoked when an incoming request exceeds the maximum content length. The default behvaior is to trigger an * {@code exceptionCaught()} event with a {@link TooLongFrameException}.当传入请求超过最大内容长度时调用。默认的behvaior用一个TooLongFrameException触发一个exceptionCaught()事件。 * * @param ctx the {@link ChannelHandlerContext} * @param oversized the accumulated message up to this point, whose type is {@code S} or {@code O} */ protected void handleOversizedMessage(ChannelHandlerContext ctx, S oversized) throws Exception { ctx.fireExceptionCaught( new TooLongFrameException("content length exceeded " + maxContentLength() + " bytes.")); }