Skip to content

Allow use of MvcUriComponentsBuilder independent of Servlet request lifecycle [SPR-12800] #17397

@spring-projects-issues

Description

@spring-projects-issues

Simon opened SPR-12800 and commented

It is a common requirement to generate links to controllers outside of an HttpServletRequest when generating E-Mails etc. Therefore it would be nice to have a way to create links which uses a configurable baseURI for the link generation instead of the request context path like this:

private String fromStatelessMethodCall(Object invocationInfo) {
  MvcUriComponentsBuilder.MethodInvocationInfo info = (MvcUriComponentsBuilder.MethodInvocationInfo) invocationInfo;
  Method method = info.getControllerMethod();
  String typePath = getTypeRequestMapping(method.getDeclaringClass());
  String methodPath = getMethodRequestMapping(method);
  String path = pathMatcher.combine(typePath, methodPath);
  UriComponentsBuilder builder = UriComponentsBuilder.fromUri(baseURI).path(path);
  UriComponents uriComponents = applyContributors(builder, method, info.getArgumentValues());
  return uriComponents.toUriString();
}

Affects: 4.1.5

Issue Links:

Referenced from: commits febcd0c

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions