Skip to content

Commit

Permalink
Jetty 12.0.x 10582 servlethttpwrapper (#10587)
Browse files Browse the repository at this point in the history
* Issue #10582 fix DispatcherTest use of ServletRequestWrapper
  • Loading branch information
janbartel authored Oct 12, 2023
1 parent fcc8827 commit fffbab0
Show file tree
Hide file tree
Showing 7 changed files with 274 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,188 +43,186 @@ public ServletRequestHttpWrapper(ServletRequest request)
@Override
public String getAuthType()
{
return null;
throw new UnsupportedOperationException();
}

@Override
public Cookie[] getCookies()
{
return null;
throw new UnsupportedOperationException();
}

@Override
public long getDateHeader(String name)
{
return 0;
throw new UnsupportedOperationException();
}

@Override
public String getHeader(String name)
{
return null;
throw new UnsupportedOperationException();
}

@Override
public Enumeration<String> getHeaders(String name)
public Enumeration<String> getHeaderNames()
{
return null;
throw new UnsupportedOperationException();
}

@Override
public Enumeration<String> getHeaderNames()
public Enumeration<String> getHeaders(String name)
{
return null;
throw new UnsupportedOperationException();
}

@Override
public int getIntHeader(String name)
{
return 0;
throw new UnsupportedOperationException();
}

@Override
public String getMethod()
{
return null;
throw new UnsupportedOperationException();
}

@Override
public String getPathInfo()
{
return null;
throw new UnsupportedOperationException();
}

@Override
public String getPathTranslated()
{
return null;
throw new UnsupportedOperationException();
}

@Override
public String getContextPath()
{
return null;
throw new UnsupportedOperationException();
}

@Override
public String getQueryString()
{
return null;
throw new UnsupportedOperationException();
}

@Override
public String getRemoteUser()
{
return null;
throw new UnsupportedOperationException();
}

@Override
public boolean isUserInRole(String role)
{
return false;
throw new UnsupportedOperationException();
}

@Override
public Principal getUserPrincipal()
{
return null;
throw new UnsupportedOperationException();
}

@Override
public String getRequestedSessionId()
{
return null;
throw new UnsupportedOperationException();
}

@Override
public String getRequestURI()
{
return null;
throw new UnsupportedOperationException();
}

@Override
public StringBuffer getRequestURL()
{
return null;
throw new UnsupportedOperationException();
}

@Override
public String getServletPath()
{
return null;
throw new UnsupportedOperationException();
}

@Override
public HttpSession getSession(boolean create)
{
return null;
throw new UnsupportedOperationException();
}

@Override
public HttpSession getSession()
{
return null;
throw new UnsupportedOperationException();
}

@Override
public boolean isRequestedSessionIdValid()
{
return false;
throw new UnsupportedOperationException();
}

@Override
public boolean isRequestedSessionIdFromCookie()
{
return false;
throw new UnsupportedOperationException();
}

@Override
public boolean isRequestedSessionIdFromURL()
{
return false;
throw new UnsupportedOperationException();
}

@Override
public boolean authenticate(HttpServletResponse response) throws IOException, ServletException
{
return false;
throw new UnsupportedOperationException();
}

@Override
public Part getPart(String name) throws IOException, ServletException
{
return null;
throw new UnsupportedOperationException();
}

@Override
public Collection<Part> getParts() throws IOException, ServletException
{
return null;
throw new UnsupportedOperationException();
}

@Override
public void login(String username, String password) throws ServletException
{

throw new UnsupportedOperationException();
}

@Override
public void logout() throws ServletException
{

throw new UnsupportedOperationException();
}

@Override
public String changeSessionId()
{
// TODO 3.1 Auto-generated method stub
return null;
throw new UnsupportedOperationException();
}

@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException
{
// TODO 3.1 Auto-generated method stub
return null;
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,66 @@ public void testInclude() throws Exception
assertEquals(expected, responses);
}

@Test
public void testServletIncludeWelcome() throws Exception
{
_server.stop();
_contextHandler.setWelcomeFiles(new String[] {"index.x"});
_contextHandler.addServlet(DispatchServletServlet.class, "/dispatch/*");
ServletHolder defaultHolder = _contextHandler.addServlet(DefaultServlet.class, "/");
defaultHolder.setInitParameter("welcomeServlets", "true");
_contextHandler.addServlet(RogerThatServlet.class, "*.x");
_server.start();

String rawResponse = _connector.getResponse("""
GET /context/r/ HTTP/1.0\r
Host: localhost\r
Connection: close\r
\r
""");

String expected = """
HTTP/1.1 200 OK\r
Content-Length: 11\r
\r
Roger That!""";

assertEquals(expected, rawResponse);


// direct include
rawResponse = _connector.getResponse("""
GET /context/dispatch/test?include=/index.x HTTP/1.0\r
Host: localhost\r
Connection: close\r
\r
""");

expected = """
HTTP/1.1 200 OK\r
Content-Length: 11\r
\r
Roger That!""";

assertEquals(expected, rawResponse);

// include through welcome file based on servlet mapping
rawResponse = _connector.getResponse("""
GET /context/dispatch/test?include=/r/ HTTP/1.0\r
Host: localhost\r
Connection: close\r
\r
""");

expected = """
HTTP/1.1 200 OK\r
Content-Length: 11\r
\r
Roger That!""";

assertEquals(expected, rawResponse);
}

public static Stream<Arguments> includeTests()
{
return Stream.of(
Expand Down Expand Up @@ -1142,13 +1202,13 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
if (request.getParameter("include") != null)
{
dispatcher = getServletContext().getRequestDispatcher(request.getParameter("include"));
dispatcher.include(new ServletRequestWrapper(request), new ServletResponseWrapper(response));
dispatcher.include(new HttpServletRequestWrapper(request), new HttpServletResponseWrapper(response));
}
else if (request.getParameter("forward") != null)
{
dispatcher = getServletContext().getRequestDispatcher(request.getParameter("forward"));
if (dispatcher != null)
dispatcher.forward(new ServletRequestWrapper(request), new ServletResponseWrapper(response));
dispatcher.forward(new HttpServletRequestWrapper(request), new HttpServletResponseWrapper(response));
else
response.sendError(404);
}
Expand Down
Loading

0 comments on commit fffbab0

Please sign in to comment.