Skip to content

Instantly share code, notes, and snippets.

@eisenreich
Last active February 5, 2021 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eisenreich/6ab40616a9e694bc2220c68ec3a01455 to your computer and use it in GitHub Desktop.
Save eisenreich/6ab40616a9e694bc2220c68ec3a01455 to your computer and use it in GitHub Desktop.
Build new request from path (Spring > 2.2.0.RELEASE)
private HttpServletRequest buildRequestFromPath(final HttpServletRequest request, final String path) {
return new HttpServletRequestWrapper(request) {
@Override
public String getRequestURI() {
return path;
}
@Override
public String getPathInfo() {
return path;
}
@Override
public Object getAttribute(final String name) {
if (name.equals(UrlPathHelper.PATH_ATTRIBUTE)) {
return path;
}
return super.getAttribute(name);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment