List<ResourceManager> managers = new ArrayList<>(); ResourceManager rootManager = (docBase.isDirectory() ? new FileResourceManager(docBase, 0) : new JarResourceManager(docBase)); if (root != null) { rootManager = new LoaderHidingResourceManager(rootManager); managers.add(new FileResourceManager( new File(file, "META-INF/resources"), 0));
@Override public Resource getResource(HttpServerExchange exchange, String path) throws IOException { for (FileResourceManager dir : directories) { Resource resource = dir.getResource(path); if (resource != null) { return resource; } } return null; } }
public Http4K publishFileSystem( String hostName, String urlPath, int port, FileResourceManager man ) { if ( ! man.getBase().isDirectory() ) { throw new RuntimeException("root must be an existing direcory:"+man.getBase().getAbsolutePath()); } Pair<PathHandler, Undertow> server = getServer(port, hostName); server.car().addPrefixPath(urlPath, new ResourceHandler(man )); return this; } public Http4K publishResourcePath( String hostName, String urlPath, int port, DynamicResourceManager man, boolean compress ) {
if ( normalizedPath.startsWith("f5_") ) { lookupCache.clear(); return super.getResource(initialPath); Element element = importShim.shimImports(normalizedPath); if ( element == null ) { return super.getResource(initialPath); return super.getResource(initialPath);
delegates.add(new FileResourceManager(resource.getCanonicalFile(), 1024, true, mergedMetaData.isSymbolicLinkingEnabled(), "/"));
public void addDirectory(File directory) { FileResourceManager p = new FileResourceManager(directory); directories.add(p); }
static ResourceManager loadResourceManagerFor(String location) { final File locationAsFile = new File(location); if ( locationAsFile.exists() ) { final boolean isCaseSensitive = !OS_NAME.contains("win"); return new FileResourceManager(locationAsFile, 100, isCaseSensitive ); } final ClassLoader classLoader = SystemResource.class.getClassLoader(); return new ClassPathResourceManager( classLoader, location ); } }
/** * publishes given file root * @param hostName * @param urlPath - prefixPath (e.g. /myapp/resource) * @param port * @param root - directory to be published */ public Http4K publishFileSystem( String hostName, String urlPath, int port, File root ) { if ( ! root.exists() ) root.mkdirs(); if ( ! root.isDirectory() ) { throw new RuntimeException("root must be an existing direcory:"+root.getAbsolutePath()); } Pair<PathHandler, Undertow> server = getServer(port, hostName); server.car().addPrefixPath(urlPath, new ResourceHandler(new FileResourceManager(root,100))); return this; }
public static HttpHandler resource(String prefix, int cacheTime) { ResourceManager resourceManager = null; if (Env.LOCAL == Env.get()) { String path = Paths.get(AssetsConfig.assetsRoot(), prefix).toString(); log.debug("using local file resource manager {}", path); resourceManager = new FileResourceManager(new File(path), 1024 * 1024); } else { log.debug("using classpath file resource manager"); ResourceManager classPathManager = new ClassPathResourceManager(CustomHandlers.class.getClassLoader(), prefix); resourceManager = new CachingResourceManager(100, 65536, new DirectBufferCache(1024, 10, 10480), classPathManager, cacheTime); } ResourceHandler handler = new ResourceHandler(resourceManager); handler.setCacheTime(cacheTime); return handler; }
final ResourceManager resourceManager = new CachingResourceManager(1000, 1L, null, new FileResourceManager(new File(path), 1 * 1024 * 1024), 250); String[] welcomeFiles = new String[] { "index.html", "index.html", "default.html", "default.htm" }; final List<String> welcomeFileList = new CopyOnWriteArrayList<>(welcomeFiles);
public RoutingHandler get() { RoutingHandler router = new RoutingHandler(); final String assetsPath = serviceConfig.getString("path"); final String assetsDirectoryName = serviceConfig.getString("dir"); final Integer assetsCacheTime = serviceConfig.getInt("cache.time"); final FileResourceManager fileResourceManager = new FileResourceManager(Paths.get(assetsDirectoryName).toFile()); router.add(Methods.GET, assetsPath + "/*", io.undertow.Handlers.rewrite("regex('" + assetsPath + "/(.*)')", "/$1", getClass().getClassLoader(), new ResourceHandler(fileResourceManager).setCachable(TruePredicate.instance()).setCacheTime(assetsCacheTime))); this.registeredEndpoints.add(EndpointInfo.builder() .withConsumes("*/*") .withProduces("*/*") .withPathTemplate(assetsPath) .withControllerName(this.getClass().getSimpleName()) .withMethod(Methods.GET) .build()); return router; } }
ResourceHandler handler = resource(new FileResourceManager(file, 3)) .addWelcomeFiles(welcomeFile) .setDirectoryListingEnabled(false);
new PathHandler(resource(new FileResourceManager( new File(base), Integer .valueOf(transferMinSize))))
FileResourceManager resourceManager = new FileResourceManager(this.resourcePath.toFile(), 1024);
for (String path : getResourcePaths()) { if (new File(path).exists()) resourceManager.add(new FileResourceManager(new File(path), 1024)); try { resourceManager.add(new ClassPathResourceManager(classLoader, path));
FileResourceManager resourceManager = new FileResourceManager(this.swaggerResourcePath.toFile(), 1024);
.setContextPath("/") .setDeploymentName("ServletContainer.war") .setResourceManager(new FileResourceManager(new File(resource.getFile()), 100));
delegates.add(new FileResourceManager(resource.getCanonicalFile(), 1024, true, mergedMetaData.isSymbolicLinkingEnabled(), "/"));
delegates.add(new FileResourceManager(resource.getCanonicalFile(), 1024, true, mergedMetaData.isSymbolicLinkingEnabled(), "/"));