Search in sources :

Example 1 with RouteNotFoundException

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;
}
Also used : RequestContext(org.webpieces.ctx.api.RequestContext) RouteNotFoundException(org.webpieces.router.api.exceptions.RouteNotFoundException) RouterRequest(org.webpieces.ctx.api.RouterRequest)

Example 2 with RouteNotFoundException

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);
}
Also used : RouteNotFoundException(org.webpieces.router.api.exceptions.RouteNotFoundException)

Example 3 with RouteNotFoundException

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);
}
Also used : RouteNotFoundException(org.webpieces.router.api.exceptions.RouteNotFoundException) FileMeta(org.webpieces.router.impl.compression.FileMeta)

Example 4 with RouteNotFoundException

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;
}
Also used : RouteId(org.webpieces.router.api.routes.RouteId) RouteNotFoundException(org.webpieces.router.api.exceptions.RouteNotFoundException)

Example 5 with RouteNotFoundException

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;
}
Also used : RouteId(org.webpieces.router.api.routes.RouteId) RouteNotFoundException(org.webpieces.router.api.exceptions.RouteNotFoundException)

Aggregations

RouteNotFoundException (org.webpieces.router.api.exceptions.RouteNotFoundException)5 RouteId (org.webpieces.router.api.routes.RouteId)2 RequestContext (org.webpieces.ctx.api.RequestContext)1 RouterRequest (org.webpieces.ctx.api.RouterRequest)1 FileMeta (org.webpieces.router.impl.compression.FileMeta)1