Search in sources :

Example 1 with HaveRouteException

use of org.webpieces.router.impl.loader.HaveRouteException in project webpieces by deanhiller.

the class AbstractRouterService method processException.

private Void processException(ResponseStreamer responseCb, RequestContext requestCtx, Throwable e) {
    Object meta = "unknown RouteMeta";
    //that decision results in the below mess instead of clean code
    if (e instanceof HaveRouteException) {
        HaveRouteException exc = (HaveRouteException) e;
        meta = exc.getResult().getMeta();
    }
    ErrorRoutes errorRoutes = getErrorRoutes(requestCtx);
    routeLoader.processException(responseCb, requestCtx, e, errorRoutes, meta);
    return null;
}
Also used : HaveRouteException(org.webpieces.router.impl.loader.HaveRouteException)

Example 2 with HaveRouteException

use of org.webpieces.router.impl.loader.HaveRouteException in project webpieces by deanhiller.

the class DevRoutingService method incomingRequestImpl.

@Override
public CompletableFuture<Void> incomingRequestImpl(RequestContext ctx, ResponseStreamer responseCb) {
    //In DevRouter, check if we need to reload the text file as it points to a new RouterModules.java implementation file
    boolean reloaded = reloadIfTextFileChanged();
    if (!reloaded)
        reloadIfClassFilesChanged();
    MatchResult result = fetchRoute(ctx);
    CompletableFuture<Void> future;
    try {
        RouteMeta meta = result.getMeta();
        if (meta.getRoute().getRouteType() == RouteType.STATIC) {
            //RESET the encodings to known so we don't try to go the compressed cache which doesn't
            //exist in dev server since we want the latest files always
            ctx.getRequest().encodings = new ArrayList<>();
        } else if (meta.getControllerInstance() == null) {
            finder.loadControllerIntoMetaObject(meta, false);
            finder.loadFiltersIntoMeta(meta, meta.getFilters(), false);
        }
        future = routeLoader.invokeRoute(result, ctx, responseCb, new DevErrorRoutes(ctx.getRequest()));
    } catch (Throwable e) {
        future = new CompletableFuture<Void>();
        future.completeExceptionally(e);
    }
    return future.exceptionally(t -> {
        throw new HaveRouteException(result, t);
    });
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RouteMeta(org.webpieces.router.impl.RouteMeta) HaveRouteException(org.webpieces.router.impl.loader.HaveRouteException) MatchResult(org.webpieces.router.impl.model.MatchResult)

Example 3 with HaveRouteException

use of org.webpieces.router.impl.loader.HaveRouteException in project webpieces by deanhiller.

the class ProdRouterService method incomingRequestImpl.

@Override
public CompletableFuture<Void> incomingRequestImpl(RequestContext ctx, ResponseStreamer responseCb) {
    MatchResult result = fetchRoute(ctx);
    CompletableFuture<Void> future;
    try {
        ProdErrorRoutes errorRoutes = new ProdErrorRoutes(ctx.getRequest(), routeLoader);
        future = routeLoader.invokeRoute(result, ctx, responseCb, errorRoutes);
    } catch (Throwable e) {
        future = new CompletableFuture<Void>();
        future.completeExceptionally(e);
    }
    return future.exceptionally(t -> {
        throw new HaveRouteException(result, t);
    });
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) HaveRouteException(org.webpieces.router.impl.loader.HaveRouteException) MatchResult(org.webpieces.router.impl.model.MatchResult)

Aggregations

HaveRouteException (org.webpieces.router.impl.loader.HaveRouteException)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 MatchResult (org.webpieces.router.impl.model.MatchResult)2 RouteMeta (org.webpieces.router.impl.RouteMeta)1