Polishing

This commit is contained in:
Juergen Hoeller 2018-07-25 14:16:02 +02:00
parent 3899b7a909
commit 3881a4aded
39 changed files with 133 additions and 147 deletions

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.core.codec;
import java.util.Collections;
@ -34,7 +35,6 @@ public abstract class Hints {
/**
* Name of hint exposing a prefix to use for correlating log messages.
* @since 5.1
*/
public static final String LOG_PREFIX_HINT = Log.class.getName() + ".PREFIX";
@ -42,7 +42,6 @@ public abstract class Hints {
* Name of boolean hint whether to avoid logging data either because it's
* potentially sensitive, or because it has been logged by a composite
* encoder, e.g. for multipart requests.
* @since 5.1
*/
public static final String SUPPRESS_LOGGING_HINT = Log.class.getName() + ".SUPPRESS_LOGGING";
@ -91,7 +90,7 @@ public abstract class Hints {
* @return the log prefix
*/
public static String getLogPrefix(@Nullable Map<String, Object> hints) {
return hints != null ? (String) hints.getOrDefault(LOG_PREFIX_HINT, "") : "";
return (hints != null ? (String) hints.getOrDefault(LOG_PREFIX_HINT, "") : "");
}
/**
@ -100,7 +99,7 @@ public abstract class Hints {
* @return whether logging of data is allowed
*/
public static boolean isLoggingSuppressed(@Nullable Map<String, Object> hints) {
return hints != null && (boolean) hints.getOrDefault(SUPPRESS_LOGGING_HINT, false);
return (hints != null && (boolean) hints.getOrDefault(SUPPRESS_LOGGING_HINT, false));
}
/**

View File

@ -39,30 +39,26 @@ public interface Profiles {
*/
boolean matches(Predicate<String> activeProfiles);
/**
* Create a new {@link Profiles} instance that checks for matches against
* the given <em>profile strings</em>.
*
* <p>The returned instance will {@linkplain Profiles#matches(Predicate) match}
* if any one of the given profile strings matches.
*
* <p>A profile string may contain a simple profile name (for example
* {@code "production"}) or a profile expression. A profile expression allows
* for more complicated profile logic to be expressed, for example
* {@code "production & cloud"}.
*
* <p>The following operators are supported in profile expressions:
* <ul>
* <li>{@code !} - A logical <em>not</em> of the profile</li>
* <li>{@code &} - A logical <em>and</em> of the profiles</li>
* <li>{@code |} - A logical <em>or</em> of the profiles</li>
* </ul>
*
* <p>Please note that the {@code &} and {@code |} operators may not be mixed
* without using parentheses. For example {@code "a & b | c"} is not a valid
* expression; it must be expressed as {@code "(a & b) | c"} or
* {@code "a & (b | c)"}.
*
* @param profiles the <em>profile strings</em> to include
* @return a new {@link Profiles} instance
*/

View File

@ -129,11 +129,6 @@ public abstract class AbstractBrokerMessageHandler
return this.destinationPrefixes;
}
@Override
public void setApplicationEventPublisher(@Nullable ApplicationEventPublisher publisher) {
this.eventPublisher = publisher;
}
/**
* Whether the client must receive messages in the order of publication.
* <p>By default messages sent to the {@code "clientOutboundChannel"} may
@ -159,6 +154,11 @@ public abstract class AbstractBrokerMessageHandler
return this.preservePublishOrder;
}
@Override
public void setApplicationEventPublisher(@Nullable ApplicationEventPublisher publisher) {
this.eventPublisher = publisher;
}
@Nullable
public ApplicationEventPublisher getApplicationEventPublisher() {
return this.eventPublisher;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.mock.web.server;
import reactor.core.publisher.Mono;
@ -38,7 +39,6 @@ import org.springframework.web.server.session.WebSessionManager;
*/
public final class MockServerWebExchange extends DefaultServerWebExchange {
private MockServerWebExchange(MockServerHttpRequest request, WebSessionManager sessionManager) {
super(request, new MockServerHttpResponse(), sessionManager,
ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
@ -101,12 +101,10 @@ public final class MockServerWebExchange extends DefaultServerWebExchange {
@Nullable
private WebSessionManager sessionManager;
public Builder(MockServerHttpRequest request) {
this.request = request;
}
/**
* Set the session to use for the exchange.
* <p>This method is mutually exclusive with

View File

@ -123,16 +123,14 @@ public final class MockMvc {
this.defaultResultHandlers = resultHandlers;
}
/**
* Return the underlying {@link DispatcherServlet} instance that this
* {@code MockMvc} was initialized with.
* <p>This is intended for use in custom request processing scenario where
* a request handling component happens to delegate to the
* {@code DispatcherServlet} at runtime and therefore needs to be injected
* with it.
* <p>For most processing scenarios, simply use {@link MockMvc#perform}, or
* if you need to configure the {@code DispatcherServlet}, provide a
* <p>This is intended for use in custom request processing scenario where a
* request handling component happens to delegate to the {@code DispatcherServlet}
* at runtime and therefore needs to be injected with it.
* <p>For most processing scenarios, simply use {@link MockMvc#perform},
* or if you need to configure the {@code DispatcherServlet}, provide a
* {@link DispatcherServletCustomizer} to the {@code MockMvcBuilder}.
* @since 5.1
*/

View File

@ -49,7 +49,6 @@ package org.springframework.test.web.servlet;
@FunctionalInterface
public interface ResultMatcher {
/**
* Assert the result of an executed request.
* @param result the result of the executed request

View File

@ -758,8 +758,6 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
* @see <a href="https://tools.ietf.org/html/rfc6750">RFC 6750</a>
*/
public void setBearerAuth(String token) {
Assert.notNull(token, "Token must not be null");
set(AUTHORIZATION, "Bearer " + token);
}

View File

@ -59,8 +59,8 @@ public abstract class HttpLogging {
/**
* Wrap the given primary logger with a composite logger that delegates to
* it or to the fallback logger "org.springframework.web.HttpLogging", if
* the primary is not enabled.
* it or to the fallback logger "org.springframework.web.HttpLogging",
* if the primary is not enabled.
* @param primaryLogger the primary logger to use
* @return the resulting composite logger
*/

View File

@ -122,6 +122,7 @@ public final class ResponseCookie extends HttpCookie {
return this.sameSite;
}
@Override
public boolean equals(Object other) {
if (this == other) {

View File

@ -29,6 +29,7 @@ import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.http.HttpMethod;
import org.springframework.util.Assert;
/**
* Jetty ReactiveStreams HttpClient implementation of {@link ClientHttpConnector}.
@ -60,6 +61,7 @@ public class JettyClientHttpConnector implements ClientHttpConnector, SmartLifec
* Create a Jetty {@link ClientHttpConnector} with the given {@link HttpClient}.
*/
public JettyClientHttpConnector(HttpClient httpClient) {
Assert.notNull(httpClient, "HttpClient is required");
this.httpClient = httpClient;
}
@ -68,6 +70,7 @@ public class JettyClientHttpConnector implements ClientHttpConnector, SmartLifec
this.bufferFactory = bufferFactory;
}
@Override
public int getPhase() {
return Integer.MAX_VALUE;
@ -110,6 +113,7 @@ public class JettyClientHttpConnector implements ClientHttpConnector, SmartLifec
callback.run();
}
@Override
public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri,
Function<? super ClientHttpRequest, Mono<Void>> requestCallback) {

View File

@ -27,7 +27,6 @@ import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseCookie;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@ -47,8 +46,6 @@ class JettyClientHttpResponse implements ClientHttpResponse {
public JettyClientHttpResponse(ReactiveResponse reactiveResponse, Publisher<DataBuffer> content) {
Assert.notNull(reactiveResponse, "reactiveResponse should not be null");
Assert.notNull(content, "content should not be null");
this.reactiveResponse = reactiveResponse;
this.content = Flux.from(content);
}

View File

@ -28,6 +28,7 @@ import reactor.netty.http.client.HttpClientRequest;
import reactor.netty.http.client.HttpClientResponse;
import org.springframework.http.HttpMethod;
import org.springframework.util.Assert;
/**
* Reactor-Netty implementation of {@link ClientHttpConnector}.
@ -56,6 +57,7 @@ public class ReactorClientHttpConnector implements ClientHttpConnector {
* @since 5.1
*/
public ReactorClientHttpConnector(HttpClient httpClient) {
Assert.notNull(httpClient, "HttpClient is required");
this.httpClient = httpClient;
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.http.codec;
import org.apache.commons.logging.Log;

View File

@ -458,8 +458,7 @@ public class Jackson2ObjectMapperBuilder {
* @see com.fasterxml.jackson.annotation.PropertyAccessor
* @see com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility
*/
public Jackson2ObjectMapperBuilder visibility(PropertyAccessor accessor,
JsonAutoDetect.Visibility visibility) {
public Jackson2ObjectMapperBuilder visibility(PropertyAccessor accessor, JsonAutoDetect.Visibility visibility) {
this.visibilities.put(accessor, visibility);
return this;
}

View File

@ -83,8 +83,8 @@ public class ProtobufJsonFormatHttpMessageConverter extends ProtobufHttpMessageC
* @param parser the JSON parser configuration
* @param printer the JSON printer configuration
* @param registryInitializer an initializer for message extensions
* @deprecated as of Spring Framework 5.1, use
* {@link #ProtobufJsonFormatHttpMessageConverter(JsonFormat.Parser, JsonFormat.Printer, ExtensionRegistry)} instead
* @deprecated as of 5.1, in favor of
* {@link #ProtobufJsonFormatHttpMessageConverter(JsonFormat.Parser, JsonFormat.Printer, ExtensionRegistry)}
*/
@Deprecated
public ProtobufJsonFormatHttpMessageConverter(@Nullable JsonFormat.Parser parser,

View File

@ -39,8 +39,8 @@ import org.springframework.util.MultiValueMap;
public interface ServerHttpRequest extends HttpRequest, ReactiveHttpInputMessage {
/**
* Return an id that represents the underlying connection, if available, or
* the request, for the purpose of correlating log messages.
* Return an id that represents the underlying connection, if available,
* or the request for the purpose of correlating log messages.
* @since 5.1
* @see org.springframework.web.server.ServerWebExchange#getLogPrefix()
*/

View File

@ -69,10 +69,6 @@ public class FormContentFilter extends OncePerRequestFilter {
this.formConverter = converter;
}
public FormHttpMessageConverter getFormConverter() {
return this.formConverter;
}
/**
* The default character set to use for reading form data.
* This is a shortcut for:<br>

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.method;
import java.lang.annotation.Annotation;
@ -93,10 +94,12 @@ public final class HandlerTypePredicate implements Predicate<Class<?>> {
}
private boolean hasSelectors() {
return !this.basePackages.isEmpty() || !this.assignableTypes.isEmpty() || !this.annotations.isEmpty();
return (!this.basePackages.isEmpty() || !this.assignableTypes.isEmpty() || !this.annotations.isEmpty());
}
// Static factory methods
/**
* {@code Predicate} that applies to any handlers.
*/
@ -158,7 +161,6 @@ public final class HandlerTypePredicate implements Predicate<Class<?>> {
private final List<Class<? extends Annotation>> annotations = new ArrayList<>();
/**
* Match handlers declared under a base package, e.g. "org.example".
* @param packages one or more base package classes

View File

@ -97,9 +97,9 @@ public class UnsupportedMediaTypeStatusException extends ResponseStatusException
/**
* 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
* <p>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

View File

@ -62,14 +62,12 @@ public class ResponseStatusExceptionHandler implements WebExceptionHandler {
@Override
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
HttpStatus status = resolveStatus(ex);
if (status == null || !exchange.getResponse().setStatusCode(status)) {
return Mono.error(ex);
}
// Mirrors AbstractHandlerExceptionResolver in spring-webmvc..
// Mirrors AbstractHandlerExceptionResolver in spring-webmvc...
String logPrefix = exchange.getLogPrefix();
if (this.warnLogger != null && this.warnLogger.isWarnEnabled()) {
this.warnLogger.warn(logPrefix + formatError(ex, exchange.getRequest()), ex);

View File

@ -55,10 +55,10 @@ import org.springframework.util.MimeTypeUtils;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.springframework.core.ResolvableType.forClass;
/**
* Unit tests for {@link BaseDefaultCodecs}.
*
* @author Rossen Stoyanchev
* @author Sebastien Deleuze
*/
@ -285,8 +285,7 @@ public class CodecConfigurerTests {
@Test
public void protobufWriterOverride() {
ProtobufEncoder encoder = new ProtobufEncoder();
ProtobufHttpMessageWriter messageWriter = new ProtobufHttpMessageWriter(encoder);
this.configurer.defaultCodecs().protobufWriter(messageWriter);
this.configurer.defaultCodecs().protobufEncoder(encoder);
assertSame(encoder, this.configurer.getWriters().stream()
.filter(writer -> writer instanceof EncoderHttpMessageWriter)
@ -311,14 +310,14 @@ public class CodecConfigurerTests {
private void assertStringDecoder(Decoder<?> decoder, boolean textOnly) {
assertEquals(StringDecoder.class, decoder.getClass());
assertTrue(decoder.canDecode(forClass(String.class), MimeTypeUtils.TEXT_PLAIN));
assertEquals(!textOnly, decoder.canDecode(forClass(String.class), MediaType.TEXT_EVENT_STREAM));
assertTrue(decoder.canDecode(ResolvableType.forClass(String.class), MimeTypeUtils.TEXT_PLAIN));
assertEquals(!textOnly, decoder.canDecode(ResolvableType.forClass(String.class), MediaType.TEXT_EVENT_STREAM));
}
private void assertStringEncoder(Encoder<?> encoder, boolean textOnly) {
assertEquals(CharSequenceEncoder.class, encoder.getClass());
assertTrue(encoder.canEncode(forClass(String.class), MimeTypeUtils.TEXT_PLAIN));
assertEquals(!textOnly, encoder.canEncode(forClass(String.class), MediaType.TEXT_EVENT_STREAM));
assertTrue(encoder.canEncode(ResolvableType.forClass(String.class), MimeTypeUtils.TEXT_PLAIN));
assertEquals(!textOnly, encoder.canEncode(ResolvableType.forClass(String.class), MediaType.TEXT_EVENT_STREAM));
}
@ -330,7 +329,6 @@ public class CodecConfigurerTests {
}
private static class TestDefaultCodecs extends BaseDefaultCodecs {
}
}

View File

@ -81,6 +81,7 @@ public class PathMatchConfigurer {
return this;
}
@Nullable
protected Boolean isUseTrailingSlashMatch() {
return this.trailingSlashMatch;

View File

@ -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) {
}

View File

@ -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

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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
*/

View File

@ -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);

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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;
}

View File

@ -172,7 +172,7 @@ import org.springframework.web.util.UrlPathHelper;
*/
public class WebMvcConfigurationSupport implements ApplicationContextAware, ServletContextAware {
private static boolean romePresent;
private static final boolean romePresent;
private static final boolean jaxb2Present;

View File

@ -122,6 +122,14 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
this.pathPrefixes = Collections.unmodifiableMap(new LinkedHashMap<>(prefixes));
}
/**
* The configured path prefixes as a read-only, possibly empty map.
* @since 5.1
*/
public Map<String, Predicate<Class<?>>> getPathPrefixes() {
return this.pathPrefixes;
}
/**
* Set the {@link ContentNegotiationManager} to use to determine requested media types.
* If not set, the default constructor is used.
@ -131,6 +139,13 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
this.contentNegotiationManager = contentNegotiationManager;
}
/**
* Return the configured {@link ContentNegotiationManager}.
*/
public ContentNegotiationManager getContentNegotiationManager() {
return this.contentNegotiationManager;
}
@Override
public void setEmbeddedValueResolver(StringValueResolver resolver) {
this.embeddedValueResolver = resolver;
@ -171,21 +186,6 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
return this.useTrailingSlashMatch;
}
/**
* The configured path prefixes as a read-only, possibly empty map.
* @since 5.1
*/
public Map<String, Predicate<Class<?>>> getPathPrefixes() {
return this.pathPrefixes;
}
/**
* Return the configured {@link ContentNegotiationManager}.
*/
public ContentNegotiationManager getContentNegotiationManager() {
return this.contentNegotiationManager;
}
/**
* Return the file extensions to use for suffix pattern matching.
*/

View File

@ -108,7 +108,7 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport {
private boolean hasScheme(String link) {
int schemeIndex = link.indexOf(':');
return (schemeIndex > 0 && !link.substring(0, schemeIndex).contains("/")) || link.indexOf("//") == 0;
return ((schemeIndex > 0 && !link.substring(0, schemeIndex).contains("/")) || link.indexOf("//") == 0);
}
@ -167,9 +167,7 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport {
* Invoked after a keyword match, after whitespaces removed, and when
* the next char is neither a single nor double quote.
*/
protected abstract int extractLink(int index, String content,
SortedSet<ContentChunkInfo> linksToAdd);
protected abstract int extractLink(int index, String content, SortedSet<ContentChunkInfo> linksToAdd);
}

View File

@ -149,7 +149,9 @@ public class EncodedResourceResolver extends AbstractResourceResolver {
}
}
catch (IOException ex) {
logger.trace("No " + coding + " resource for [" + resource.getFilename() + "]", ex);
if (logger.isTraceEnabled()) {
logger.trace("No " + coding + " resource for [" + resource.getFilename() + "]", ex);
}
}
}
}
@ -188,7 +190,6 @@ public class EncodedResourceResolver extends AbstractResourceResolver {
private final Resource encoded;
EncodedResource(Resource original, String coding, String extension) throws IOException {
this.original = original;
this.coding = coding;

View File

@ -155,17 +155,13 @@ public class WebSocketTransportRegistration {
}
/**
* Set the maximum time allowed in milliseconds after the WebSocket
* connection is established and before the first sub-protocol message is
* received.
*
* Set the maximum time allowed in milliseconds after the WebSocket connection
* is established and before the first sub-protocol message is received.
* <p>This handler is for WebSocket connections that use a sub-protocol.
* Therefore, we expect the client to send at least one sub-protocol message
* in the beginning, or else we assume the connection isn't doing well, e.g.
* proxy issue, slow network, and can be closed.
*
* <p>By default this is set to {@code 60,000} (1 minute).
*
* @param timeToFirstMessage the maximum time allowed in milliseconds
* @since 5.1
*/

View File

@ -222,17 +222,13 @@ public class SubProtocolWebSocketHandler
}
/**
* Set the maximum time allowed in milliseconds after the WebSocket
* connection is established and before the first sub-protocol message is
* received.
*
* Set the maximum time allowed in milliseconds after the WebSocket connection
* is established and before the first sub-protocol message is received.
* <p>This handler is for WebSocket connections that use a sub-protocol.
* Therefore, we expect the client to send at least one sub-protocol message
* in the beginning, or else we assume the connection isn't doing well, e.g.
* proxy issue, slow network, and can be closed.
*
* <p>By default this is set to {@code 60,000} (1 minute).
*
* @param timeToFirstMessage the maximum time allowed in milliseconds
* @since 5.1
* @see #checkSessions()