Search in sources :

Example 1 with HttpContentConsumer

use of io.cdap.cdap.api.service.http.HttpContentConsumer in project cdap by caskdata.

the class AbstractHttpHandlerDelegator method wrapContentConsumer.

/**
 * Returns a new instance of {@link BodyConsumer} that wraps around the given {@link HttpContentConsumer}
 * and {@link DelayedHttpServiceResponder}.
 *
 * IMPORTANT: This method will also capture the context associated with the current thread, hence after
 * this method is called, no other methods on this class should be called from the current thread.
 *
 * This method is called from handler class generated by {@link HttpHandlerGenerator}.
 */
@SuppressWarnings("unused")
protected final BodyConsumer wrapContentConsumer(HttpContentConsumer consumer, DelayedHttpServiceResponder responder, TransactionControl defaultTxControl) {
    Preconditions.checkState(!responder.hasBufferedResponse(), "HttpContentConsumer may not be used after a response has already been sent.");
    // Close the provided responder since a new one will be created for the BodyConsumerAdapter to use.
    responder.close();
    ServiceTaskExecutor taskExecutor = context.getServiceTaskExecutor();
    Cancellable contextReleaser = context.capture();
    return new BodyConsumerAdapter(new DelayedHttpServiceResponder(responder, (contentProducer, txServiceContext) -> new BodyProducerAdapter(contentProducer, txServiceContext, contextReleaser, defaultTxControl)), consumer, taskExecutor, contextReleaser, defaultTxControl);
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) BodyConsumer(io.cdap.http.BodyConsumer) HttpResponder(io.cdap.http.HttpResponder) HttpContentConsumer(io.cdap.cdap.api.service.http.HttpContentConsumer) HandlerContext(io.cdap.http.HandlerContext) HttpHandler(io.cdap.http.HttpHandler) MetricsContext(io.cdap.cdap.api.metrics.MetricsContext) HttpContentProducer(io.cdap.cdap.api.service.http.HttpContentProducer) BodyProducer(io.cdap.http.BodyProducer) TransactionControl(io.cdap.cdap.api.annotation.TransactionControl) HttpServiceRequest(io.cdap.cdap.api.service.http.HttpServiceRequest) ThrowingRunnable(io.cdap.cdap.internal.app.runtime.ThrowingRunnable) Preconditions(com.google.common.base.Preconditions) Cancellable(org.apache.twill.common.Cancellable) CombineClassLoader(io.cdap.cdap.common.lang.CombineClassLoader) Cancellable(org.apache.twill.common.Cancellable)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 TransactionControl (io.cdap.cdap.api.annotation.TransactionControl)1 MetricsContext (io.cdap.cdap.api.metrics.MetricsContext)1 HttpContentConsumer (io.cdap.cdap.api.service.http.HttpContentConsumer)1 HttpContentProducer (io.cdap.cdap.api.service.http.HttpContentProducer)1 HttpServiceRequest (io.cdap.cdap.api.service.http.HttpServiceRequest)1 CombineClassLoader (io.cdap.cdap.common.lang.CombineClassLoader)1 ThrowingRunnable (io.cdap.cdap.internal.app.runtime.ThrowingRunnable)1 BodyConsumer (io.cdap.http.BodyConsumer)1 BodyProducer (io.cdap.http.BodyProducer)1 HandlerContext (io.cdap.http.HandlerContext)1 HttpHandler (io.cdap.http.HttpHandler)1 HttpResponder (io.cdap.http.HttpResponder)1 HttpRequest (io.netty.handler.codec.http.HttpRequest)1 Cancellable (org.apache.twill.common.Cancellable)1