Search in sources :

Example 6 with ResourceManager

use of io.undertow.server.handlers.resource.ResourceManager in project spring-boot by spring-projects.

the class UndertowServletWebServerFactory method getDocumentRootResourceManager.

private ResourceManager getDocumentRootResourceManager() {
    File root = getCanonicalDocumentRoot();
    List<URL> metaInfResourceUrls = getUrlsOfJarsWithMetaInfResources();
    List<URL> resourceJarUrls = new ArrayList<URL>();
    List<ResourceManager> resourceManagers = new ArrayList<ResourceManager>();
    ResourceManager rootResourceManager = root.isDirectory() ? new FileResourceManager(root, 0) : new JarResourceManager(root);
    resourceManagers.add(rootResourceManager);
    for (URL url : metaInfResourceUrls) {
        if ("file".equals(url.getProtocol())) {
            File file = new File(url.getFile());
            if (file.isFile()) {
                try {
                    resourceJarUrls.add(new URL("jar:" + url + "!/"));
                } catch (MalformedURLException ex) {
                    throw new RuntimeException(ex);
                }
            } else {
                resourceManagers.add(new FileResourceManager(new File(file, "META-INF/resources"), 0));
            }
        } else {
            resourceJarUrls.add(url);
        }
    }
    resourceManagers.add(new MetaInfResourcesResourceManager(resourceJarUrls));
    return new CompositeResourceManager(resourceManagers.toArray(new ResourceManager[resourceManagers.size()]));
}
Also used : MalformedURLException(java.net.MalformedURLException) FileResourceManager(io.undertow.server.handlers.resource.FileResourceManager) ArrayList(java.util.ArrayList) ResourceManager(io.undertow.server.handlers.resource.ResourceManager) FileResourceManager(io.undertow.server.handlers.resource.FileResourceManager) File(java.io.File) URL(java.net.URL)

Aggregations

ResourceManager (io.undertow.server.handlers.resource.ResourceManager)6 Resource (io.undertow.server.handlers.resource.Resource)3 IOException (java.io.IOException)3 FileResourceManager (io.undertow.server.handlers.resource.FileResourceManager)2 PathResourceManager (io.undertow.server.handlers.resource.PathResourceManager)2 ServletRequestContext (io.undertow.servlet.handlers.ServletRequestContext)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 VirtualFile (org.jboss.vfs.VirtualFile)2 HandlerWrapper (io.undertow.server.HandlerWrapper)1 HttpHandler (io.undertow.server.HttpHandler)1 PredicatedHandler (io.undertow.server.handlers.builder.PredicatedHandler)1 CachingResourceManager (io.undertow.server.handlers.resource.CachingResourceManager)1 ServletExtension (io.undertow.servlet.ServletExtension)1 AuthMethodConfig (io.undertow.servlet.api.AuthMethodConfig)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 ErrorPage (io.undertow.servlet.api.ErrorPage)1 FilterInfo (io.undertow.servlet.api.FilterInfo)1 HttpMethodSecurityInfo (io.undertow.servlet.api.HttpMethodSecurityInfo)1 ListenerInfo (io.undertow.servlet.api.ListenerInfo)1