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

Add method to get the defaultServlet MappedResource from ServletHandler #11710

Closed
wants to merge 1 commit into from

Conversation

lachlan-roberts
Copy link
Contributor

This is needed to improve the way we find the servlet mapped to the default mapping in appengine:
https://github.com/GoogleCloudPlatform/appengine-java-standard/blob/97f644a3b5a3edfccb06e58f7401e047b6d28c48/runtime/runtime_impl_jetty12/src/main/java/com/google/apphosting/runtime/jetty/ee10/ResourceFileServlet.java#L259

Currently it does handler.getMappedServlet("/") which will actually return the servlet from a context root mapping so is incorrect.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
@lachlan-roberts lachlan-roberts added the Sponsored This issue affects a user with a commercial support agreement label Apr 26, 2024
Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

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

Not sure I understand the need?

@gregw
Copy link
Contributor

gregw commented Apr 26, 2024

@lachlan-roberts I think this is the logic you need

@Test
public void testXServletMappings() throws Exception
{
    Server server = new Server();
    ServletContextHandler context = new ServletContextHandler("/");
    server.setHandler(context);
    ServletHandler handler = new ServletHandler();
    context.setHandler(handler);

    handler.addServletWithMapping(SomeServlet.class.getName(), "/path");
    handler.addServletWithMapping(DefaultServlet.class.getName(), "/");
    handler.addServletWithMapping(SomeServlet.class.getName(), "");

    server.start();

    ServletHandler.MappedServlet mapped = handler.getMappedServlet("/something");
    assertEquals(mapped.getServletHolder().getName(), handler.getServletMapping("/").getServletName());

    mapped = handler.getMappedServlet("/");
    assertNotEquals(mapped.getServletHolder().getName(), handler.getServletMapping("/").getServletName());

    mapped = handler.getMappedServlet("/path");
    assertNotEquals(mapped.getServletHolder().getName(), handler.getServletMapping("/").getServletName()); 
}

@lachlan-roberts
Copy link
Contributor Author

Closing as we can use getServletMapping() which compares on pathSpec.

@lachlan-roberts lachlan-roberts deleted the ServletHandler-defaultServlet branch April 29, 2024 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Sponsored This issue affects a user with a commercial support agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants