diff --git a/jetty-core/jetty-osgi/src/main/java/org/eclipse/jetty/osgi/OSGiApp.java b/jetty-core/jetty-osgi/src/main/java/org/eclipse/jetty/osgi/OSGiApp.java index 5f2fa1fad017..fb71c6985fd9 100644 --- a/jetty-core/jetty-osgi/src/main/java/org/eclipse/jetty/osgi/OSGiApp.java +++ b/jetty-core/jetty-osgi/src/main/java/org/eclipse/jetty/osgi/OSGiApp.java @@ -29,6 +29,7 @@ import org.eclipse.jetty.server.Deployable; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.StringUtil; +import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceFactory; import org.osgi.framework.Bundle; @@ -80,7 +81,7 @@ private static Resource getBundleAsResource(Bundle bundle) throws Exception File bundleLocation = BundleFileLocatorHelperFactory.getFactory().getHelper().getBundleInstallLocation(bundle); File root = (bundleOverrideLocation == null ? bundleLocation : new File(bundleOverrideLocation)); //Fix some osgiPaths.get( locations which point to an archive, but that doesn't end in .jar - URL url = BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(root.toURI().toURL()); + URL url = BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(URIUtil.correctURI(root.toURI()).toURL()); return ResourceFactory.root().newResource(url); } diff --git a/jetty-core/jetty-osgi/src/main/java/org/eclipse/jetty/osgi/util/Util.java b/jetty-core/jetty-osgi/src/main/java/org/eclipse/jetty/osgi/util/Util.java index 27ea01b2d64a..b97afbddfd2e 100644 --- a/jetty-core/jetty-osgi/src/main/java/org/eclipse/jetty/osgi/util/Util.java +++ b/jetty-core/jetty-osgi/src/main/java/org/eclipse/jetty/osgi/util/Util.java @@ -29,6 +29,7 @@ import org.eclipse.jetty.osgi.OSGiServerConstants; import org.eclipse.jetty.util.StringUtil; +import org.eclipse.jetty.util.URIUtil; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.Filter; @@ -61,7 +62,7 @@ public static URI resolvePathAsLocalizedURI(String path, Bundle bundle, Path jet return null; if (path.startsWith("file:/")) - return new URI(path); + return URIUtil.correctURI(new URI(path)); if (path.startsWith("/") && File.separatorChar != '/') return new URI("file:" + path); diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebInfConfiguration.java b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebInfConfiguration.java index f1ee27e818a1..19e6819cbaf2 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebInfConfiguration.java +++ b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebInfConfiguration.java @@ -204,19 +204,24 @@ public void unpack(WebAppContext context) throws IOException !webApp.isDirectory() ) { - // Look for sibling directory. Path extractedWebAppDir = null; + // If this is a war file, we should look for a sibling + // directory of the same name where it has been already extracted if (war != null) { - Path warPath = context.getResourceFactory().newResource(war).getPath(); - - // look for a sibling like "foo/" to a "foo.war" - if (warPath != null && FileID.isWebArchive(warPath) && Files.exists(warPath)) + // We have obtained the webApp from the war string, so it + // cannot be a CombinedResource, therefore safe to use it's Path + Path warPath = webApp.getPath(); + if (warPath != null) { - Path sibling = warPath.getParent().resolve(FileID.getBasename(warPath)); - if (Files.exists(sibling) && Files.isDirectory(sibling) && Files.isWritable(sibling)) - extractedWebAppDir = sibling; + // look for a sibling like "foo/" to a "foo.war" + if (FileID.isWebArchive(warPath) && Files.exists(warPath)) + { + Path sibling = warPath.getParent().resolve(FileID.getBasename(warPath)); + if (Files.exists(sibling) && Files.isDirectory(sibling) && Files.isWritable(sibling)) + extractedWebAppDir = sibling; + } } } diff --git a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebInfConfiguration.java b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebInfConfiguration.java index ccb0ad828510..8420bdccc002 100644 --- a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebInfConfiguration.java +++ b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebInfConfiguration.java @@ -207,18 +207,24 @@ public void unpack(WebAppContext context) throws IOException !webApp.isDirectory()) ) { - // Look for sibling directory. Path extractedWebAppDir = null; + // If this is a war file, we should look for a sibling + // directory of the same name if (war != null) { - Path warPath = Path.of(war); - // look for a sibling like "foo/" to a "foo.war" - if (FileID.isWebArchive(warPath) && Files.exists(warPath)) + // We have obtained the webApp from the war string, so it + // cannot be a CombinedResource, therefore safe to use it's Path + Path warPath = webApp.getPath(); + if (warPath != null) { - Path sibling = warPath.getParent().resolve(FileID.getBasename(warPath)); - if (Files.exists(sibling) && Files.isDirectory(sibling) && Files.isWritable(sibling)) - extractedWebAppDir = sibling; + // look for a sibling like "foo/" to a "foo.war" + if (FileID.isWebArchive(warPath) && Files.exists(warPath)) + { + Path sibling = warPath.getParent().resolve(FileID.getBasename(warPath)); + if (Files.exists(sibling) && Files.isDirectory(sibling) && Files.isWritable(sibling)) + extractedWebAppDir = sibling; + } } }