Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #10661 Allow jetty api to override servlets and mappings from webdefault #10668

Merged
merged 14 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.eclipse.jetty.ee10.servlet.DefaultServlet;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.eclipse.jetty.ee10.servlet.ServletMapping;
import org.eclipse.jetty.logging.StacklessLogging;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
Expand Down Expand Up @@ -137,7 +138,18 @@ public void testDuplicateServletMappingsFromDescriptors(WorkDir workDir) throws
wac.setBaseResourceAsPath(docroot);
wac.setDescriptor(webXml.toURI().toURL().toString());
wac.start();
assertEquals("other", wac.getServletHandler().getServletMapping("/").getServletName());
ServletMapping[] mappings = wac.getServletHandler().getServletMappings();
ServletMapping mapping = null;
for (ServletMapping m : mappings)
{
if (m.containsPathSpec("/"))
{
assertEquals(null, mapping);
mapping = m;
janbartel marked this conversation as resolved.
Show resolved Hide resolved
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you iterate through all of the mappings, what if there are 2 mappings both with path spec /? (I know this shouldn't be possible, but you found we accidentally did just that before this PR, and we should ensure that we don't have that regression again)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 147 is doing exactly this.

assertNotNull(mapping);
assertEquals("other", mapping.getServletName());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
version="6.0">
version="6.0">

<display-name>Bad Redefine Default Servlet Mapping WebApp</display-name>
<display-name>Bad Redefine Default Servlet Mapping WebApp</display-name>
<servlet>
<servlet-name>first</servlet-name>
<servlet-class>org.acme.webapp.GetResourceServlet</servlet-class>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
version="6.0">
version="6.0">

<display-name>Redefine Default Servlet Mapping WebApp</display-name>
<display-name>Redefine Default Servlet Mapping WebApp</display-name>
<servlet>
<servlet-name>other</servlet-name>
<servlet-class>org.acme.webapp.GetResourceServlet</servlet-class>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.eclipse.jetty.ee9.servlet.DefaultServlet;
import org.eclipse.jetty.ee9.servlet.ServletHolder;
import org.eclipse.jetty.ee9.servlet.ServletMapping;
import org.eclipse.jetty.logging.StacklessLogging;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.MavenPaths;
Expand Down Expand Up @@ -130,7 +131,18 @@ public void testDuplicateServletMappingsFromDescriptors(WorkDir workDir) throws
wac.setBaseResourceAsPath(docroot);
wac.setDescriptor(webXml.toUri().toURL().toString());
wac.start();
assertEquals("other", wac.getServletHandler().getServletMapping("/").getServletName());
ServletMapping[] mappings = wac.getServletHandler().getServletMappings();
ServletMapping mapping = null;
for (ServletMapping m : mappings)
{
if (m.containsPathSpec("/"))
{
assertEquals(null, mapping);
mapping = m;
janbartel marked this conversation as resolved.
Show resolved Hide resolved
}
}
assertNotNull(mapping);
assertEquals("other", mapping.getServletName());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
version="6.0">
version="6.0">

<display-name>Bad Redefine Default Servlet Mapping WebApp</display-name>
<display-name>Bad Redefine Default Servlet Mapping WebApp</display-name>
<servlet>
<servlet-name>first</servlet-name>
<servlet-class>org.acme.webapp.GetResourcePathsServlet</servlet-class>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
version="6.0">
version="6.0">

<display-name>Redefine Default Servlet Mapping WebApp</display-name>
<display-name>Redefine Default Servlet Mapping WebApp</display-name>
<servlet>
<servlet-name>other</servlet-name>
<servlet-class>org.acme.webapp.GetResourcePathsServlet</servlet-class>
Expand Down