-
Notifications
You must be signed in to change notification settings - Fork 403
Description
The DefaultUriResolver uses URI to resolve the resource-path, e.g. for images.
If there is, e.g. a simple img tag with src="logo.png", the image cannot be resolved, if it is provided within a jar (or war) file, although there is no problem when serving directly from file-system (e.g. during development).
This is, because URI does not "understand" the URI-scheme of jar files like this one:
jar:file:/E:/example/target/server-1.0.0.war!/WEB-INF/classes!/export/
So, if this is the baseURI for the DefaultUriResolver and it tries to resolve logo.png against this baseURI, the DefaultUriResolver returns just logo.png and does not append the name to the baseURI.
The problem here is, that a jar-URI has no "path" in terms of an uri, which makes it opaque and therefore nothing can be resolved against the URI.
Since URL understands jar-schemes, a quick fix could be this:
URI possiblyRelative = new URI(uri);
if (possiblyRelative.isAbsolute()) {
return possiblyRelative.toString();
} else {
if(baseUri.startsWith("jar")){
URL base =new URL(baseUri);
URL absolute = new URL(base, uri);
return absolute.toString();
}else {
URI base = new URI(baseUri);
URI absolute = base.resolve(uri);
return absolute.toString();
}
}
we use this in a our own implementation of FSUriResolver, which is working. But may be, you could consider this also for the default implementation.