@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { callBodyProducerHandleError(bodyProducer, future.cause()); channel.close(); return; } try { bodyProducer.finished(); } catch (Throwable t) { callBodyProducerHandleError(bodyProducer, t); channel.close(); } } };
@Override public void finished() throws Exception { try { delegate.finished(); } finally { taskExecutor.releaseCallResources(); } }
@Override public void sendContent(HttpResponseStatus status, BodyProducer bodyProducer, HttpHeaders headers) { // Buffer all contents produced by the body producer ByteBuf contentChunks = Unpooled.EMPTY_BUFFER; try { ByteBuf chunk = bodyProducer.nextChunk(); while (chunk.isReadable()) { contentChunks = Unpooled.wrappedBuffer(contentChunks, chunk); chunk = bodyProducer.nextChunk(); } bodyProducer.finished(); final ByteBuf finalContentChunks = contentChunks; response = new AbstractInternalResponse(status.code()) { @Override public InputStream openInputStream() throws IOException { return new ByteBufInputStream(finalContentChunks.duplicate()); } }; } catch (Throwable t) { try { bodyProducer.handleError(t); } catch (Throwable et) { LOG.warn("Exception raised from BodyProducer.handleError() for {}", bodyProducer, et); } } }