Temporary fix for challenged TCK test (#5803)

This is to pass the current TCK.  This has been challenged in https://github.com/eclipse-ee4j/jakartaee-tck/issues/585
This commit is contained in:
Greg Wilkins 2020-12-14 15:12:11 +01:00 committed by GitHub
parent adbe5c58a1
commit 9edbd56ffb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 0 deletions

View File

@ -2416,6 +2416,14 @@ public class Request implements HttpServletRequest
@Override @Override
public HttpServletMapping getHttpServletMapping() 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 // 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, // INCLUDE dispatch, in which case this method returns the mapping of the source servlet,
// which we recover from the IncludeAttributes wrapper. // which we recover from the IncludeAttributes wrapper.

View File

@ -20,6 +20,7 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import javax.servlet.AsyncContext;
import javax.servlet.DispatcherType; import javax.servlet.DispatcherType;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
@ -469,6 +470,17 @@ public class DispatcherTest
testForward(); 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 public static class WrappingFilter implements Filter
{ {
@Override @Override
@ -1060,4 +1072,45 @@ public class DispatcherTest
response.getOutputStream().print(request.getDispatcherType().toString()); 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");
}
}
} }