diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java index 92a58fc29f..671e580b40 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java @@ -22,8 +22,7 @@ import java.util.Map; import org.springframework.lang.Nullable; import org.springframework.util.PathMatcher; - -import static org.springframework.util.StringUtils.*; +import org.springframework.util.StringUtils; /** * Represents a parsed path pattern. Includes a chain of path elements @@ -154,9 +153,9 @@ public class PathPattern implements Comparable { */ public boolean matches(String path) { if (this.head == null) { - return !hasLength(path); + return !StringUtils.hasLength(path); } - else if (!hasLength(path)) { + else if (!StringUtils.hasLength(path)) { if (this.head instanceof WildcardTheRestPathElement || this.head instanceof CaptureTheRestPathElement) { path = ""; // Will allow CaptureTheRest to bind the variable to empty } @@ -179,7 +178,7 @@ public class PathPattern implements Comparable { if (this.head == null) { return new PathRemainingMatchInfo(path); } - else if (!hasLength(path)) { + else if (!StringUtils.hasLength(path)) { return null; } @@ -208,9 +207,9 @@ public class PathPattern implements Comparable { */ public boolean matchStart(String path) { if (this.head == null) { - return !hasLength(path); + return !StringUtils.hasLength(path); } - else if (!hasLength(path)) { + else if (!StringUtils.hasLength(path)) { return true; } MatchingContext matchingContext = new MatchingContext(path, false); @@ -228,13 +227,11 @@ public class PathPattern implements Comparable { if (this.head != null && this.head.matches(0, matchingContext)) { return matchingContext.getExtractedVariables(); } + else if (!StringUtils.hasLength(path)) { + return Collections.emptyMap(); + } else { - if (!hasLength(path)) { - return Collections.emptyMap(); - } - else { - throw new IllegalStateException("Pattern \"" + this + "\" is not a match for \"" + path + "\""); - } + throw new IllegalStateException("Pattern \"" + this + "\" is not a match for \"" + path + "\""); } } @@ -400,15 +397,15 @@ public class PathPattern implements Comparable { */ public String combine(String pattern2string) { // If one of them is empty the result is the other. If both empty the result is "" - if (!hasLength(this.patternString)) { - if (!hasLength(pattern2string)) { + if (!StringUtils.hasLength(this.patternString)) { + if (!StringUtils.hasLength(pattern2string)) { return ""; } else { return pattern2string; } } - else if (!hasLength(pattern2string)) { + else if (!StringUtils.hasLength(pattern2string)) { return this.patternString; } diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java index d588801a68..58f3ad0169 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java @@ -22,14 +22,14 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.springframework.util.AntPathMatcher; import org.springframework.web.util.UriUtils; import org.springframework.web.util.pattern.PathPattern.MatchingContext; /** * A regex path element. Used to represent any complicated element of the path. * For example in '/foo/*_*/*_{foobar}' both *_* and *_{foobar} - * are {@link RegexPathElement} path elements. Derived from the general {@link AntPathMatcher} approach. + * are {@link RegexPathElement} path elements. Derived from the general + * {@link org.springframework.util.AntPathMatcher} approach. * * @author Andy Clement * @since 5.0 diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/SeparatorPathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/SeparatorPathElement.java index 2d394795e4..8634e3b547 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/SeparatorPathElement.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/SeparatorPathElement.java @@ -48,7 +48,7 @@ class SeparatorPathElement extends PathElement { matched = true; } else { - matched = ((candidateIndex + 1) == matchingContext.candidateLength); + matched = (candidateIndex + 1 == matchingContext.candidateLength); } } else { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java index ae7a802477..818e981855 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java @@ -276,9 +276,8 @@ class DefaultWebClient implements WebClient { @Override public RequestHeadersSpec syncBody(Object body) { - Assert.isTrue(!(body instanceof Publisher), "Please specify the element class by " + - "using body(Publisher, Class)"); - + Assert.isTrue(!(body instanceof Publisher), + "Please specify the element class by using body(Publisher, Class)"); this.inserter = BodyInserters.fromObject(body); return this; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java index cc05d5ca28..d77c352284 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java @@ -339,6 +339,7 @@ public interface WebClient { S uri(Function uriFunction); } + /** * Contract for specifying request headers leading up to the exchange. */ @@ -417,22 +418,19 @@ public interface WebClient { /** * Exchange the request for a {@code ClientResponse} with full access * to the response status and headers before extracting the body. - * *

Use {@link Mono#flatMap(Function)} or * {@link Mono#flatMapMany(Function)} to compose further on the response: - * *

-		 *	Mono<Pojo> mono = client.get().uri("/")
-		 *		.accept(MediaType.APPLICATION_JSON)
-		 *		.exchange()
-		 *		.flatMap(response -> response.bodyToMono(Pojo.class));
+		 * Mono<Pojo> mono = client.get().uri("/")
+		 *     .accept(MediaType.APPLICATION_JSON)
+		 *     .exchange()
+		 *     .flatMap(response -> response.bodyToMono(Pojo.class));
 		 *
-		 *	Flux<Pojo> flux = client.get().uri("/")
-		 *		.accept(MediaType.APPLICATION_STREAM_JSON)
-		 *		.exchange()
-		 *		.flatMapMany(response -> response.bodyToFlux(Pojo.class));
+		 * Flux<Pojo> flux = client.get().uri("/")
+		 *     .accept(MediaType.APPLICATION_STREAM_JSON)
+		 *     .exchange()
+		 *     .flatMapMany(response -> response.bodyToFlux(Pojo.class));
 		 * 
- * * @return a {@code Mono} with the response * @see #retrieve() */ @@ -443,29 +441,26 @@ public interface WebClient { * retrieving the full response (i.e. status, headers, and body) where * instead of returning {@code Mono} it exposes shortcut * methods to extract the response body. - * *

Use of this method is simpler when you don't need to deal directly * with {@link ClientResponse}, e.g. to use a custom {@code BodyExtractor} * or to check the status and headers before extracting the response. - * *

-		 *	Mono<Pojo> bodyMono = client.get().uri("/")
-		 *		.accept(MediaType.APPLICATION_JSON)
-		 *		.retrieve()
-		 *		.bodyToMono(Pojo.class);
+		 * Mono<Pojo> bodyMono = client.get().uri("/")
+		 *     .accept(MediaType.APPLICATION_JSON)
+		 *     .retrieve()
+		 *     .bodyToMono(Pojo.class);
 		 *
-		 *	Mono<ResponseEntity<Pojo>> entityMono = client.get().uri("/")
-		 *		.accept(MediaType.APPLICATION_JSON)
-		 *		.retrieve()
-		 *		.bodyToEntity(Pojo.class);
+		 * Mono<ResponseEntity<Pojo>> entityMono = client.get().uri("/")
+		 *     .accept(MediaType.APPLICATION_JSON)
+		 *     .retrieve()
+		 *     .bodyToEntity(Pojo.class);
 		 * 
- * * @return spec with options for extracting the response body */ ResponseSpec retrieve(); - } + interface RequestBodySpec extends RequestHeadersSpec { /** @@ -515,15 +510,14 @@ public interface WebClient { * @return this builder */ RequestHeadersSpec syncBody(Object body); - } + interface ResponseSpec { /** * Extract the body to a {@code Mono}. If the response has status code 4xx or 5xx, the * {@code Mono} will contain a {@link WebClientException}. - * * @param bodyType the expected response body type * @param response body type * @return a mono containing the body, or a {@link WebClientException} if the status code is @@ -534,7 +528,6 @@ public interface WebClient { /** * Extract the body to a {@code Flux}. If the response has status code 4xx or 5xx, the * {@code Flux} will contain a {@link WebClientException}. - * * @param elementType the type of element in the response * @param the type of elements in the response * @return a flux containing the body, or a {@link WebClientException} if the status code is @@ -546,7 +539,6 @@ public interface WebClient { * Returns the response as a delayed {@code ResponseEntity}. Unlike * {@link #bodyToMono(Class)} and {@link #bodyToFlux(Class)}, this method does not check * for a 4xx or 5xx status code before extracting the body. - * * @param bodyType the expected response body type * @param response body type * @return {@code Mono} with the {@code ResponseEntity} @@ -557,7 +549,6 @@ public interface WebClient { * Returns the response as a delayed list of {@code ResponseEntity}s. Unlike * {@link #bodyToMono(Class)} and {@link #bodyToFlux(Class)}, this method does not check * for a 4xx or 5xx status code before extracting the body. - * * @param elementType the expected response body list element type * @param the type of elements in the list * @return {@code Mono} with the list of {@code ResponseEntity}s