use of org.webpieces.router.impl.RouteMeta 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.RouteMeta in project webpieces by deanhiller.
the class ResponseProcessor method createRedirect.
private CompletableFuture<Void> createRedirect(RouteId id, Map<String, Object> args, boolean isAjaxRedirect) {
if (responseSent)
throw new IllegalStateException("You already sent a response. do not call Actions.redirect or Actions.render more than once");
responseSent = true;
RouterRequest request = ctx.getRequest();
Method method = matchedMeta.getMethod();
RouteMeta nextRequestMeta = reverseRoutes.get(id);
if (nextRequestMeta == null)
throw new IllegalReturnValueException("Route=" + id + " returned from method='" + method + "' was not added in the RouterModules");
else if (!nextRequestMeta.getRoute().matchesMethod(HttpMethod.GET))
throw new IllegalReturnValueException("method='" + method + "' is trying to redirect to routeid=" + id + " but that route is not a GET method route and must be");
Route route = nextRequestMeta.getRoute();
Map<String, String> keysToValues = reverseTranslator.formMap(method, route.getPathParamNames(), args);
Set<String> keySet = keysToValues.keySet();
List<String> argNames = route.getPathParamNames();
if (keySet.size() != argNames.size()) {
throw new IllegalReturnValueException("Method='" + method + "' returns a Redirect action with wrong number of arguments. args=" + keySet.size() + " when it should be size=" + argNames.size());
}
String path = route.getFullPath();
for (String name : argNames) {
String value = keysToValues.get(name);
if (value == null)
throw new IllegalArgumentException("Method='" + method + "' returns a Redirect that is missing argument key=" + name + " to form the url on the redirect");
path = path.replace("{" + name + "}", value);
}
RedirectResponse redirectResponse = new RedirectResponse(isAjaxRedirect, request.isHttps, request.domain, request.port, path);
return wrapFunctionInContext(() -> responseCb.sendRedirect(redirectResponse));
}
use of org.webpieces.router.impl.RouteMeta in project webpieces by deanhiller.
the class AbstractRouteBuilder method addRoute.
public void addRoute(Route r, RouteId routeId) {
log.info("scope:'" + routerInfo + "' adding route=" + r.getMethod() + " " + r.getFullPath() + " method=" + r.getControllerMethodString());
RouteMeta meta = new RouteMeta(r, holder.getInjector(), currentPackage.get(), holder.getUrlEncoding());
holder.getFinder().loadControllerIntoMetaObject(meta, true);
routes.addRoute(meta);
if (routeId != null)
holder.getReverseRoutes().addRoute(routeId, meta);
else {
holder.getReverseRoutes().addContentRoute(meta);
}
}
use of org.webpieces.router.impl.RouteMeta in project webpieces by deanhiller.
the class R1RouterBuilder method applyFilters.
public void applyFilters(WebAppMeta rm) {
ReverseRoutes reverseRoutes = holder.getReverseRoutes();
Collection<RouteMeta> metas = reverseRoutes.getAllRouteMetas();
for (RouteMeta meta : metas) {
String path = meta.getRoute().getFullPath();
List<FilterInfo<?>> filters = findMatchingFilters(path, meta.getRoute().isHttpsRoute());
meta.setFilters(filters);
}
List<L2DomainRoutes> allDomains = allRouting.getAllDomains();
for (L2DomainRoutes domainRoutes : allDomains) {
applyFilters(domainRoutes, rm);
}
}
use of org.webpieces.router.impl.RouteMeta in project webpieces by deanhiller.
the class AbstractDomainBuilder method setNotFoundRoute.
private void setNotFoundRoute(Route r) {
if (!"".equals(this.routerInfo.getPath()))
throw new UnsupportedOperationException("setNotFoundRoute can only be called on the root Router, not a scoped router");
log.info("scope:'" + routerInfo + "' adding PAGE_NOT_FOUND route=" + r.getFullPath() + " method=" + r.getControllerMethodString());
RouteMeta meta = new RouteMeta(r, holder.getInjector(), currentPackage.get(), holder.getUrlEncoding());
holder.getFinder().loadControllerIntoMetaObject(meta, true);
domainRoutes.setPageNotFoundRoute(meta);
}
Aggregations