Search in sources :

Example 1 with NullWriter

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

the class ENotFoundRouter method invokeNotFoundRoute.

public XFuture<StreamWriter> invokeNotFoundRoute(RequestContext ctx, ProxyStreamHandle handle, NotFoundException exc) {
    Endpoint info = new Endpoint(svc);
    RouteInfoForNotFound data = new RouteInfoForNotFound(exc);
    InvokeInfo invokeInfo = new InvokeInfo(ctx, handle, RouteType.NOT_FOUND, loadedController, i18nBaseBundle);
    return invoker.invokeNotFound(invokeInfo, info, data).thenApply(voidd -> new NullWriter());
}
Also used : InvokeInfo(org.webpieces.router.impl.routeinvoker.InvokeInfo) RouteInfoForNotFound(org.webpieces.router.impl.services.RouteInfoForNotFound) NullWriter(org.webpieces.router.impl.routeinvoker.NullWriter)

Example 2 with NullWriter

use of org.webpieces.router.impl.routeinvoker.NullWriter 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)

Example 3 with NullWriter

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

the class DevRouteInvoker method invokeHtmlController.

@Override
public RouterStreamRef invokeHtmlController(InvokeInfo invokeInfo, StreamService dynamicInfo, RouteData data) {
    // special case for if stuff didn't compile and we flag it
    Throwable exc = (Throwable) invokeInfo.getRequestCtx().getRequest().requestState.get(ERROR_KEY);
    if (exc != null) {
        log.error("Could not compile your code", exc);
        RouteInfoForInternalError error = new RouteInfoForInternalError(exc);
        XFuture<Void> future = invokeDevelopmentErrorPage(invokeInfo, error);
        XFuture<StreamWriter> writer = future.thenApply(voidd -> new NullWriter());
        return new RouterStreamRef("notCompileError", writer, null);
    }
    if (invokeInfo.getRequestCtx().getRequest().queryParams.containsKey(DevelopmentController.INTERNAL_ERROR_KEY)) {
        // need to simulate the error to show production page
        throw new SimulateInternalError();
    }
    // }
    return super.invokeHtmlController(invokeInfo, dynamicInfo, data);
}
Also used : StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) RouteInfoForInternalError(org.webpieces.router.impl.services.RouteInfoForInternalError) SimulateInternalError(org.webpieces.router.impl.routers.SimulateInternalError) NullWriter(org.webpieces.router.impl.routeinvoker.NullWriter) RouterStreamRef(org.webpieces.router.impl.routeinvoker.RouterStreamRef)

Aggregations

NullWriter (org.webpieces.router.impl.routeinvoker.NullWriter)3 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)2 RouterStreamRef (org.webpieces.router.impl.routeinvoker.RouterStreamRef)2 InvokeInfo (org.webpieces.router.impl.routeinvoker.InvokeInfo)1 RequestStreamWriter2 (org.webpieces.router.impl.routeinvoker.RequestStreamWriter2)1 SimulateInternalError (org.webpieces.router.impl.routers.SimulateInternalError)1 RouteInfoForInternalError (org.webpieces.router.impl.services.RouteInfoForInternalError)1 RouteInfoForNotFound (org.webpieces.router.impl.services.RouteInfoForNotFound)1