From 210aa8e75b7a86ee05457f19067e97842605553d Mon Sep 17 00:00:00 2001 From: gregw Date: Sat, 12 Dec 2020 12:44:15 +0100 Subject: [PATCH] Temporary fix for challenged TCK test This is to pass the current TCK. This has been challenged in https://github.com/eclipse-ee4j/jakartaee-tck/issues/585 --- .../org/eclipse/jetty/server/Request.java | 8 +++ .../eclipse/jetty/servlet/DispatcherTest.java | 53 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index 7666fcdfdfe5..0658e1edc38c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -2416,6 +2416,14 @@ ServletPathMapping findServletPathMapping() @Override public HttpServletMapping getHttpServletMapping() { + // TODO This is to pass the current TCK. This has been challenged in https://github.com/eclipse-ee4j/jakartaee-tck/issues/585 + if (_dispatcherType == DispatcherType.ASYNC) + { + Object async = getAttribute(AsyncContext.ASYNC_MAPPING); + if (async != null) + return (ServletPathMapping)async; + } + // The mapping returned is normally for the current servlet. Except during an // INCLUDE dispatch, in which case this method returns the mapping of the source servlet, // which we recover from the IncludeAttributes wrapper. diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DispatcherTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DispatcherTest.java index fa17a6310fb8..33c2746bd717 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DispatcherTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DispatcherTest.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.EnumSet; import java.util.List; +import javax.servlet.AsyncContext; import javax.servlet.DispatcherType; import javax.servlet.Filter; import javax.servlet.FilterChain; @@ -469,6 +470,17 @@ public void testWrappedForwardCloseIntercepted() throws Exception testForward(); } + @Test + public void testDispatchMapping() throws Exception + { + _contextHandler.addServlet(new ServletHolder("TestServlet", MappingServlet.class), "/TestServlet"); + _contextHandler.addServlet(new ServletHolder("DispatchServlet", AsyncDispatch2TestServlet.class), "/DispatchServlet"); + + String response = _connector.getResponse("GET /context/DispatchServlet HTTP/1.0\n\n"); + // TODO This is to pass the current TCK. This has been challenged in https://github.com/eclipse-ee4j/jakartaee-tck/issues/585 + assertThat(response, containsString("matchValue=DispatchServlet, pattern=/DispatchServlet, servletName=DispatchServlet, mappingMatch=EXACT")); + } + public static class WrappingFilter implements Filter { @Override @@ -1060,4 +1072,45 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t response.getOutputStream().print(request.getDispatcherType().toString()); } } + + public static class MappingServlet extends HttpServlet + { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException + { + HttpServletMapping mapping = req.getHttpServletMapping(); + if (mapping == null) + { + resp.getWriter().println("Get null HttpServletMapping"); + } + else + { + StringBuilder sb = new StringBuilder(); + sb.append("matchValue=" + mapping.getMatchValue()) + .append(", pattern=" + mapping.getPattern()) + .append(", servletName=" + mapping.getServletName()) + .append(", mappingMatch=" + mapping.getMappingMatch()); + resp.getWriter().println(sb.toString()); + } + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException + { + this.doGet(req, resp); + } + } + + public static class AsyncDispatch2TestServlet extends HttpServlet + { + public void doGet(HttpServletRequest req, HttpServletResponse resp) + throws IOException + { + AsyncContext asyncContext = req.startAsync(); + asyncContext.setTimeout(0); + asyncContext.dispatch("/TestServlet"); + } + } }