use of org.webpieces.router.api.exceptions.RouteNotFoundException in project webpieces by deanhiller.
the class ReverseRoutes method convertToUrl.
public String convertToUrl(String routeId, Map<String, String> args, boolean isValidating) {
RouteMeta routeMeta = get(routeId);
Route route = routeMeta.getRoute();
String urlPath = route.getFullPath();
List<String> pathParamNames = route.getPathParamNames();
for (String param : pathParamNames) {
String val = args.get(param);
if (val == null) {
String strArgs = "";
for (Entry<String, String> entry : args.entrySet()) {
boolean equals = entry.getKey().equals(param);
strArgs = " ARG:'" + entry.getKey() + "'='" + entry.getValue() + "' equals=" + equals + "\n";
}
throw new RouteNotFoundException("missing argument. param=" + param + " is required" + " to exist(and cannot be null as well). route=" + routeId + " args=" + strArgs);
}
String encodedVal = urlEncode(val);
urlPath = urlPath.replace("{" + param + "}", encodedVal);
}
if (isValidating)
return urlPath;
RequestContext ctx = Current.getContext();
RouterRequest request = ctx.getRequest();
if (!route.isHttpsRoute() || request.isHttps)
return urlPath;
//we are rendering an http page with a link to https so need to do special magic
String domain = request.domain;
if (ports == null)
ports = portConfigCallback.fetchPortConfig();
int httpsPort = ports.getHttpsPort();
return "https://" + domain + ":" + httpsPort + urlPath;
}
use of org.webpieces.router.api.exceptions.RouteNotFoundException in project webpieces by deanhiller.
the class WebServerImpl method loopThroughFile.
private void loopThroughFile(URL url, BufferedReader bufReader) throws IOException {
RouteNotFoundException firstException = null;
int count = 1;
String errorMsg = "";
String line;
while ((line = bufReader.readLine()) != null) {
if ("".equals(line.trim()))
continue;
String[] split = line.split("/");
if (split.length != 3)
throw new IllegalStateException("size=" + split.length + " corrupt line=" + line);
String type = split[0];
String location = URLEncoder.decode(split[1], StandardCharsets.UTF_8);
String meta = split[2];
try {
if (ProdTemplateModule.ROUTE_TYPE.equals(type)) {
processRoute(line, location, meta);
} else if (ProdTemplateModule.PATH_TYPE.equals(type)) {
processPath(url, line, location, meta);
} else
throw new IllegalStateException("wrong type. corrupt line=" + line);
} catch (RouteNotFoundException e) {
if (firstException == null)
firstException = e;
errorMsg += "\n\nError " + (count++) + ": " + e.getMessage() + " location=" + location + "\n entire line=" + line;
}
}
if (firstException != null)
throw new RuntimeException("There were one or more invalid routeIds in html files=" + errorMsg, firstException);
}
use of org.webpieces.router.api.exceptions.RouteNotFoundException in project webpieces by deanhiller.
the class WebServerImpl method processPath.
private void processPath(URL url, String line, String location, String urlPath) throws UnsupportedEncodingException {
String path = URLEncoder.decode(urlPath, StandardCharsets.UTF_8);
FileMeta meta = routingService.relativeUrlToHash(path);
if (meta == null)
throw new RouteNotFoundException("backing file for urlPath=" + path + " was not found or route is missing to connect url to path. url=" + url);
}
use of org.webpieces.router.api.exceptions.RouteNotFoundException in project webpieces by deanhiller.
the class ReverseRoutes method getByClassAndName.
private ReversableRouter getByClassAndName(String name) {
if (duplicateClassAndNames.contains(name)) {
Set<RouteId> keySet = routeIdToRoute.keySet();
String routes = "";
for (RouteId id : keySet) {
String potentialName = id.getClass().getSimpleName() + "." + id.name();
if (name.equals(potentialName))
routes += "\nroute=" + id.getClass().getName() + "." + id.name();
}
throw new RouteNotFoundException("There is more than one route matching the class and name. Qualify it with the package like org.web." + name + ". These are the conflicting ids which is why you need to be more specific=" + routes);
}
ReversableRouter routeMeta = classAndNameToRoute.get(name);
if (routeMeta == null)
throw new RouteNotFoundException("route=" + name + " not found");
return routeMeta;
}
use of org.webpieces.router.api.exceptions.RouteNotFoundException in project webpieces by deanhiller.
the class ReverseRoutes method getByName.
private ReversableRouter getByName(String name) {
if (duplicateNames.contains(name)) {
Set<RouteId> keySet = routeIdToRoute.keySet();
String routes = "";
for (RouteId id : keySet) {
if (name.equals(id.name()))
routes += "\nroute=" + id.getClass();
}
throw new RouteNotFoundException("There is more than one route matching the name. Qualify it with the class like XXXRouteId." + name + ". Same names are found in these enum classes=" + routes);
}
ReversableRouter routeMeta = routeNameToRoute.get(name);
if (routeMeta == null)
throw new RouteNotFoundException("route=" + name + " not found.");
return routeMeta;
}
Aggregations