Polishing
This commit is contained in:
parent
3b1d46b3ba
commit
c244f33f84
|
|
@ -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<PathPattern> {
|
|||
*/
|
||||
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<PathPattern> {
|
|||
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<PathPattern> {
|
|||
*/
|
||||
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<PathPattern> {
|
|||
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<PathPattern> {
|
|||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 '<tt>/foo/*_*/*_{foobar}</tt>' both <tt>*_*</tt> and <tt>*_{foobar}</tt>
|
||||
* 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
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class SeparatorPathElement extends PathElement {
|
|||
matched = true;
|
||||
}
|
||||
else {
|
||||
matched = ((candidateIndex + 1) == matchingContext.candidateLength);
|
||||
matched = (candidateIndex + 1 == matchingContext.candidateLength);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -339,6 +339,7 @@ public interface WebClient {
|
|||
S uri(Function<UriBuilder, URI> 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.
|
||||
*
|
||||
* <p>Use {@link Mono#flatMap(Function)} or
|
||||
* {@link Mono#flatMapMany(Function)} to compose further on the response:
|
||||
*
|
||||
* <pre>
|
||||
* 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));
|
||||
* </pre>
|
||||
*
|
||||
* @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<ClientResponse>} it exposes shortcut
|
||||
* methods to extract the response body.
|
||||
*
|
||||
* <p>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.
|
||||
*
|
||||
* <pre>
|
||||
* 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);
|
||||
* </pre>
|
||||
*
|
||||
* @return spec with options for extracting the response body
|
||||
*/
|
||||
ResponseSpec retrieve();
|
||||
|
||||
}
|
||||
|
||||
|
||||
interface RequestBodySpec extends RequestHeadersSpec<RequestBodySpec> {
|
||||
|
||||
/**
|
||||
|
|
@ -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 <T> 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 <T> 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 <T> 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 <T> the type of elements in the list
|
||||
* @return {@code Mono} with the list of {@code ResponseEntity}s
|
||||
|
|
|
|||
Loading…
Reference in New Issue