Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jetty-12.1.x' into jetty-12.1.x-…
Browse files Browse the repository at this point in the history
…11813-noops-after-commit
  • Loading branch information
janbartel committed May 27, 2024
2 parents 89096c9 + f7e502b commit 0682cbc
Show file tree
Hide file tree
Showing 6 changed files with 313 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -785,21 +785,65 @@ public ServletHolder addServletWithMapping(String className, String pathSpec)
* @return The servlet holder.
*/
public ServletHolder addServletWithMapping(Class<? extends Servlet> servlet, String pathSpec)
{
return addServletWithMapping(null, servlet, pathSpec);
}

/**
* Convenience method to add a servlet.
*
* @param servletName The name of the servlet holder or {@code null} for a default name.
* @param servlet the servlet class
* @param pathSpecs the path specs
* @return The servlet holder.
*/
public ServletHolder addServletWithMapping(String servletName, Class<? extends Servlet> servlet, String... pathSpecs)
{
ServletHolder holder = newServletHolder(Source.EMBEDDED);
if (servletName != null)
holder.setName(servletName);
holder.setHeldClass(servlet);
addServletWithMapping(holder, pathSpec);
addServletWithMappings(holder, pathSpecs);

return holder;
}

/**
* Convenience method to add a servlet.
*
* @param servletName The name of the servlet holder or {@code null} for a default name.
* @param servlet the servlet instance
* @param pathSpecs the path specs
* @return The servlet holder.
*/
public ServletHolder addServletWithMapping(String servletName, Servlet servlet, String... pathSpecs)
{
ServletHolder holder = newServletHolder(Source.EMBEDDED);
if (servletName != null)
holder.setName(servletName);
holder.setServlet(servlet);
addServletWithMappings(holder, pathSpecs);
return holder;
}

/**
* Convenience method to add a servlet.
*
* @param servlet servlet holder to add
* @param pathSpec servlet mappings for the servletHolder
*/
public void addServletWithMapping(ServletHolder servlet, String pathSpec)
{
addServletWithMappings(servlet, pathSpec);
}

/**
* Convenience method to add a servlet.
*
* @param servlet servlet holder to add
* @param pathSpecs servlet mappings for the servletHolder
*/
public void addServletWithMappings(ServletHolder servlet, String... pathSpecs)
{
Objects.requireNonNull(servlet);
ServletHolder[] holders = getServlets();
Expand All @@ -811,10 +855,13 @@ public void addServletWithMapping(ServletHolder servlet, String pathSpec)
setServlets(ArrayUtil.addToArray(holders, servlet, ServletHolder.class));
}

ServletMapping mapping = new ServletMapping();
mapping.setServletName(servlet.getName());
mapping.setPathSpec(pathSpec);
setServletMappings(ArrayUtil.addToArray(getServletMappings(), mapping, ServletMapping.class));
if (pathSpecs != null && pathSpecs.length > 0)
{
ServletMapping mapping = new ServletMapping();
mapping.setServletName(servlet.getName());
mapping.setPathSpecs(pathSpecs);
addServletMapping(mapping);
}
}
catch (RuntimeException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ public ServletPathMapping(PathSpec pathSpec, String servletName, String pathInCo
case PREFIX_GLOB:
_mappingMatch = MappingMatch.PATH;
_servletPath = pathSpec.getPrefix();
_matchValue = _servletPath.startsWith("/") ? _servletPath.substring(1) : _servletPath;
_pathInfo = matchedPath != null
? matchedPath.getPathInfo()
: _servletPath.length() == pathInContext.length() ? null : pathInContext.substring(_servletPath.length());
_matchValue = _pathInfo == null ? "" : _pathInfo.startsWith("/") ? _pathInfo.substring(1) : _pathInfo;
break;

case SUFFIX_GLOB:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public void testDispatchAsyncContextEncodedUrl() throws Exception
assertThat("async run attr query string", responseBody, containsString("async:run:attr:queryString:dispatch=true"));
assertThat("async run context path", responseBody, containsString("async:run:attr:contextPath:/ctx"));
assertThat("async run request uri has correct encoding", responseBody, containsString("async:run:attr:requestURI:/ctx/encoded/hello%20there"));
assertThat("http servlet mapping matchValue is correct", responseBody, containsString("async:run:attr:mapping:matchValue:encoded"));
assertThat("http servlet mapping matchValue is correct", responseBody, containsString("async:run:attr:mapping:matchValue:hello there"));
assertThat("http servlet mapping pattern is correct", responseBody, containsString("async:run:attr:mapping:pattern:/encoded/*"));
assertThat("http servlet mapping servletName is correct", responseBody, containsString("async:run:attr:mapping:servletName:"));
assertThat("http servlet mapping mappingMatch is correct", responseBody, containsString("async:run:attr:mapping:mappingMatch:PATH"));
Expand Down Expand Up @@ -333,7 +333,7 @@ public void testDispatchAsyncAmbiguousUrl() throws Exception
assertThat("async run attr query string", responseBody, containsString("async:run:attr:queryString:dispatch=true"));
assertThat("async run context path", responseBody, containsString("async:run:attr:contextPath:/ctx"));
assertThat("async run request uri has correct encoding", responseBody, containsString("async:run:attr:requestURI:/ctx/ambiguous/hello%20there"));
assertThat("http servlet mapping matchValue is correct", responseBody, containsString("async:run:attr:mapping:matchValue:ambiguous"));
assertThat("http servlet mapping matchValue is correct", responseBody, containsString("async:run:attr:mapping:matchValue:hello there"));
assertThat("http servlet mapping pattern is correct", responseBody, containsString("async:run:attr:mapping:pattern:/ambiguous/*"));
assertThat("http servlet mapping servletName is correct", responseBody, containsString("async:run:attr:mapping:servletName:"));
assertThat("http servlet mapping mappingMatch is correct", responseBody, containsString("async:run:attr:mapping:mappingMatch:PATH"));
Expand Down
Loading

0 comments on commit 0682cbc

Please sign in to comment.