use of org.webpieces.router.impl.Route in project webpieces by deanhiller.
the class ControllerResolver method resolveControllerClassAndMethod.
//A webapp could override this class entirely to feed back locations of Class's and methods based on the
//Strings passed in from the RouteModules
public ResolvedMethod resolveControllerClassAndMethod(RouteMeta meta) {
Route r = meta.getRoute();
String controllerAndMethod = r.getControllerMethodString();
int index = controllerAndMethod.lastIndexOf(".");
String methodStr = controllerAndMethod.substring(index + 1);
String controllerStr = controllerAndMethod.substring(0, index);
if (countMatches(controllerAndMethod) > 1) {
//If they do absolute class name like
//org.webpieces.Controller.method, then just return it...
ResolvedMethod method = new ResolvedMethod(controllerStr, methodStr);
return method;
}
if (controllerStr.startsWith("/")) {
//absolute reference using /org/webpieces/Controller.method, just replace / with .
controllerStr = controllerStr.replace("/", ".");
controllerStr = controllerStr.substring(1);
} else if (controllerStr.contains("/")) {
//relative reference is annoying but easier for users..(and more concise..
controllerStr = ClassUtil.translate(meta.getPackageContext(), controllerStr);
} else {
//finally for Controllers in the same package as the router, it makes the
//Controller.method really concise...
controllerStr = meta.getPackageContext() + "." + controllerStr;
}
ResolvedMethod method = new ResolvedMethod(controllerStr, methodStr);
return method;
}
use of org.webpieces.router.impl.Route in project webpieces by deanhiller.
the class AbstractRouteBuilder method addContentRoute.
public void addContentRoute(HttpMethod method, String path, String controllerMethod) {
UrlPath p = new UrlPath(routerInfo, path);
Route route = new RouteImpl(method, p, controllerMethod, isHttpsOnlyRoutes);
addRoute(route, null);
}
use of org.webpieces.router.impl.Route 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.Route in project webpieces by deanhiller.
the class AbstractDomainBuilder method setInternalErrorRoute.
@Override
public void setInternalErrorRoute(String controllerMethod) {
Route route = new RouteImpl(controllerMethod, RouteType.INTERNAL_SERVER_ERROR);
setInternalSvrErrorRoute(route);
}
use of org.webpieces.router.impl.Route in project webpieces by deanhiller.
the class AbstractRouteBuilder method addRoute.
@Override
public void addRoute(HttpMethod method, String path, String controllerMethod, RouteId routeId, boolean checkToken) {
UrlPath p = new UrlPath(routerInfo, path);
Route route = new RouteImpl(method, p, controllerMethod, routeId, isHttpsOnlyRoutes, checkToken);
addRoute(route, routeId);
}
Aggregations