Search in sources :

Example 6 with RequestContext

use of org.webpieces.ctx.api.RequestContext in project webpieces by deanhiller.

the class AbstractRouteInvoker method invokeRealRoute.

protected RouterStreamRef invokeRealRoute(InvokeInfo invokeInfo, StreamService endpoint, RouteData data) {
    if (endpoint == null)
        throw new IllegalStateException("Bug, service should never be null at this point");
    LoadedController loadedController = invokeInfo.getLoadedController();
    RequestContext requestCtx = invokeInfo.getRequestCtx();
    Messages messages = new Messages(invokeInfo.getI18nBundleName(), "webpieces");
    requestCtx.setMessages(messages);
    MethodMeta methodMeta = new MethodMeta(loadedController, requestCtx, invokeInfo.getRouteType(), data);
    return endpoint.openStream(methodMeta, invokeInfo.getHandler());
}
Also used : MethodMeta(org.webpieces.router.api.routes.MethodMeta) Messages(org.webpieces.ctx.api.Messages) LoadedController(org.webpieces.router.impl.loader.LoadedController) RequestContext(org.webpieces.ctx.api.RequestContext)

Example 7 with RequestContext

use of org.webpieces.ctx.api.RequestContext in project webpieces by deanhiller.

the class EScopedRouter method invokeRouter.

private RouterStreamRef invokeRouter(AbstractRouter router, RequestContext ctx, ProxyStreamHandle handler, boolean isCorsRequest) {
    RouterStreamRef streamRef = invokeWithProtection(router, ctx, handler, isCorsRequest);
    XFuture<StreamWriter> writer = streamRef.getWriter().handle((r, t) -> {
        if (t == null)
            return XFuture.completedFuture(r);
        XFuture<StreamWriter> fut = new XFuture<>();
        Throwable exc = convert(router.getMatchInfo(), t);
        fut.completeExceptionally(exc);
        return fut;
    }).thenCompose(Function.identity());
    return new RouterStreamRef("eScoped2", writer, streamRef);
}
Also used : ProcessCors(org.webpieces.router.api.routebldr.ProcessCors) SneakyThrow(org.webpieces.util.exceptions.SneakyThrow) LoggerFactory(org.slf4j.LoggerFactory) RouterHeader(org.webpieces.ctx.api.RouterHeader) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Function(java.util.function.Function) ArrayList(java.util.ArrayList) NotFoundException(org.webpieces.http.exception.NotFoundException) Strings(com.google.common.base.Strings) RouterRequest(org.webpieces.ctx.api.RouterRequest) RequestContext(org.webpieces.ctx.api.RequestContext) Map(java.util.Map) RouterInfo(org.webpieces.router.impl.model.RouterInfo) WebpiecesException(org.webpieces.util.exceptions.WebpiecesException) Logger(org.slf4j.Logger) RouterFutureUtil(org.webpieces.router.impl.RouterFutureUtil) AccessResult(org.webpieces.router.api.routebldr.AccessResult) SpecificRouterInvokeException(org.webpieces.router.api.exceptions.SpecificRouterInvokeException) TimeUnit(java.util.concurrent.TimeUnit) ProxyStreamHandle(org.webpieces.router.impl.proxyout.ProxyStreamHandle) List(java.util.List) HttpMethod(org.webpieces.ctx.api.HttpMethod) XFuture(org.webpieces.util.futures.XFuture) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) Http2HeaderName(com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName) MatchResult2(org.webpieces.router.impl.model.MatchResult2) RouterStreamRef(org.webpieces.router.impl.routeinvoker.RouterStreamRef) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) XFuture(org.webpieces.util.futures.XFuture) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) RouterStreamRef(org.webpieces.router.impl.routeinvoker.RouterStreamRef)

Example 8 with RequestContext

use of org.webpieces.ctx.api.RequestContext in project webpieces by deanhiller.

the class ServiceInvoker method invokeSvc.

public XFuture<Void> invokeSvc(MethodMeta meta, String i18nBundleName, Endpoint service, Processor processor, ProxyStreamHandle handle) {
    if (processor == null || meta == null || service == null || handle == null)
        throw new IllegalArgumentException("nothing can be null into this metehod");
    handle.initJustBeforeInvoke(reverseRoutes, meta);
    RequestContext requestCtx = meta.getCtx();
    LoadedController loadedController = meta.getLoadedController();
    Messages messages = new Messages(i18nBundleName, "webpieces");
    requestCtx.setMessages(messages);
    XFuture<Action> response = futureUtil.catchBlockWrap(() -> invokeService(service, meta), (t) -> convert(loadedController, t));
    return response.thenCompose(resp -> continueProcessing(handle, meta, resp, processor));
}
Also used : Action(org.webpieces.router.api.controller.actions.Action) Messages(org.webpieces.ctx.api.Messages) LoadedController(org.webpieces.router.impl.loader.LoadedController) RequestContext(org.webpieces.ctx.api.RequestContext)

