List of usage examples for io.netty.channel ChannelHandlerContext fireExceptionCaught
@Override ChannelHandlerContext fireExceptionCaught(Throwable cause);
From source file:com.basho.riak.client.core.netty.RiakSecurityDecoder.java
License:Apache License
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause.getCause() instanceof javax.net.ssl.SSLHandshakeException) { // consume } else {//from ww w . j a va2s . c o m ctx.fireExceptionCaught(cause); } }
From source file:com.book.netty5.client.HeartBeatReqHandler.java
License:Apache License
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { cause.printStackTrace();//w w w . j av a 2 s .c o m if (heartBeat != null) { heartBeat.cancel(true); heartBeat = null; } ctx.fireExceptionCaught(cause); }
From source file:com.cc.nettytest.proxy.decoder.CCLengthFieldBasedFrameDecoder.java
License:Apache License
private void fail(ChannelHandlerContext ctx, long frameLength) { if (frameLength > 0) { ctx.fireExceptionCaught(new TooLongFrameException( "Adjusted frame length exceeds " + maxFrameLength + ": " + frameLength + " - discarded")); } else {//from www .j av a2 s . co m ctx.fireExceptionCaught( new TooLongFrameException("Adjusted frame length exceeds " + maxFrameLength + " - discarding")); } }
From source file:com.cloudera.livy.client.local.rpc.SaslHandler.java
License:Apache License
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { if (!isComplete()) { LOG.info("Exception in SASL negotiation.", cause); onError(cause);/*from w ww . j ava2 s. c o m*/ ctx.close(); } ctx.fireExceptionCaught(cause); }
From source file:com.couchbase.client.core.endpoint.AbstractGenericHandler.java
License:Apache License
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof IOException) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(logIdent(ctx, endpoint) + "Connection reset by peer: " + cause.getMessage(), cause); } else {//from w w w . j a v a 2s. com LOGGER.info(logIdent(ctx, endpoint) + "Connection reset by peer: " + cause.getMessage()); } handleOutstandingOperations(ctx); } else if (cause instanceof DecoderException && cause.getCause() instanceof SSLHandshakeException) { if (!connectFuture.isDone()) { connectFuture.setFailure(cause.getCause()); } else { // This should not be possible, since handshake is done before connecting. But just in case, we // can trap and log an error that might slip through for one reason or another. LOGGER.warn(logIdent(ctx, endpoint) + "Caught SSL exception after being connected: " + cause.getMessage(), cause); } } else { LOGGER.warn(logIdent(ctx, endpoint) + "Caught unknown exception: " + cause.getMessage(), cause); ctx.fireExceptionCaught(cause); } }
From source file:com.ebay.jetstream.messaging.transport.netty.autoflush.handler.NettyAutoFlushBatcher.java
License:MIT License
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (!ctx.channel().isActive()) { ReferenceCountUtil.release(msg); // we might get here as channel is closed but upstream has not been notified yet. It could be still sending us events. // in such a case we will inform the future and send an exception upstream Throwable cause = new Exception("passed channel not active - " + ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().getHostAddress()); promise.setFailure(cause);/*from www. j a va 2s . com*/ ctx.fireExceptionCaught(cause); return; } AutoFlushWriterChannelQueue queue = m_channelQueue.get(ctx.channel()); if (queue == null) { queue = new AutoFlushWriterChannelQueue(m_maxFlushBufferSz.get()); queue.setChannelHandlerContext(ctx); m_channelQueue.put(ctx.channel(), queue); } MessageEvent e = new MessageEvent(msg, promise); queue.add(e); if (queue.isTimeToFlush()) { flush(ctx, queue); } }
From source file:com.eucalyptus.ws.handlers.IoWsSecHandler.java
License:Open Source License
@Override public void write(final io.netty.channel.ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) throws Exception { final Object o = msg; if (o instanceof IoMessage) { try {/*from w w w.ja v a 2 s . c om*/ final IoMessage ioMessage = (IoMessage) o; OMElement elem = null; Document doc = null; SOAPEnvelope env = ioMessage.getSoapEnvelope(); HoldMe.canHas.lock(); try { final StAXOMBuilder doomBuilder = HoldMe.getStAXOMBuilder(HoldMe.getDOOMFactory(), env.getXMLStreamReader()); elem = doomBuilder.getDocumentElement(); elem.build(); doc = ((Element) elem).getOwnerDocument(); } finally { HoldMe.canHas.unlock(); } final List<WSEncryptionPart> partsToSign = Lists.newArrayList(); final WSSecHeader wsheader = new WSSecHeader("", false); try { wsheader.insertSecurityHeader(doc); } catch (WSSecurityException e) { LOG.error(e, e); ctx.fireExceptionCaught(e); } final WSSecSignature signer = new WSSecSignature(); final WSSConfig config = WSSConfig.getNewInstance(); config.setWsiBSPCompliant(false); signer.setWsConfig(config); signer.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE); signer.setSigCanonicalization(WSConstants.C14N_EXCL_OMIT_COMMENTS); try { signer.prepare(doc, this.credentialLookup.apply(ctx), wsheader); } catch (WSSecurityException e) { LOG.error(doc); LOG.error(e, e); ctx.fireExceptionCaught(e); } if (this.shouldTimeStamp()) { final WSSecTimestamp ts = new WSSecTimestamp(); ts.setTimeToLive(300); ts.prepare(doc); ts.prependToHeader(wsheader); } partsToSign.addAll(this.getSignatureParts()); signer.appendBSTElementToHeader(wsheader); List<Reference> references = null; try { references = signer.addReferencesToSign(partsToSign, wsheader); } catch (WSSecurityException e) { LOG.error(doc); LOG.error(e, e); ctx.fireExceptionCaught(e); } try { signer.computeSignature(references, false, null); } catch (WSSecurityException e) { LOG.error(doc); LOG.error(e, e); ctx.fireExceptionCaught(e); } SOAPEnvelope envelope = null; HoldMe.canHas.lock(); try { final StAXSOAPModelBuilder stAXSOAPModelBuilder = new StAXSOAPModelBuilder( elem.getXMLStreamReader(), HoldMe.getOMSOAP11Factory(), null); envelope = stAXSOAPModelBuilder.getSOAPEnvelope(); if (envelope != null) envelope.build(); } finally { HoldMe.canHas.unlock(); } ioMessage.setSoapEnvelope(envelope); } catch (OMException e) { LOG.error(e, e); ctx.fireExceptionCaught(e); } } super.write(ctx, msg, promise); }
From source file:com.facebook.nifty.core.ThriftFrameDecoder.java
License:Apache License
private TTransport tryDecodeFramedMessage(ChannelHandlerContext ctx, ByteBuf buffer) { // Framed messages are prefixed by the size of the frame (which doesn't include the // framing itself). int messageStartReaderIndex = buffer.readerIndex(); // Read the i32 frame contents size int messageContentsLength = buffer.getInt(messageStartReaderIndex); // The full message is larger by the size of the frame size prefix int messageLength = messageContentsLength + MESSAGE_FRAME_SIZE; if (messageContentsLength > maxFrameSize) { ctx.fireExceptionCaught( new TooLongFrameException("Maximum frame size of " + maxFrameSize + " exceeded")); }//from w w w . ja va 2s. c om int messageContentsOffset = messageStartReaderIndex + MESSAGE_FRAME_SIZE; if (messageLength == 0) { // Zero-sized frame: just ignore it and return nothing buffer.readerIndex(messageContentsOffset); return null; } else if (buffer.readableBytes() < messageLength) { // Full message isn't available yet, return nothing for now return null; } else { // Full message is available, return it ByteBuf messageBuffer = extractFrame(buffer, messageContentsOffset, messageContentsLength); ThriftMessage message = new ThriftMessage(messageBuffer, ThriftTransportType.FRAMED); buffer.readerIndex(messageStartReaderIndex + messageLength); return new TNiftyTransport(ctx.channel(), message); } }
From source file:com.facebook.nifty.core.ThriftFrameDecoder.java
License:Apache License
private TTransport tryDecodeUnframedMessage(ChannelHandlerContext ctx, ByteBuf buffer) throws TException { // Perform a trial decode, skipping through // the fields, to see whether we have an entire message available. int messageLength = 0; int messageStartReaderIndex = buffer.readerIndex(); try {/*from w w w . j ava 2s . co m*/ TNiftyTransport decodeAttemptTransport = new TNiftyTransport(ctx.channel(), buffer); TProtocol inputProtocol = this.inputProtocolFactory.getProtocol(decodeAttemptTransport); // Skip through the message inputProtocol.readMessageBegin(); TProtocolUtil.skip(inputProtocol, TType.STRUCT); inputProtocol.readMessageEnd(); messageLength = buffer.readerIndex() - messageStartReaderIndex; } catch (IndexOutOfBoundsException e) { // No complete message was decoded: ran out of bytes return null; } finally { if (buffer.readerIndex() - messageStartReaderIndex > maxFrameSize) { ctx.fireExceptionCaught( new TooLongFrameException("Maximum frame size of " + maxFrameSize + " exceeded")); } buffer.readerIndex(messageStartReaderIndex); } if (messageLength <= 0) { return null; } // We have a full message in the read buffer, slice it off ByteBuf messageBuffer = extractFrame(buffer, messageStartReaderIndex, messageLength); ThriftMessage message = new ThriftMessage(messageBuffer, ThriftTransportType.UNFRAMED); buffer.readerIndex(messageStartReaderIndex + messageLength); return new TNiftyTransport(ctx.channel(), message); }
From source file:com.github.ambry.rest.NettyMessageProcessor.java
License:Open Source License
/** * Netty calls this function when any exception is caught during the functioning of this handler. * <p/>/*from w w w . j a v a 2 s . com*/ * Centralized error handling based on the exception is performed here. Error responses are sent to the client via * the {@link RestResponseChannel} wherever possible. * <p/> * If this function throws an Exception, it is bubbled up to the handler before this one in the Netty pipeline. * @param ctx The {@link ChannelHandlerContext} that can be used to perform operations on the channel. * @param cause The cause of the error. * @throws Exception if there is an {@link Exception} while handling the {@code cause} caught. */ @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { try { nettyMetrics.processorExceptionCaughtCount.inc(); if (cause instanceof RestServiceException) { RestServiceErrorCode errorCode = ((RestServiceException) cause).getErrorCode(); if (ResponseStatus.getResponseStatus(errorCode) == ResponseStatus.BadRequest) { logger.debug("Error on channel {}", ctx.channel(), errorCode, cause); } else { logger.error("Error on channel {}", ctx.channel(), errorCode, cause); } } else { logger.error("Error on channel {}", ctx.channel(), cause); } if (cause instanceof Exception) { onRequestAborted((Exception) cause); } else { ctx.fireExceptionCaught(cause); } } catch (Exception e) { String uri = (request != null) ? request.getUri() : null; nettyMetrics.exceptionCaughtTasksError.inc(); logger.error("Swallowing exception during exceptionCaught tasks on channel {} for request {}", ctx.channel(), uri, e); ctx.close(); } }