diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/JettyWebXmlConfiguration.java b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/JettyWebXmlConfiguration.java
index 1e11793fe678..16c1f6fbce46 100644
--- a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/JettyWebXmlConfiguration.java
+++ b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/JettyWebXmlConfiguration.java
@@ -33,6 +33,7 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
public static final String PROPERTY_WEB_INF = "web-inf";
public static final String XML_CONFIGURATION = "org.eclipse.jetty.webapp.JettyWebXmlConfiguration";
public static final String JETTY_WEB_XML = "jetty-web.xml";
+ public static final String JETTY_EE10_WEB_XML = "jetty-ee10-web.xml";
public JettyWebXmlConfiguration()
{
@@ -53,44 +54,71 @@ public void configure(WebAppContext context) throws Exception
LOG.debug("Configuring web-jetty.xml");
Resource webInf = context.getWebInf();
- // handle any WEB-INF descriptors
- if (webInf != null && webInf.isDirectory())
+ // get the jetty-ee10-web.xml or jetty-web.xml
+ Resource jetty = resolveJettyWebXml(webInf);
+ if (Resources.isReadableFile(jetty))
{
- // Attempt to load ancient jetty8-web.xml file
- Resource jetty = webInf.resolve("jetty8-web.xml");
- if (Resources.missing(jetty))
- jetty = webInf.resolve(JETTY_WEB_XML);
- if (Resources.missing(jetty))
- jetty = webInf.resolve("web-jetty.xml");
-
- if (Resources.isReadableFile(jetty))
- {
- if (LOG.isDebugEnabled())
- LOG.debug("Configure: {}", jetty);
+ if (LOG.isDebugEnabled())
+ LOG.debug("Configure: {}", jetty);
- Object xmlAttr = context.getAttribute(XML_CONFIGURATION);
- context.removeAttribute(XML_CONFIGURATION);
- final XmlConfiguration jetty_config = xmlAttr instanceof XmlConfiguration ? (XmlConfiguration)xmlAttr : new XmlConfiguration(jetty);
+ Object xmlAttr = context.getAttribute(XML_CONFIGURATION);
+ context.removeAttribute(XML_CONFIGURATION);
+ final XmlConfiguration jetty_config = xmlAttr instanceof XmlConfiguration ? (XmlConfiguration)xmlAttr : new XmlConfiguration(jetty);
- setupXmlConfiguration(context, jetty_config, webInf);
+ setupXmlConfiguration(context, jetty_config, webInf);
- try
- {
- WebAppClassLoader.runWithServerClassAccess(() ->
- {
- jetty_config.configure(context);
- return null;
- });
- }
- catch (Exception e)
+ try
+ {
+ WebAppClassLoader.runWithServerClassAccess(() ->
{
- LOG.warn("Error applying {}", jetty);
- throw e;
- }
+ jetty_config.configure(context);
+ return null;
+ });
+ }
+ catch (Exception e)
+ {
+ LOG.warn("Error applying {}", jetty);
+ throw e;
}
}
}
+ /**
+ * Obtain a WEB-INF/jetty-ee9-web.xml, falling back to
+ * looking for WEB-INF/jetty-web.xml.
+ *
+ * @param webInf the WEB-INF of the context to search
+ * @return the file if it exists or null otherwise
+ */
+ private Resource resolveJettyWebXml(Resource webInf)
+ {
+ String xmlFile = JETTY_EE10_WEB_XML;
+ try
+ {
+ if (webInf == null || !webInf.isDirectory())
+ return null;
+
+ //try to find jetty-ee10-web.xml
+ Resource jetty = webInf.resolve(xmlFile);
+ if (!Resources.missing(jetty))
+ return jetty;
+
+ xmlFile = JETTY_WEB_XML;
+ //failing that, look for jetty-web.xml
+ jetty = webInf.resolve(xmlFile);
+ if (!Resources.missing(jetty))
+ return jetty;
+
+ return null;
+ }
+ catch (Exception e)
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("Error resolving WEB-INF/" + xmlFile, e);
+ return null;
+ }
+ }
+
/**
* Configures some well-known properties before the XmlConfiguration reads
* the configuration.
diff --git a/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/JettyWebXmlConfigurationTest.java b/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/JettyWebXmlConfigurationTest.java
new file mode 100644
index 000000000000..7fed285843a4
--- /dev/null
+++ b/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/JettyWebXmlConfigurationTest.java
@@ -0,0 +1,73 @@
+//
+// ========================================================================
+// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
+//
+// This program and the accompanying materials are made available under the
+// terms of the Eclipse Public License v. 2.0 which is available at
+// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
+// which is available at https://www.apache.org/licenses/LICENSE-2.0.
+//
+// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
+// ========================================================================
+//
+
+package org.eclipse.jetty.ee10.webapp;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class JettyWebXmlConfigurationTest
+{
+ Server _server;
+
+ @BeforeEach
+ public void setUp()
+ {
+ _server = new Server();
+ }
+
+ @AfterEach
+ public void tearDown() throws Exception
+ {
+ if (_server != null)
+ _server.stop();
+ }
+
+ @Test
+ public void testWithOnlyJettyWebXml() throws Exception
+ {
+ Path testWebappDir = MavenTestingUtils.getTargetPath("test-classes/webapp-with-jetty-web-xml");
+ assertTrue(Files.exists(testWebappDir));
+
+ WebAppContext context = new WebAppContext();
+ context.setContextPath("/banana");
+ _server.setHandler(context);
+ context.setWar(testWebappDir.toFile().getAbsolutePath());
+ _server.start();
+ assertThat(context.getContextPath(), is("/orange"));
+ }
+
+ @Test
+ public void testWithJettyEEWebXml() throws Exception
+ {
+ Path testWebappDir = MavenTestingUtils.getTargetPath("test-classes/webapp-with-jetty-ee10-web-xml");
+ assertTrue(Files.exists(testWebappDir));
+
+ WebAppContext context = new WebAppContext();
+ context.setContextPath("/banana");
+ _server.setHandler(context);
+ context.setWar(testWebappDir.toFile().getAbsolutePath());
+ _server.start();
+ assertThat(context.getContextPath(), is("/raspberry"));
+ }
+}
diff --git a/jetty-ee10/jetty-ee10-webapp/src/test/resources/webapp-with-jetty-ee10-web-xml/WEB-INF/jetty-ee10-web.xml b/jetty-ee10/jetty-ee10-webapp/src/test/resources/webapp-with-jetty-ee10-web-xml/WEB-INF/jetty-ee10-web.xml
new file mode 100644
index 000000000000..beba698c2c91
--- /dev/null
+++ b/jetty-ee10/jetty-ee10-webapp/src/test/resources/webapp-with-jetty-ee10-web-xml/WEB-INF/jetty-ee10-web.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /raspberry
+
+
diff --git a/jetty-ee10/jetty-ee10-webapp/src/test/resources/webapp-with-jetty-ee10-web-xml/WEB-INF/jetty-web.xml b/jetty-ee10/jetty-ee10-webapp/src/test/resources/webapp-with-jetty-ee10-web-xml/WEB-INF/jetty-web.xml
new file mode 100644
index 000000000000..bc6363a9b73d
--- /dev/null
+++ b/jetty-ee10/jetty-ee10-webapp/src/test/resources/webapp-with-jetty-ee10-web-xml/WEB-INF/jetty-web.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /apple
+
+
diff --git a/jetty-ee10/jetty-ee10-webapp/src/test/resources/webapp-with-jetty-web-xml/WEB-INF/jetty-web.xml b/jetty-ee10/jetty-ee10-webapp/src/test/resources/webapp-with-jetty-web-xml/WEB-INF/jetty-web.xml
new file mode 100644
index 000000000000..c1fd44b483bf
--- /dev/null
+++ b/jetty-ee10/jetty-ee10-webapp/src/test/resources/webapp-with-jetty-web-xml/WEB-INF/jetty-web.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /orange
+
+
diff --git a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/JettyWebXmlConfiguration.java b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/JettyWebXmlConfiguration.java
index 3572650b1613..12b532b49f05 100644
--- a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/JettyWebXmlConfiguration.java
+++ b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/JettyWebXmlConfiguration.java
@@ -33,6 +33,7 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
public static final String PROPERTY_WEB_INF = "web-inf";
public static final String XML_CONFIGURATION = "org.eclipse.jetty.webapp.JettyWebXmlConfiguration";
public static final String JETTY_WEB_XML = "jetty-web.xml";
+ public static final String JETTY_EE11_WEB_XML = "jetty-ee11-web.xml";
public JettyWebXmlConfiguration()
{
@@ -53,44 +54,71 @@ public void configure(WebAppContext context) throws Exception
LOG.debug("Configuring web-jetty.xml");
Resource webInf = context.getWebInf();
- // handle any WEB-INF descriptors
- if (webInf != null && webInf.isDirectory())
+ // get the jetty-ee11-web.xml or jetty-web.xml
+ Resource jetty = resolveJettyWebXml(webInf);
+ if (Resources.isReadableFile(jetty))
{
- // Attempt to load ancient jetty8-web.xml file
- Resource jetty = webInf.resolve("jetty8-web.xml");
- if (Resources.missing(jetty))
- jetty = webInf.resolve(JETTY_WEB_XML);
- if (Resources.missing(jetty))
- jetty = webInf.resolve("web-jetty.xml");
-
- if (Resources.isReadableFile(jetty))
- {
- if (LOG.isDebugEnabled())
- LOG.debug("Configure: {}", jetty);
+ if (LOG.isDebugEnabled())
+ LOG.debug("Configure: {}", jetty);
- Object xmlAttr = context.getAttribute(XML_CONFIGURATION);
- context.removeAttribute(XML_CONFIGURATION);
- final XmlConfiguration jetty_config = xmlAttr instanceof XmlConfiguration ? (XmlConfiguration)xmlAttr : new XmlConfiguration(jetty);
+ Object xmlAttr = context.getAttribute(XML_CONFIGURATION);
+ context.removeAttribute(XML_CONFIGURATION);
+ final XmlConfiguration jetty_config = xmlAttr instanceof XmlConfiguration ? (XmlConfiguration)xmlAttr : new XmlConfiguration(jetty);
- setupXmlConfiguration(context, jetty_config, webInf);
+ setupXmlConfiguration(context, jetty_config, webInf);
- try
- {
- WebAppClassLoader.runWithServerClassAccess(() ->
- {
- jetty_config.configure(context);
- return null;
- });
- }
- catch (Exception e)
+ try
+ {
+ WebAppClassLoader.runWithServerClassAccess(() ->
{
- LOG.warn("Error applying {}", jetty);
- throw e;
- }
+ jetty_config.configure(context);
+ return null;
+ });
+ }
+ catch (Exception e)
+ {
+ LOG.warn("Error applying {}", jetty);
+ throw e;
}
}
}
+ /**
+ * Obtain a WEB-INF/jetty-ee9-web.xml, falling back to
+ * looking for WEB-INF/jetty-web.xml.
+ *
+ * @param webInf the WEB-INF of the context to search
+ * @return the file if it exists or null otherwise
+ */
+ private Resource resolveJettyWebXml(Resource webInf)
+ {
+ String xmlFile = JETTY_EE11_WEB_XML;
+ try
+ {
+ if (webInf == null || !webInf.isDirectory())
+ return null;
+
+ //try to find jetty-ee11-web.xml
+ Resource jetty = webInf.resolve(xmlFile);
+ if (!Resources.missing(jetty))
+ return jetty;
+
+ xmlFile = JETTY_WEB_XML;
+ //failing that, look for jetty-web.xml
+ jetty = webInf.resolve(xmlFile);
+ if (!Resources.missing(jetty))
+ return jetty;
+
+ return null;
+ }
+ catch (Exception e)
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("Error resolving WEB-INF/" + xmlFile, e);
+ return null;
+ }
+ }
+
/**
* Configures some well-known properties before the XmlConfiguration reads
* the configuration.
diff --git a/jetty-ee11/jetty-ee11-webapp/src/test/java/org/eclipse/jetty/ee11/webapp/JettyWebXmlConfigurationTest.java b/jetty-ee11/jetty-ee11-webapp/src/test/java/org/eclipse/jetty/ee11/webapp/JettyWebXmlConfigurationTest.java
new file mode 100644
index 000000000000..578e72a8acf1
--- /dev/null
+++ b/jetty-ee11/jetty-ee11-webapp/src/test/java/org/eclipse/jetty/ee11/webapp/JettyWebXmlConfigurationTest.java
@@ -0,0 +1,73 @@
+//
+// ========================================================================
+// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
+//
+// This program and the accompanying materials are made available under the
+// terms of the Eclipse Public License v. 2.0 which is available at
+// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
+// which is available at https://www.apache.org/licenses/LICENSE-2.0.
+//
+// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
+// ========================================================================
+//
+
+package org.eclipse.jetty.ee11.webapp;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class JettyWebXmlConfigurationTest
+{
+ Server _server;
+
+ @BeforeEach
+ public void setUp()
+ {
+ _server = new Server();
+ }
+
+ @AfterEach
+ public void tearDown() throws Exception
+ {
+ if (_server != null)
+ _server.stop();
+ }
+
+ @Test
+ public void testWithOnlyJettyWebXml() throws Exception
+ {
+ Path testWebappDir = MavenTestingUtils.getTargetPath("test-classes/webapp-with-jetty-web-xml");
+ assertTrue(Files.exists(testWebappDir));
+
+ WebAppContext context = new WebAppContext();
+ context.setContextPath("/banana");
+ _server.setHandler(context);
+ context.setWar(testWebappDir.toFile().getAbsolutePath());
+ _server.start();
+ assertThat(context.getContextPath(), is("/orange"));
+ }
+
+ @Test
+ public void testWithJettyEEWebXml() throws Exception
+ {
+ Path testWebappDir = MavenTestingUtils.getTargetPath("test-classes/webapp-with-jetty-ee11-web-xml");
+ assertTrue(Files.exists(testWebappDir));
+
+ WebAppContext context = new WebAppContext();
+ context.setContextPath("/banana");
+ _server.setHandler(context);
+ context.setWar(testWebappDir.toFile().getAbsolutePath());
+ _server.start();
+ assertThat(context.getContextPath(), is("/raspberry"));
+ }
+}
diff --git a/jetty-ee11/jetty-ee11-webapp/src/test/resources/webapp-with-jetty-ee11-web-xml/WEB-INF/jetty-ee11-web.xml b/jetty-ee11/jetty-ee11-webapp/src/test/resources/webapp-with-jetty-ee11-web-xml/WEB-INF/jetty-ee11-web.xml
new file mode 100644
index 000000000000..ba20dc5a78c9
--- /dev/null
+++ b/jetty-ee11/jetty-ee11-webapp/src/test/resources/webapp-with-jetty-ee11-web-xml/WEB-INF/jetty-ee11-web.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /raspberry
+
+
diff --git a/jetty-ee11/jetty-ee11-webapp/src/test/resources/webapp-with-jetty-ee11-web-xml/WEB-INF/jetty-web.xml b/jetty-ee11/jetty-ee11-webapp/src/test/resources/webapp-with-jetty-ee11-web-xml/WEB-INF/jetty-web.xml
new file mode 100644
index 000000000000..ba00780a686f
--- /dev/null
+++ b/jetty-ee11/jetty-ee11-webapp/src/test/resources/webapp-with-jetty-ee11-web-xml/WEB-INF/jetty-web.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /apple
+
+
diff --git a/jetty-ee11/jetty-ee11-webapp/src/test/resources/webapp-with-jetty-web-xml/WEB-INF/jetty-web.xml b/jetty-ee11/jetty-ee11-webapp/src/test/resources/webapp-with-jetty-web-xml/WEB-INF/jetty-web.xml
new file mode 100644
index 000000000000..cc7494c391c5
--- /dev/null
+++ b/jetty-ee11/jetty-ee11-webapp/src/test/resources/webapp-with-jetty-web-xml/WEB-INF/jetty-web.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /orange
+
+
diff --git a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/JettyWebXmlConfiguration.java b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/JettyWebXmlConfiguration.java
index 1c4728be8a10..e1f1a703b684 100644
--- a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/JettyWebXmlConfiguration.java
+++ b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/JettyWebXmlConfiguration.java
@@ -35,6 +35,7 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
public static final String PROPERTY_WEB_INF = "web-inf";
public static final String XML_CONFIGURATION = "org.eclipse.jetty.ee9.webapp.JettyWebXmlConfiguration";
public static final String JETTY_WEB_XML = "jetty-web.xml";
+ public static final String JETTY_EE_9_WEB_XML = "jetty-ee9-web.xml";
public JettyWebXmlConfiguration()
{
@@ -54,44 +55,71 @@ public void configure(WebAppContext context) throws Exception
LOG.debug("Configuring web-jetty.xml");
Resource webInf = context.getWebInf();
- // handle any WEB-INF descriptors
- if (webInf != null && webInf.isDirectory())
+ // get the jetty-ee9-web.xml or jetty-web.xml
+ Resource jetty = resolveJettyWebXml(webInf);
+ if (Resources.isReadableFile(jetty))
{
- // do jetty.xml file
- Resource jetty = webInf.resolve("jetty8-web.xml");
- if (Resources.missing(jetty))
- jetty = webInf.resolve(JETTY_WEB_XML);
- if (Resources.missing(jetty))
- jetty = webInf.resolve("web-jetty.xml");
-
- if (Resources.isReadableFile(jetty))
- {
- if (LOG.isDebugEnabled())
- LOG.debug("Configure: {}", jetty);
+ if (LOG.isDebugEnabled())
+ LOG.debug("Configure: {}", jetty);
- Object xmlAttr = context.getAttribute(XML_CONFIGURATION);
- context.removeAttribute(XML_CONFIGURATION);
- final XmlConfiguration jetty_config = xmlAttr instanceof XmlConfiguration ? (XmlConfiguration)xmlAttr : new XmlConfiguration(jetty);
+ Object xmlAttr = context.getAttribute(XML_CONFIGURATION);
+ context.removeAttribute(XML_CONFIGURATION);
+ final XmlConfiguration jetty_config = xmlAttr instanceof XmlConfiguration ? (XmlConfiguration)xmlAttr : new XmlConfiguration(jetty);
- setupXmlConfiguration(context, jetty_config, webInf);
+ setupXmlConfiguration(context, jetty_config, webInf);
- try
- {
- WebAppClassLoader.runWithServerClassAccess(() ->
- {
- jetty_config.configure(context);
- return null;
- });
- }
- catch (Exception e)
+ try
+ {
+ WebAppClassLoader.runWithServerClassAccess(() ->
{
- LOG.warn("Error applying {}", jetty);
- throw e;
- }
+ jetty_config.configure(context);
+ return null;
+ });
+ }
+ catch (Exception e)
+ {
+ LOG.warn("Error applying {}", jetty);
+ throw e;
}
}
}
+ /**
+ * Obtain a WEB-INF/jetty-ee9-web.xml, falling back to
+ * looking for WEB-INF/jetty-web.xml.
+ *
+ * @param webInf the WEB-INF of the context to search
+ * @return the file if it exists or null otherwise
+ */
+ private Resource resolveJettyWebXml(Resource webInf)
+ {
+ String xmlFile = JETTY_EE_9_WEB_XML;
+ try
+ {
+ if (webInf == null || !webInf.isDirectory())
+ return null;
+
+ //try to find jetty-ee9-web.xml
+ Resource jetty = webInf.resolve(xmlFile);
+ if (!Resources.missing(jetty))
+ return jetty;
+
+ xmlFile = JETTY_WEB_XML;
+ //failing that, look for jetty-web.xml
+ jetty = webInf.resolve(xmlFile);
+ if (!Resources.missing(jetty))
+ return jetty;
+
+ return null;
+ }
+ catch (Exception e)
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("Error resolving WEB-INF/" + xmlFile, e);
+ return null;
+ }
+ }
+
/**
* Configures some well-known properties before the XmlConfiguration reads
* the configuration.
diff --git a/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/JettyWebXmlConfigurationTest.java b/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/JettyWebXmlConfigurationTest.java
new file mode 100644
index 000000000000..5fcb6fa5c645
--- /dev/null
+++ b/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/JettyWebXmlConfigurationTest.java
@@ -0,0 +1,73 @@
+//
+// ========================================================================
+// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
+//
+// This program and the accompanying materials are made available under the
+// terms of the Eclipse Public License v. 2.0 which is available at
+// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
+// which is available at https://www.apache.org/licenses/LICENSE-2.0.
+//
+// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
+// ========================================================================
+//
+
+package org.eclipse.jetty.ee9.webapp;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class JettyWebXmlConfigurationTest
+{
+ Server _server;
+
+ @BeforeEach
+ public void setUp()
+ {
+ _server = new Server();
+ }
+
+ @AfterEach
+ public void tearDown() throws Exception
+ {
+ if (_server != null)
+ _server.stop();
+ }
+
+ @Test
+ public void testWithOnlyJettyWebXml() throws Exception
+ {
+ Path testWebappDir = MavenTestingUtils.getTargetPath("test-classes/webapp-with-jetty-web-xml");
+ assertTrue(Files.exists(testWebappDir));
+
+ WebAppContext context = new WebAppContext();
+ context.setContextPath("/banana");
+ _server.setHandler(context);
+ context.setWar(testWebappDir.toFile().getAbsolutePath());
+ _server.start();
+ assertThat(context.getContextPath(), is("/orange"));
+ }
+
+ @Test
+ public void testWithJettyEEWebXml() throws Exception
+ {
+ Path testWebappDir = MavenTestingUtils.getTargetPath("test-classes/webapp-with-jetty-ee9-web-xml");
+ assertTrue(Files.exists(testWebappDir));
+
+ WebAppContext context = new WebAppContext();
+ context.setContextPath("/banana");
+ _server.setHandler(context);
+ context.setWar(testWebappDir.toFile().getAbsolutePath());
+ _server.start();
+ assertThat(context.getContextPath(), is("/raspberry"));
+ }
+}
diff --git a/jetty-ee9/jetty-ee9-webapp/src/test/resources/webapp-with-jetty-ee9-web-xml/WEB-INF/jetty-ee9-web.xml b/jetty-ee9/jetty-ee9-webapp/src/test/resources/webapp-with-jetty-ee9-web-xml/WEB-INF/jetty-ee9-web.xml
new file mode 100644
index 000000000000..68227056378f
--- /dev/null
+++ b/jetty-ee9/jetty-ee9-webapp/src/test/resources/webapp-with-jetty-ee9-web-xml/WEB-INF/jetty-ee9-web.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /raspberry
+
+
diff --git a/jetty-ee9/jetty-ee9-webapp/src/test/resources/webapp-with-jetty-ee9-web-xml/WEB-INF/jetty-web.xml b/jetty-ee9/jetty-ee9-webapp/src/test/resources/webapp-with-jetty-ee9-web-xml/WEB-INF/jetty-web.xml
new file mode 100644
index 000000000000..517bef72c458
--- /dev/null
+++ b/jetty-ee9/jetty-ee9-webapp/src/test/resources/webapp-with-jetty-ee9-web-xml/WEB-INF/jetty-web.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /apple
+
+
diff --git a/jetty-ee9/jetty-ee9-webapp/src/test/resources/webapp-with-jetty-web-xml/WEB-INF/jetty-web.xml b/jetty-ee9/jetty-ee9-webapp/src/test/resources/webapp-with-jetty-web-xml/WEB-INF/jetty-web.xml
new file mode 100644
index 000000000000..90d5ac4e64ad
--- /dev/null
+++ b/jetty-ee9/jetty-ee9-webapp/src/test/resources/webapp-with-jetty-web-xml/WEB-INF/jetty-web.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /orange
+
+