Example 9 with RequestContext

use of org.webpieces.ctx.api.RequestContext in project webpieces by deanhiller.

the class RouteInvoker method processNotFound.

public CompletableFuture<Void> processNotFound(ResponseStreamer responseCb, RequestContext requestCtx, NotFoundException e, ErrorRoutes errorRoutes, Object meta) {
    NotFoundException exc = (NotFoundException) e;
    NotFoundInfo notFoundInfo = errorRoutes.fetchNotfoundRoute(exc);
    RouteMeta notFoundResult = notFoundInfo.getResult();
    RouterRequest overridenRequest = notFoundInfo.getReq();
    RequestContext overridenCtx = new RequestContext(requestCtx.getValidation(), (FlashSub) requestCtx.getFlash(), requestCtx.getSession(), overridenRequest);
    //http 404...(unless an exception happens in calling this code and that then goes to 500)
    return notFound(notFoundResult, notFoundInfo.getService(), exc, overridenCtx, responseCb);
}
Also used : NotFoundException(org.webpieces.router.api.exceptions.NotFoundException) RequestContext(org.webpieces.ctx.api.RequestContext) RouterRequest(org.webpieces.ctx.api.RouterRequest)

Example 10 with RequestContext

use of org.webpieces.ctx.api.RequestContext in project webpieces by deanhiller.

the class AbstractRouterService method incomingCompleteRequest.

@Override
public final CompletableFuture<Void> incomingCompleteRequest(RouterRequest routerRequest, ResponseStreamer responseCb) {
    try {
        if (!started)
            throw new IllegalStateException("Either start was not called by client or start threw an exception that client ignored and must be fixed");
        ;
        Session session = (Session) cookieTranslator.translateCookieToScope(routerRequest, new SessionImpl(translator));
        FlashSub flash = (FlashSub) cookieTranslator.translateCookieToScope(routerRequest, new FlashImpl(translator));
        Validation validation = (Validation) cookieTranslator.translateCookieToScope(routerRequest, new ValidationImpl(translator));
        RequestContext requestCtx = new RequestContext(validation, flash, session, routerRequest);
        return processRequest(requestCtx, responseCb);
    } catch (BadCookieException e) {
        throw e;
    } catch (Throwable e) {
        log.warn("uncaught exception", e);
        return responseCb.failureRenderingInternalServerErrorPage(e);
    }
}
Also used : Validation(org.webpieces.ctx.api.Validation) BadCookieException(org.webpieces.router.api.exceptions.BadCookieException) SessionImpl(org.webpieces.router.impl.ctx.SessionImpl) FlashImpl(org.webpieces.router.impl.ctx.FlashImpl) RequestContext(org.webpieces.ctx.api.RequestContext) FlashSub(org.webpieces.ctx.api.FlashSub) Session(org.webpieces.ctx.api.Session) ValidationImpl(org.webpieces.router.impl.ctx.ValidationImpl)

Aggregations

RequestContext (org.webpieces.ctx.api.RequestContext)25 RouterRequest (org.webpieces.ctx.api.RouterRequest)8 LoadedController (org.webpieces.router.impl.loader.LoadedController)7 XFuture (org.webpieces.util.futures.XFuture)6 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)5 List (java.util.List)5 ProxyStreamHandle (org.webpieces.router.impl.proxyout.ProxyStreamHandle)5 Method (java.lang.reflect.Method)4 Map (java.util.Map)4 Function (java.util.function.Function)4 NotFoundException (org.webpieces.http.exception.NotFoundException)4 ArrayList (java.util.ArrayList)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 HttpMethod (org.webpieces.ctx.api.HttpMethod)3 RenderResponse (org.webpieces.router.impl.dto.RenderResponse)3 View (org.webpieces.router.impl.dto.View)3 RouterStreamRef (org.webpieces.router.impl.routeinvoker.RouterStreamRef)3 FutureHelper (org.webpieces.util.futures.FutureHelper)3 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)2