diff --git a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/AttributeNormalizer.java b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/AttributeNormalizer.java index aae4361f6fe..78b18762619 100644 --- a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/AttributeNormalizer.java +++ b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/AttributeNormalizer.java @@ -142,14 +142,19 @@ public class AttributeNormalizer } } + private URI warURI; private List attributes = new ArrayList<>(); public AttributeNormalizer(Resource baseResource) { + // WAR URI is always evaluated before paths. + warURI = baseResource == null ? null : baseResource.getURI(); + // We don't normalize or resolve the baseResource URI + if (!warURI.isAbsolute()) + throw new IllegalArgumentException("WAR URI is not absolute: " + warURI); try { // Track path attributes for expansion - attributes.add(new PathAttribute("WAR", baseResource == null ? null : baseResource.getFile().toPath()).weight(10)); attributes.add(new PathAttribute("jetty.base", "jetty.base").weight(9)); attributes.add(new PathAttribute("jetty.home", "jetty.home").weight(8)); attributes.add(new PathAttribute("user.home", "user.home").weight(7)); @@ -306,7 +311,13 @@ public class AttributeNormalizer private String getString(String property) { - // Use known attributes first + // Use war path (if known) + if("WAR".equalsIgnoreCase(property)) + { + return warURI.toASCIIString(); + } + + // Use known path attributes for (PathAttribute attr : attributes) { if (attr.key.equalsIgnoreCase(property)) diff --git a/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/AttributeNormalizerTest.java b/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/AttributeNormalizerTest.java index e0bec424b7b..e347cd12061 100644 --- a/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/AttributeNormalizerTest.java +++ b/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/AttributeNormalizerTest.java @@ -48,7 +48,8 @@ public class AttributeNormalizerTest public static List data() { String[][] tests = { - { "WAR", toSystemPath("/opt/jetty-distro/demo.base/webapps/root") }, + // Can't test 'WAR' property, as its not a Path (which this testcase works with) + // { "WAR", toSystemPath("http://localhost/resources/webapps/root") }, { "jetty.home", toSystemPath("/opt/jetty-distro") }, { "jetty.base", toSystemPath("/opt/jetty-distro/demo.base") }, { "user.home", toSystemPath("/home/user") },