void chunk(HttpChunk chunk) throws Exception { Preconditions.checkState( bodyConsumer != null, "Received chunked content without BodyConsumer."); if (chunk.isLast()) { bodyConsumer.finished(responder); bodyConsumer = null; } else { try { bodyConsumer.chunk(chunk.getContent(), responder); } catch (Throwable t) { bodyConsumer.handleError(t); bodyConsumer = null; throw new HandlerException(HttpResponseStatus.INTERNAL_SERVER_ERROR, "", t); } } }
/** Calls the httpHandler method. */ void invoke() throws Exception { if (isStreaming) { // Casting guarantee to be succeeded. bodyConsumer = (BodyConsumer) method.invoke(handler, args); if (requestContent.readable()) { try { bodyConsumer.chunk(requestContent, responder); } catch (Throwable t) { bodyConsumer.handleError(t); bodyConsumer = null; throw new HandlerException(HttpResponseStatus.INTERNAL_SERVER_ERROR, "", t); } } if (!isChunkedRequest) { bodyConsumer.finished(responder); bodyConsumer = null; } } else { // Actually <T> would be void method.invoke(handler, args); bodyConsumer = null; } }