Search in sources :

Example 1 with URLResource

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

the class JarResourceManager method getResource.

@Override
public Resource getResource(String path) throws IOException {
    URL url = new URL("jar:" + this.jarPath + "!" + (path.startsWith("/") ? path : "/" + path));
    URLResource resource = new URLResource(url, path);
    if (StringUtils.hasText(path) && !"/".equals(path) && resource.getContentLength() < 0) {
        return null;
    }
    return resource;
}
Also used : URLResource(io.undertow.server.handlers.resource.URLResource) URL(java.net.URL)

Example 2 with URLResource

use of io.undertow.server.handlers.resource.URLResource in project keycloak by keycloak.

the class UndertowDeployerHelper method getResourceManager.

private ResourceManager getResourceManager(final String appServerRoot, final WebArchive archive) throws IOException {
    return new ResourceManager() {

        @Override
        public Resource getResource(String path) throws IOException {
            if (path == null || path.isEmpty()) {
                return null;
            }
            Node node = archive.get(path);
            if (node == null) {
                log.warnf("Application '%s' did not found resource on path %s", archive.getName(), path);
                return null;
            } else {
                URL contextUrl = new URL(appServerRoot);
                URL myResourceUrl = new URL(contextUrl.getProtocol(), contextUrl.getHost(), contextUrl.getPort(), path, new URLStreamHandler() {

                    @Override
                    protected URLConnection openConnection(URL u) throws IOException {
                        return new URLConnection(u) {

                            @Override
                            public void connect() throws IOException {
                            }

                            @Override
                            public InputStream getInputStream() throws IOException {
                                return node.getAsset().openStream();
                            }
                        };
                    }
                });
                return new URLResource(myResourceUrl, myResourceUrl.openConnection(), path);
            }
        }

        @Override
        public boolean isResourceChangeListenerSupported() {
            return false;
        }

        @Override
        public void registerResourceChangeListener(ResourceChangeListener listener) {
            throw UndertowMessages.MESSAGES.resourceChangeListenerNotSupported();
        }

        @Override
        public void removeResourceChangeListener(ResourceChangeListener listener) {
            throw UndertowMessages.MESSAGES.resourceChangeListenerNotSupported();
        }

        @Override
        public void close() throws IOException {
        // TODO: Should close open streams?
        }
    };
}
Also used : URLStreamHandler(java.net.URLStreamHandler) URLResource(io.undertow.server.handlers.resource.URLResource) InputStream(java.io.InputStream) Node(org.jboss.shrinkwrap.api.Node) ResourceChangeListener(io.undertow.server.handlers.resource.ResourceChangeListener) ResourceManager(io.undertow.server.handlers.resource.ResourceManager) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Aggregations

URLResource (io.undertow.server.handlers.resource.URLResource)2 URL (java.net.URL)2 ResourceChangeListener (io.undertow.server.handlers.resource.ResourceChangeListener)1 ResourceManager (io.undertow.server.handlers.resource.ResourceManager)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URLConnection (java.net.URLConnection)1 URLStreamHandler (java.net.URLStreamHandler)1 Node (org.jboss.shrinkwrap.api.Node)1