/** * Add a route that serves resources from classpath. */ default Route addClasspathResourceRoute(String urlPath, String resourceBasePath) { return addResourceRoute(new ClasspathResourceHandler(urlPath, resourceBasePath)); }
public ClasspathResourceHandler(String urlPath, String resourceBasePath) { super(urlPath); this.resourceBasePath = getNormalizedPath(resourceBasePath); }
@Override public URL getResourceUrl(String resourcePath) { if (!isValidResourcePath(resourceBasePath, resourcePath)) { log.warn("Request for '{}' which is not located in '{}'", resourcePath, resourceBasePath); return null; } String resourceName = getResourceBasePath() + "/" + resourcePath; return this.getClass().getClassLoader().getResource(resourceName); }
default Route addClasspathResourceRoute(String urlPath, Class<?> resourceClass) { return addResourceRoute(new ClasspathResourceHandler(urlPath, resourceClass.getName().replace(".", "/"))); }
protected RouteRegistration addClasspathResourceRoute(String basePath, String classpathDirectory) { resourcePaths.add(StringUtils.removeStart(basePath, "/")); return GET(new ClasspathResourceHandler(basePath, classpathDirectory)); }
protected RouteRegistration addClasspathResourceRoute(String basePath, String classpathDirectory) { resourcePaths.add(StringUtils.removeStart(basePath, "/")); return GET(new ClasspathResourceHandler(basePath, classpathDirectory)); }