Package io.undertow.server.handlers.resource

Examples of io.undertow.server.handlers.resource.Resource


        super(testClass.getClassLoader(), testClass.getPackage().getName().replace(".", "/"));
    }

    @Override
    public Resource getResource(String path) throws IOException {
        final Resource delegate = super.getResource(path);
        if(delegate == null) {
            return delegate;
        }
        return new Resource() {
            @Override
            public String getPath() {
                return delegate.getPath();
            }

            @Override
            public Date getLastModified() {
                return new Date(delegate.getLastModified().getTime() + 20); //file system dates may have a millisecond part, see UNDERTOW-341
            }

            @Override
            public String getLastModifiedString() {
                return delegate.getLastModifiedString();
            }

            @Override
            public ETag getETag() {
                return delegate.getETag();
            }

            @Override
            public String getName() {
                return delegate.getName();
            }

            @Override
            public boolean isDirectory() {
                return delegate.isDirectory();
            }

            @Override
            public List<Resource> list() {
                return delegate.list();
            }

            @Override
            public String getContentType(MimeMappings mimeMappings) {
                return delegate.getContentType(mimeMappings);
            }

            @Override
            public void serve(Sender sender, HttpServerExchange exchange, IoCallback completionCallback) {
                delegate.serve(sender, exchange, completionCallback);
            }

            @Override
            public Long getContentLength() {
                return delegate.getContentLength();
            }

            @Override
            public String getCacheKey() {
                return delegate.getCacheKey();
            }

            @Override
            public File getFile() {
                return delegate.getFile();
            }

            @Override
            public File getResourceManagerRoot() {
                return delegate.getResourceManagerRoot();
            }

            @Override
            public URL getUrl() {
                return delegate.getUrl();
            }
        };
    }
View Full Code Here


            f = new FileOutputStream(file);
            f.write("Hi".getBytes());
        } finally {
            IoUtils.safeClose(f);
        }
        Resource res = fileResourceManager.getResource("1#2.txt");
        InputStream in = null;
        try {
            in = res.getUrl().openStream();
            Assert.assertEquals("Hi", FileUtils.readFile(in));
        } finally {
            IoUtils.safeClose(in);
        }
    }
View Full Code Here

            return match;
        }
        try {

            String remaining = match.getRemaining() == null ? match.getMatched() : match.getRemaining();
            Resource resource = resourceManager.getResource(remaining);
            if (resource == null || !resource.isDirectory()) {
                return match;
            }

            boolean pathEndsWithSlash = remaining.endsWith("/");
            final String pathWithTrailingSlash = pathEndsWithSlash ? remaining : remaining + "/";
View Full Code Here

            return null;
        }
        for (String i : welcomePages) {
            try {
                final String mergedPath = path + i;
                Resource resource = resourceManager.getResource(mergedPath);
                if (resource != null) {
                    final ServletPathMatch handler = data.getServletHandlerByPath(mergedPath);
                    return new ServletPathMatch(handler.getServletChain(), mergedPath, null, requiresRedirect ? REDIRECT : REWRITE, i);
                }
            } catch (IOException e) {
View Full Code Here

        final String path = getPath(req);
        if (!isAllowed(path)) {
            resp.sendError(404);
            return;
        }
        final Resource resource = resourceManager.getResource(path);
        if (resource == null) {
            if (req.getDispatcherType() == DispatcherType.INCLUDE) {
                //servlet 9.3
                throw new FileNotFoundException(path);
            } else {
                resp.sendError(404);
            }
            return;
        } else if (resource.isDirectory()) {
            if ("css".equals(req.getQueryString())) {
                resp.setContentType("text/css");
                resp.getWriter().write(DirectoryUtils.Blobs.FILE_CSS);
                return;
            } else if ("js".equals(req.getQueryString())) {
View Full Code Here

        return deployment.getMimeExtensionMappings().get(file.substring(pos + 1));
    }

    @Override
    public Set<String> getResourcePaths(final String path) {
        final Resource resource;
        try {
            resource = deploymentInfo.getResourceManager().getResource(path);
        } catch (IOException e) {
            return null;
        }
        if (resource == null || !resource.isDirectory()) {
            return null;
        }
        final Set<String> resources = new HashSet<String>();
        for (Resource res : resource.list()) {
            File file = res.getFile();
            if (file != null) {
                File base = res.getResourceManagerRoot();
                String filePath = file.getAbsolutePath().substring(base.getAbsolutePath().length());
                filePath = filePath.replace('\\', '/'); //for windows systems
View Full Code Here

    @Override
    public URL getResource(final String path) throws MalformedURLException {
        if (!path.startsWith("/")) {
            throw UndertowServletMessages.MESSAGES.pathMustStartWithSlash(path);
        }
        Resource resource = null;
        try {
            resource = deploymentInfo.getResourceManager().getResource(path);
        } catch (IOException e) {
            return null;
        }
        if (resource == null) {
            return null;
        }
        return resource.getUrl();
    }
View Full Code Here

        return resource.getUrl();
    }

    @Override
    public InputStream getResourceAsStream(final String path) {
        Resource resource = null;
        try {
            resource = deploymentInfo.getResourceManager().getResource(path);
        } catch (IOException e) {
            return null;
        }
        if (resource == null) {
            return null;
        }
        try {
            if (resource.getFile() != null) {
                return new BufferedInputStream(new FileInputStream(resource.getFile()));
            } else {
                return new BufferedInputStream(resource.getUrl().openStream());
            }
        } catch (FileNotFoundException e) {
            //should never happen, as the resource loader should return null in this case
            return null;
        } catch (IOException e) {
View Full Code Here

    @Override
    public String getRealPath(final String path) {
        if (path == null) {
            return null;
        }
        Resource resource = null;
        try {
            resource = deploymentInfo.getResourceManager().getResource(path);
        } catch (IOException e) {
            return null;
        }
        if (resource == null) {
            return null;
        }
        File file = resource.getFile();
        if (file == null) {
            return null;
        }
        return file.getAbsolutePath();
    }
View Full Code Here

        return deployment.getMimeExtensionMappings().get(file.substring(pos + 1));
    }

    @Override
    public Set<String> getResourcePaths(final String path) {
        final Resource resource;
        try {
            resource = deploymentInfo.getResourceManager().getResource(path);
        } catch (IOException e) {
            return null;
        }
        if (resource == null || !resource.isDirectory()) {
            return null;
        }
        final Set<String> resources = new HashSet<String>();
        for (Resource res : resource.list()) {
            File file = res.getFile();
            if (file != null) {
                File base = res.getResourceManagerRoot();
                String filePath = file.getAbsolutePath().substring(base.getAbsolutePath().length());
                filePath = filePath.replace('\\', '/'); //for windows systems
View Full Code Here

TOP

Related Classes of io.undertow.server.handlers.resource.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.