Search in sources :

Example 1 with RequestStreamWriter2

use of org.webpieces.router.impl.routeinvoker.RequestStreamWriter2 in project webpieces by deanhiller.

the class RequestResponseStream method openStream.

@Override
public RouterStreamRef openStream(MethodMeta meta, ProxyStreamHandle handle) {
    boolean endOfStream = meta.getCtx().getRequest().originalRequest.isEndOfStream();
    if (endOfStream) {
        // If there is no body, just invoke to process OR IN CASE of InternalError or NotFound, there is NO need
        // to wait for the request body and we can respond early, which stops wasting CPU of reading in their body
        meta.getCtx().getRequest().body = DataWrapperGeneratorFactory.EMPTY;
        XFuture<StreamWriter> invokeSvc = invoker.invokeSvc(meta, i18nBundleName, service, processor, handle).thenApply(voidd -> new NullWriter());
        return new RouterStreamRef("reqRespStreamProxy", invokeSvc, null);
    }
    // At this point, we don't have the end of the stream so return a request writer that calls invoke when complete
    RequestStreamWriter2 writer = new RequestStreamWriter2(requestBodyParsers, meta, (newInfo) -> invoker.invokeSvc(newInfo, i18nBundleName, service, processor, handle));
    XFuture<StreamWriter> w = XFuture.completedFuture(writer);
    return new RouterStreamRef("requestRespStream", w, null);
}
Also used : RequestStreamWriter2(org.webpieces.router.impl.routeinvoker.RequestStreamWriter2) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) NullWriter(org.webpieces.router.impl.routeinvoker.NullWriter) RouterStreamRef(org.webpieces.router.impl.routeinvoker.RouterStreamRef)

Aggregations

StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)1 NullWriter (org.webpieces.router.impl.routeinvoker.NullWriter)1 RequestStreamWriter2 (org.webpieces.router.impl.routeinvoker.RequestStreamWriter2)1 RouterStreamRef (org.webpieces.router.impl.routeinvoker.RouterStreamRef)1