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;
}
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?
}
};
}
Aggregations