Polishing
This commit is contained in:
@@ -81,6 +81,7 @@ public class PathMatchConfigurer {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
protected Boolean isUseTrailingSlashMatch() {
|
||||
return this.trailingSlashMatch;
|
||||
|
||||
@@ -24,7 +24,6 @@ import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -95,7 +94,11 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware {
|
||||
@Override
|
||||
public void setApplicationContext(@Nullable ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
assertWebMvcNotEnabled(applicationContext);
|
||||
if (applicationContext != null) {
|
||||
Assert.state(!applicationContext.containsBean("mvcContentNegotiationManager"),
|
||||
"The Java/XML config for Spring MVC and Spring WebFlux cannot both be enabled, " +
|
||||
"e.g. via @EnableWebMvc and @EnableWebFlux, in the same application.");
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -103,19 +106,6 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware {
|
||||
return this.applicationContext;
|
||||
}
|
||||
|
||||
private static void assertWebMvcNotEnabled(@Nullable ApplicationContext applicationContext) {
|
||||
try {
|
||||
if (applicationContext != null) {
|
||||
Assert.isNull(applicationContext.getType("mvcContentNegotiationManager"),
|
||||
"The Java/XML config for Spring MVC and Spring WebFlux cannot both be enabled, " +
|
||||
"e.g. via @EnableWebMvc and @EnableWebFlux, in the same application.");
|
||||
}
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException ex) {
|
||||
// Expected...
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public DispatcherHandler webHandler() {
|
||||
@@ -349,7 +339,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to add custom {@link Converter}s and {@link Formatter Converter}s and {@link Formatters}.
|
||||
* Override to add custom {@link Converter}s and {@link Formatter Formatter}s.
|
||||
*/
|
||||
protected void addFormatters(FormatterRegistry registry) {
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class UnsupportedMediaTypeException extends NestedRuntimeException {
|
||||
* Return the body type in the context of which this exception was generated.
|
||||
* This is applicable when the exception was raised as a result trying to
|
||||
* encode from or decode to a specific Java type.
|
||||
* @return the body type, or {@code null}
|
||||
* @return the body type, or {@code null} if not available
|
||||
* @since 5.1
|
||||
*/
|
||||
@Nullable
|
||||
|
||||
@@ -30,8 +30,10 @@ public class UnknownHttpStatusCodeException extends WebClientResponseException {
|
||||
|
||||
private static final long serialVersionUID = 2407169540168185007L;
|
||||
|
||||
public UnknownHttpStatusCodeException(int statusCode, HttpHeaders headers,
|
||||
byte[] responseBody, Charset responseCharset) {
|
||||
|
||||
public UnknownHttpStatusCodeException(
|
||||
int statusCode, HttpHeaders headers, byte[] responseBody, Charset responseCharset) {
|
||||
|
||||
super("Unknown status code [" + statusCode + "]", statusCode, "",
|
||||
headers, responseBody, responseCharset);
|
||||
}
|
||||
|
||||
@@ -98,14 +98,14 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder {
|
||||
|
||||
@Override
|
||||
public ServerRequest.Builder method(HttpMethod method) {
|
||||
Assert.notNull(method, "'method' must not be null");
|
||||
Assert.notNull(method, "HttpMethod must not be null");
|
||||
this.methodName = method.name();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerRequest.Builder uri(URI uri) {
|
||||
Assert.notNull(uri, "'uri' must not be null");
|
||||
Assert.notNull(uri, "URI must not be null");
|
||||
this.uri = uri;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -80,8 +80,8 @@ public abstract class RequestPredicates {
|
||||
|
||||
|
||||
/**
|
||||
* Return a {@code RequestPredicate} that matches if the request's HTTP method is equal to the
|
||||
* given method.
|
||||
* Return a {@code RequestPredicate} that matches if the request's
|
||||
* HTTP method is equal to the given method.
|
||||
* @param httpMethod the HTTP method to match against
|
||||
* @return a predicate that tests against the given HTTP method
|
||||
*/
|
||||
@@ -90,8 +90,8 @@ public abstract class RequestPredicates {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@code RequestPredicate} that matches if the request's HTTP method is equal to one
|
||||
* the of the given methods.
|
||||
* Return a {@code RequestPredicate} that matches if the request's
|
||||
* HTTP method is equal to one the of the given methods.
|
||||
* @param httpMethods the HTTP methods to match against
|
||||
* @return a predicate that tests against the given HTTP methods
|
||||
* @since 5.1
|
||||
@@ -101,7 +101,8 @@ public abstract class RequestPredicates {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@code RequestPredicate} that tests the request path against the given path pattern.
|
||||
* Return a {@code RequestPredicate} that tests the request path
|
||||
* against the given path pattern.
|
||||
* @param pattern the pattern to match to
|
||||
* @return a predicate that tests against the given path pattern
|
||||
*/
|
||||
@@ -111,20 +112,22 @@ public abstract class RequestPredicates {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a function that creates new path-matching {@code RequestPredicates} from pattern
|
||||
* Strings using the given {@link PathPatternParser}. This method can be used to specify a
|
||||
* non-default, customized {@code PathPatternParser} when resolving path patterns.
|
||||
* Return a function that creates new path-matching {@code RequestPredicates}
|
||||
* from pattern Strings using the given {@link PathPatternParser}.
|
||||
* <p>This method can be used to specify a non-default, customized
|
||||
* {@code PathPatternParser} when resolving path patterns.
|
||||
* @param patternParser the parser used to parse patterns given to the returned function
|
||||
* @return a function that resolves patterns Strings into path-matching
|
||||
* {@code RequestPredicate}s
|
||||
* @return a function that resolves a pattern String into a path-matching
|
||||
* {@code RequestPredicates} instance
|
||||
*/
|
||||
public static Function<String, RequestPredicate> pathPredicates(PathPatternParser patternParser) {
|
||||
Assert.notNull(patternParser, "'patternParser' must not be null");
|
||||
Assert.notNull(patternParser, "PathPatternParser must not be null");
|
||||
return pattern -> new PathPatternPredicate(patternParser.parse(pattern));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@code RequestPredicate} that tests the request's headers against the given headers predicate.
|
||||
* Return a {@code RequestPredicate} that tests the request's headers
|
||||
* against the given headers predicate.
|
||||
* @param headersPredicate a predicate that tests against the request headers
|
||||
* @return a predicate that tests against the given header predicate
|
||||
*/
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Default implementation of {@link RouterFunctions.Builder}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 5.1
|
||||
*/
|
||||
@@ -40,6 +41,7 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
|
||||
private List<HandlerFilterFunction<ServerResponse, ServerResponse>> filterFunctions = new ArrayList<>();
|
||||
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder add(RouterFunction<ServerResponse> routerFunction) {
|
||||
Assert.notNull(routerFunction, "RouterFunction must not be null");
|
||||
@@ -49,6 +51,7 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
|
||||
private RouterFunctions.Builder add(RequestPredicate predicate,
|
||||
HandlerFunction<ServerResponse> handlerFunction) {
|
||||
|
||||
this.routerFunctions.add(RouterFunctions.route(predicate, handlerFunction));
|
||||
return this;
|
||||
}
|
||||
@@ -61,6 +64,7 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
@Override
|
||||
public RouterFunctions.Builder GET(String pattern, RequestPredicate predicate,
|
||||
HandlerFunction<ServerResponse> handlerFunction) {
|
||||
|
||||
return add(RequestPredicates.GET(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@@ -72,6 +76,7 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
@Override
|
||||
public RouterFunctions.Builder HEAD(String pattern, RequestPredicate predicate,
|
||||
HandlerFunction<ServerResponse> handlerFunction) {
|
||||
|
||||
return add(RequestPredicates.HEAD(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@@ -83,6 +88,7 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
@Override
|
||||
public RouterFunctions.Builder POST(String pattern, RequestPredicate predicate,
|
||||
HandlerFunction<ServerResponse> handlerFunction) {
|
||||
|
||||
return add(RequestPredicates.POST(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@@ -94,6 +100,7 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
@Override
|
||||
public RouterFunctions.Builder PUT(String pattern, RequestPredicate predicate,
|
||||
HandlerFunction<ServerResponse> handlerFunction) {
|
||||
|
||||
return add(RequestPredicates.PUT(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@@ -105,6 +112,7 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
@Override
|
||||
public RouterFunctions.Builder PATCH(String pattern, RequestPredicate predicate,
|
||||
HandlerFunction<ServerResponse> handlerFunction) {
|
||||
|
||||
return add(RequestPredicates.PATCH(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@@ -116,6 +124,7 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
@Override
|
||||
public RouterFunctions.Builder DELETE(String pattern, RequestPredicate predicate,
|
||||
HandlerFunction<ServerResponse> handlerFunction) {
|
||||
|
||||
return add(RequestPredicates.DELETE(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@@ -127,6 +136,7 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
@Override
|
||||
public RouterFunctions.Builder OPTIONS(String pattern, RequestPredicate predicate,
|
||||
HandlerFunction<ServerResponse> handlerFunction) {
|
||||
|
||||
return add(RequestPredicates.OPTIONS(pattern).and(predicate), handlerFunction);
|
||||
}
|
||||
|
||||
@@ -149,7 +159,6 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
RouterFunctionBuilder nestedBuilder = new RouterFunctionBuilder();
|
||||
builderConsumer.accept(nestedBuilder);
|
||||
RouterFunction<ServerResponse> nestedRoute = nestedBuilder.build();
|
||||
|
||||
this.routerFunctions.add(RouterFunctions.nest(predicate, nestedRoute));
|
||||
return this;
|
||||
}
|
||||
@@ -161,7 +170,6 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
Assert.notNull(routerFunctionSupplier, "RouterFunction Supplier must not be null");
|
||||
|
||||
RouterFunction<ServerResponse> nestedRoute = routerFunctionSupplier.get();
|
||||
|
||||
this.routerFunctions.add(RouterFunctions.nest(predicate, nestedRoute));
|
||||
return this;
|
||||
}
|
||||
@@ -169,12 +177,14 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
@Override
|
||||
public RouterFunctions.Builder path(String pattern,
|
||||
Consumer<RouterFunctions.Builder> builderConsumer) {
|
||||
|
||||
return nest(RequestPredicates.path(pattern), builderConsumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunctions.Builder path(String pattern,
|
||||
Supplier<RouterFunction<ServerResponse>> routerFunctionSupplier) {
|
||||
|
||||
return nest(RequestPredicates.path(pattern), routerFunctionSupplier);
|
||||
}
|
||||
|
||||
@@ -195,6 +205,7 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
@Override
|
||||
public RouterFunctions.Builder after(
|
||||
BiFunction<ServerRequest, ServerResponse, ServerResponse> responseProcessor) {
|
||||
|
||||
Assert.notNull(responseProcessor, "ResponseProcessor must not be null");
|
||||
return filter((request, next) -> next.handle(request)
|
||||
.map(serverResponse -> responseProcessor.apply(request, serverResponse)));
|
||||
@@ -212,9 +223,9 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Throwable> RouterFunctions.Builder onError(
|
||||
Class<T> exceptionType,
|
||||
public <T extends Throwable> RouterFunctions.Builder onError(Class<T> exceptionType,
|
||||
BiFunction<? super T, ServerRequest, Mono<ServerResponse>> responseProvider) {
|
||||
|
||||
Assert.notNull(exceptionType, "ExceptionType must not be null");
|
||||
Assert.notNull(responseProvider, "ResponseProvider must not be null");
|
||||
|
||||
@@ -224,7 +235,6 @@ class RouterFunctionBuilder implements RouterFunctions.Builder {
|
||||
|
||||
@Override
|
||||
public RouterFunction<ServerResponse> build() {
|
||||
|
||||
RouterFunction<ServerResponse> result = this.routerFunctions.stream()
|
||||
.reduce(RouterFunction::and)
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
|
||||
@@ -289,7 +289,7 @@ public interface ServerRequest {
|
||||
ServerWebExchange exchange();
|
||||
|
||||
|
||||
// Static methods
|
||||
// Static builder methods
|
||||
|
||||
/**
|
||||
* Create a new {@code ServerRequest} based on the given {@code ServerWebExchange} and
|
||||
|
||||
@@ -82,6 +82,14 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
||||
.forEach(entry -> this.pathPrefixes.put(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* The configured path prefixes as a read-only, possibly empty map.
|
||||
* @since 5.1
|
||||
*/
|
||||
public Map<String, Predicate<Class<?>>> getPathPrefixes() {
|
||||
return Collections.unmodifiableMap(this.pathPrefixes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link RequestedContentTypeResolver} to use to determine requested
|
||||
* media types. If not set, the default constructor is used.
|
||||
@@ -91,6 +99,13 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
||||
this.contentTypeResolver = contentTypeResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured {@link RequestedContentTypeResolver}.
|
||||
*/
|
||||
public RequestedContentTypeResolver getContentTypeResolver() {
|
||||
return this.contentTypeResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEmbeddedValueResolver(StringValueResolver resolver) {
|
||||
this.embeddedValueResolver = resolver;
|
||||
@@ -106,21 +121,6 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The configured path prefixes as a read-only, possibly empty map.
|
||||
* @since 5.1
|
||||
*/
|
||||
public Map<String, Predicate<Class<?>>> getPathPrefixes() {
|
||||
return Collections.unmodifiableMap(this.pathPrefixes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured {@link RequestedContentTypeResolver}.
|
||||
*/
|
||||
public RequestedContentTypeResolver getContentTypeResolver() {
|
||||
return this.contentTypeResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* Expects a handler to have a type-level @{@link Controller} annotation.
|
||||
|
||||
@@ -134,7 +134,7 @@ public class HandshakeInfo {
|
||||
|
||||
/**
|
||||
* A log prefix used in the handshake to correlate log messages, if any.
|
||||
* @return a log prefix, or {@code null}
|
||||
* @return a log prefix, or {@code null} if not specified
|
||||
* @since 5.1
|
||||
*/
|
||||
@Nullable
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.reactive.socket.client;
|
||||
|
||||
import java.net.URI;
|
||||
@@ -25,6 +26,7 @@ import reactor.netty.http.websocket.WebsocketInbound;
|
||||
|
||||
import org.springframework.core.io.buffer.NettyDataBufferFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.reactive.socket.HandshakeInfo;
|
||||
import org.springframework.web.reactive.socket.WebSocketHandler;
|
||||
@@ -57,6 +59,7 @@ public class ReactorNettyWebSocketClient implements WebSocketClient {
|
||||
* @since 5.1
|
||||
*/
|
||||
public ReactorNettyWebSocketClient(HttpClient httpClient) {
|
||||
Assert.notNull(httpClient, "HttpClient is required");
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user