From fadfcf4e43725f4ce5180618a88c21010d55055a Mon Sep 17 00:00:00 2001 From: wkwkhautbois Date: Fri, 28 Jan 2022 23:06:32 +0900 Subject: [PATCH 1/2] Fix ServletUriComponentsBuilder examples in ref docs Closes gh-27984 --- src/docs/asciidoc/web/webmvc.adoc | 46 +++++++++++++++++-------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/docs/asciidoc/web/webmvc.adoc b/src/docs/asciidoc/web/webmvc.adoc index 7bca08dd9d2..52e6d0db4d4 100644 --- a/src/docs/asciidoc/web/webmvc.adoc +++ b/src/docs/asciidoc/web/webmvc.adoc @@ -4109,10 +4109,9 @@ as the following example shows: // Re-uses host, scheme, port, path and query string... - ServletUriComponentsBuilder ucb = ServletUriComponentsBuilder.fromRequest(request) - .replaceQueryParam("accountId", "{id}").build() - .expand("123") - .encode(); + URI uri = ServletUriComponentsBuilder.fromRequest(request) + .replaceQueryParam("accountId", "{id}") + .build("123"); ---- [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] .Kotlin @@ -4121,10 +4120,9 @@ as the following example shows: // Re-uses host, scheme, port, path and query string... - val ucb = ServletUriComponentsBuilder.fromRequest(request) - .replaceQueryParam("accountId", "{id}").build() - .expand("123") - .encode() + val uri = ServletUriComponentsBuilder.fromRequest(request) + .replaceQueryParam("accountId", "{id}") + .build("123") ---- You can create URIs relative to the context path, as the following example shows: @@ -4132,18 +4130,22 @@ You can create URIs relative to the context path, as the following example shows [source,java,indent=0,subs="verbatim,quotes",role="primary"] .Java ---- - // Re-uses host, port and context path... + // Re-uses host, port, scheme and context path... - ServletUriComponentsBuilder ucb = ServletUriComponentsBuilder.fromContextPath(request) - .path("/accounts").build() + URI uri = ServletUriComponentsBuilder.fromContextPath(request) + .path("/accounts") + .build() + .toUri(); ---- [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] .Kotlin ---- - // Re-uses host, port and context path... + // Re-uses host, port, scheme and context path... - val ucb = ServletUriComponentsBuilder.fromContextPath(request) - .path("/accounts").build() + val uri = ServletUriComponentsBuilder.fromContextPath(request) + .path("/accounts") + .build() + .toUri() ---- You can create URIs relative to a Servlet (for example, `/main/{asterisk}`), @@ -4152,18 +4154,22 @@ as the following example shows: [source,java,indent=0,subs="verbatim,quotes",role="primary"] .Java ---- - // Re-uses host, port, context path, and Servlet prefix... + // Re-uses host, port, scheme, context path, and Servlet prefix... - ServletUriComponentsBuilder ucb = ServletUriComponentsBuilder.fromServletMapping(request) - .path("/accounts").build() + URI uri = ServletUriComponentsBuilder.fromServletMapping(request) + .path("/accounts") + .build() + .toUri(); ---- [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] .Kotlin ---- - // Re-uses host, port, context path, and Servlet prefix... + // Re-uses host, port, scheme, context path, and Servlet prefix... - val ucb = ServletUriComponentsBuilder.fromServletMapping(request) - .path("/accounts").build() + val uri = ServletUriComponentsBuilder.fromServletMapping(request) + .path("/accounts") + .build() + .toUri() ---- NOTE: As of 5.1, `ServletUriComponentsBuilder` ignores information from the `Forwarded` and From 0e670b1c1546522b8f158bff6d1092b1b8035ea2 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 28 Jan 2022 16:15:21 +0100 Subject: [PATCH 2/2] Polish contribution See gh-27984 --- src/docs/asciidoc/web/webmvc.adoc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/docs/asciidoc/web/webmvc.adoc b/src/docs/asciidoc/web/webmvc.adoc index 52e6d0db4d4..b34860566c9 100644 --- a/src/docs/asciidoc/web/webmvc.adoc +++ b/src/docs/asciidoc/web/webmvc.adoc @@ -4107,7 +4107,7 @@ as the following example shows: ---- HttpServletRequest request = ... - // Re-uses host, scheme, port, path and query string... + // Re-uses scheme, host, port, path, and query string... URI uri = ServletUriComponentsBuilder.fromRequest(request) .replaceQueryParam("accountId", "{id}") @@ -4118,7 +4118,7 @@ as the following example shows: ---- val request: HttpServletRequest = ... - // Re-uses host, scheme, port, path and query string... + // Re-uses scheme, host, port, path, and query string... val uri = ServletUriComponentsBuilder.fromRequest(request) .replaceQueryParam("accountId", "{id}") @@ -4130,7 +4130,9 @@ You can create URIs relative to the context path, as the following example shows [source,java,indent=0,subs="verbatim,quotes",role="primary"] .Java ---- - // Re-uses host, port, scheme and context path... + HttpServletRequest request = ... + + // Re-uses scheme, host, port, and context path... URI uri = ServletUriComponentsBuilder.fromContextPath(request) .path("/accounts") @@ -4140,7 +4142,9 @@ You can create URIs relative to the context path, as the following example shows [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] .Kotlin ---- - // Re-uses host, port, scheme and context path... + val request: HttpServletRequest = ... + + // Re-uses scheme, host, port, and context path... val uri = ServletUriComponentsBuilder.fromContextPath(request) .path("/accounts") @@ -4154,7 +4158,9 @@ as the following example shows: [source,java,indent=0,subs="verbatim,quotes",role="primary"] .Java ---- - // Re-uses host, port, scheme, context path, and Servlet prefix... + HttpServletRequest request = ... + + // Re-uses scheme, host, port, context path, and Servlet mapping prefix... URI uri = ServletUriComponentsBuilder.fromServletMapping(request) .path("/accounts") @@ -4164,7 +4170,9 @@ as the following example shows: [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] .Kotlin ---- - // Re-uses host, port, scheme, context path, and Servlet prefix... + val request: HttpServletRequest = ... + + // Re-uses scheme, host, port, context path, and Servlet mapping prefix... val uri = ServletUriComponentsBuilder.fromServletMapping(request) .path("/accounts")