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;
}
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);
});
}
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;
}
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);
}
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);
});
}
Aggregations