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

Temporary fix for challenged TCK test #5803

Merged
merged 1 commit into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really want to fall through to use the target mapping if this is null.
Should we skip the null check here and return (ServletPathMapping)async always.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is a mute point as the async mapping should never be null when the dispatch type is ASYNC... however, just in case I would prefer to return non 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
}
}
}