Search in sources :

Example 1 with MatchResult

use of org.webpieces.router.impl.model.MatchResult in project webpieces by deanhiller.

the class AbstractRouterService method fetchRoute.

protected MatchResult fetchRoute(RequestContext ctx) {
    MatchResult result = routeLoader.fetchRoute(ctx.getRequest());
    ctx.setPathParams(result.getPathParams());
    return result;
}
Also used : MatchResult(org.webpieces.router.impl.model.MatchResult)

Example 2 with MatchResult

use of org.webpieces.router.impl.model.MatchResult 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 MatchResult

use of org.webpieces.router.impl.model.MatchResult in project webpieces by deanhiller.

the class RouteLoader method fetchRoute.

public MatchResult fetchRoute(RouterRequest req) {
    L1AllRouting allRoutingInfo = routerBuilder.getRouterInfo();
    MatchResult meta = allRoutingInfo.fetchRoute(req, req.relativePath);
    if (meta == null)
        throw new IllegalStateException("missing exception on creation if we go this far");
    return meta;
}
Also used : L1AllRouting(org.webpieces.router.impl.model.L1AllRouting) MatchResult(org.webpieces.router.impl.model.MatchResult)

Example 4 with MatchResult

use of org.webpieces.router.impl.model.MatchResult in project webpieces by deanhiller.

the class RouteMeta method matches.

public MatchResult matches(RouterRequest request, String subPath) {
    Matcher matcher = route.matches(request, subPath);
    if (matcher == null)
        return null;
    else if (!matcher.matches())
        return null;
    List<String> names = route.getPathParamNames();
    Map<String, String> namesToValues = new HashMap<>();
    for (String name : names) {
        String value = matcher.group(name);
        if (value == null)
            throw new IllegalArgumentException("Bug, something went wrong. request=" + request);
        //convert special characters back to their normal form like '+' to ' ' (space)
        String decodedVal = urlDecode(value);
        namesToValues.put(name, decodedVal);
    }
    return new MatchResult(this, namesToValues);
}
Also used : Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) MatchResult(org.webpieces.router.impl.model.MatchResult)

Example 5 with MatchResult

use of org.webpieces.router.impl.model.MatchResult 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

MatchResult (org.webpieces.router.impl.model.MatchResult)6 CompletableFuture (java.util.concurrent.CompletableFuture)3 HaveRouteException (org.webpieces.router.impl.loader.HaveRouteException)2 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 RouteMeta (org.webpieces.router.impl.RouteMeta)1 L1AllRouting (org.webpieces.router.impl.model.L1AllRouting)1