Browse Source

Polishing

pull/1916/head
Juergen Hoeller 7 years ago
parent
commit
fd75600c26
  1. 2
      spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java
  2. 25
      spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java
  3. 4
      spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java
  4. 2
      spring-web/src/main/java/org/springframework/web/server/ServerWebExchange.java
  5. 22
      spring-web/src/main/java/org/springframework/web/server/WebSession.java
  6. 41
      spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java
  7. 4
      spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java
  8. 6
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java
  9. 21
      spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java

2
spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java vendored

@ -149,7 +149,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc @@ -149,7 +149,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc
@Override
protected <T> T getBean(Class<T> type) {
Assert.state(this.beanFactory != null, "BeanFactory required for resolution of [" + type + "]");
Assert.state(this.beanFactory != null, () -> "BeanFactory required for resolution of [" + type + "]");
try {
return this.beanFactory.getBean(type);
}

25
spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java

@ -443,12 +443,12 @@ public class AnnotatedElementUtils { @@ -443,12 +443,12 @@ public class AnnotatedElementUtils {
* @param annotationType the annotation type to find (never {@code null})
* @return the set of all merged repeatable {@code Annotations} found,
* or an empty set if none were found
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
* is {@code null}, or if the container type cannot be resolved
* @since 4.3
* @see #getMergedAnnotation(AnnotatedElement, Class)
* @see #getAllMergedAnnotations(AnnotatedElement, Class)
* @see #getMergedRepeatableAnnotations(AnnotatedElement, Class, Class)
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
* is {@code null}, or if the container type cannot be resolved
*/
public static <A extends Annotation> Set<A> getMergedRepeatableAnnotations(AnnotatedElement element,
Class<A> annotationType) {
@ -474,13 +474,13 @@ public class AnnotatedElementUtils { @@ -474,13 +474,13 @@ public class AnnotatedElementUtils {
* {@link java.lang.annotation.Repeatable}
* @return the set of all merged repeatable {@code Annotations} found,
* or an empty set if none were found
* @since 4.3
* @see #getMergedAnnotation(AnnotatedElement, Class)
* @see #getAllMergedAnnotations(AnnotatedElement, Class)
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
* is {@code null}, or if the container type cannot be resolved
* @throws AnnotationConfigurationException if the supplied {@code containerType}
* is not a valid container annotation for the supplied {@code annotationType}
* @since 4.3
* @see #getMergedAnnotation(AnnotatedElement, Class)
* @see #getAllMergedAnnotations(AnnotatedElement, Class)
*/
public static <A extends Annotation> Set<A> getMergedRepeatableAnnotations(AnnotatedElement element,
Class<A> annotationType, @Nullable Class<? extends Annotation> containerType) {
@ -729,12 +729,12 @@ public class AnnotatedElementUtils { @@ -729,12 +729,12 @@ public class AnnotatedElementUtils {
* @param annotationType the annotation type to find (never {@code null})
* @return the set of all merged repeatable {@code Annotations} found,
* or an empty set if none were found
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
* is {@code null}, or if the container type cannot be resolved
* @since 4.3
* @see #findMergedAnnotation(AnnotatedElement, Class)
* @see #findAllMergedAnnotations(AnnotatedElement, Class)
* @see #findMergedRepeatableAnnotations(AnnotatedElement, Class, Class)
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
* is {@code null}, or if the container type cannot be resolved
*/
public static <A extends Annotation> Set<A> findMergedRepeatableAnnotations(AnnotatedElement element,
Class<A> annotationType) {
@ -760,13 +760,13 @@ public class AnnotatedElementUtils { @@ -760,13 +760,13 @@ public class AnnotatedElementUtils {
* {@link java.lang.annotation.Repeatable}
* @return the set of all merged repeatable {@code Annotations} found,
* or an empty set if none were found
* @since 4.3
* @see #findMergedAnnotation(AnnotatedElement, Class)
* @see #findAllMergedAnnotations(AnnotatedElement, Class)
* @throws IllegalArgumentException if the {@code element} or {@code annotationType}
* is {@code null}, or if the container type cannot be resolved
* @throws AnnotationConfigurationException if the supplied {@code containerType}
* is not a valid container annotation for the supplied {@code annotationType}
* @since 4.3
* @see #findMergedAnnotation(AnnotatedElement, Class)
* @see #findAllMergedAnnotations(AnnotatedElement, Class)
*/
public static <A extends Annotation> Set<A> findMergedRepeatableAnnotations(AnnotatedElement element,
Class<A> annotationType, @Nullable Class<? extends Annotation> containerType) {
@ -1280,9 +1280,9 @@ public class AnnotatedElementUtils { @@ -1280,9 +1280,9 @@ public class AnnotatedElementUtils {
* annotation for the supplied repeatable {@code annotationType} (i.e.,
* that it declares a {@code value} attribute that holds an array of the
* {@code annotationType}).
* @since 4.3
* @throws AnnotationConfigurationException if the supplied {@code containerType}
* is not a valid container annotation for the supplied {@code annotationType}
* @since 4.3
*/
private static void validateContainerType(Class<? extends Annotation> annotationType,
Class<? extends Annotation> containerType) {
@ -1305,9 +1305,6 @@ public class AnnotatedElementUtils { @@ -1305,9 +1305,6 @@ public class AnnotatedElementUtils {
}
}
/**
* @since 4.3
*/
private static <A extends Annotation> Set<A> postProcessAndSynthesizeAggregatedResults(AnnotatedElement element,
Class<A> annotationType, List<AnnotationAttributes> aggregatedResults) {

4
spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java

@ -147,7 +147,7 @@ class DefaultMvcResult implements MvcResult { @@ -147,7 +147,7 @@ class DefaultMvcResult implements MvcResult {
" was not set during the specified timeToWait=" + timeToWait);
}
Object result = this.asyncResult.get();
Assert.state(result != RESULT_NONE, "Async result for handler [" + this.handler + "] was not set");
Assert.state(result != RESULT_NONE, () -> "Async result for handler [" + this.handler + "] was not set");
return this.asyncResult.get();
}
@ -160,7 +160,7 @@ class DefaultMvcResult implements MvcResult { @@ -160,7 +160,7 @@ class DefaultMvcResult implements MvcResult {
try {
return this.asyncDispatchLatch.await(timeout, TimeUnit.MILLISECONDS);
}
catch (InterruptedException e) {
catch (InterruptedException ex) {
return false;
}
}

2
spring-web/src/main/java/org/springframework/web/server/ServerWebExchange.java

@ -80,7 +80,7 @@ public interface ServerWebExchange { @@ -80,7 +80,7 @@ public interface ServerWebExchange {
@SuppressWarnings("unchecked")
default <T> T getRequiredAttribute(String name) {
T value = getAttribute(name);
Assert.notNull(value, "Required attribute '" + name + "' is missing.");
Assert.notNull(value, () -> "Required attribute '" + name + "' is missing.");
return value;
}

22
spring-web/src/main/java/org/springframework/web/server/WebSession.java

@ -1,5 +1,5 @@ @@ -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.
@ -71,7 +71,7 @@ public interface WebSession { @@ -71,7 +71,7 @@ public interface WebSession {
@SuppressWarnings("unchecked")
default <T> T getRequiredAttribute(String name) {
T value = getAttribute(name);
Assert.notNull(value, "Required attribute '" + name + "' is missing.");
Assert.notNull(value, () -> "Required attribute '" + name + "' is missing.");
return value;
}
@ -116,13 +116,19 @@ public interface WebSession { @@ -116,13 +116,19 @@ public interface WebSession {
Mono<Void> invalidate();
/**
* Save the session persisting attributes (e.g. if stored remotely) and also
* sending the session id to the client if the session is new.
* <p>Note that a session must be started explicitly via {@link #start()} or
* implicitly by adding attributes or otherwise this method has no effect.
* Save the session through the {@code WebSessionStore} as follows:
* <ul>
* <li>If the session is new (i.e. created but never persisted), it must have
* been started explicitly via {@link #start()} or implicitly by adding
* attributes, or otherwise this method should have no effect.
* <li>If the session was retrieved through the {@code WebSessionStore},
* the implementation for this method must check whether the session was
* {@link #invalidate() invalidated} and if so return an error.
* </ul>
* <p>Note that this method is not intended for direct use by applications.
* Instead it is automatically invoked just before the response is
* committed.
* @return {@code Mono} to indicate completion with success or error
* <p>Typically this method should be automatically invoked just before the
* response is committed so applications don't have to by default.
*/
Mono<Void> save();

41
spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java

@ -42,20 +42,18 @@ import org.springframework.web.server.session.DefaultWebSessionManager; @@ -42,20 +42,18 @@ import org.springframework.web.server.session.DefaultWebSessionManager;
import org.springframework.web.server.session.WebSessionManager;
/**
* This builder has two purposes.
* This builder has two purposes:
*
* <p>One is to assemble a processing chain that consists of a target
* {@link WebHandler}, then decorated with a set of {@link WebFilter}'s, then
* further decorated with a set of {@link WebExceptionHandler}'s.
* <p>One is to assemble a processing chain that consists of a target {@link WebHandler},
* then decorated with a set of {@link WebFilter WebFilters}, then further decorated with
* a set of {@link WebExceptionHandler WebExceptionHandlers}.
*
* <p>The second purpose is to adapt the resulting processing chain to an
* {@link HttpHandler} -- the lowest level reactive HTTP handling abstraction,
* which can then be used with any of the supported runtimes. The adaptation
* is done with the help of {@link HttpWebHandlerAdapter}.
* <p>The second purpose is to adapt the resulting processing chain to an {@link HttpHandler}:
* the lowest-level reactive HTTP handling abstraction which can then be used with any of the
* supported runtimes. The adaptation is done with the help of {@link HttpWebHandlerAdapter}.
*
* <p>The processing chain can be assembled manually via builder methods, or
* detected from Spring configuration via
* {@link #applicationContext(ApplicationContext)}, or a mix of both.
* <p>The processing chain can be assembled manually via builder methods, or detected from
* a Spring {@link ApplicationContext} via {@link #applicationContext}, or a mix of both.
*
* @author Rossen Stoyanchev
* @author Sebastien Deleuze
@ -240,13 +238,12 @@ public class WebHttpHandlerBuilder { @@ -240,13 +238,12 @@ public class WebHttpHandlerBuilder {
}
/**
* Whether a {@code WebSessionManager} is configured or not, either
* detected from an {@code ApplicationContext} or explicitly configured via
* {@link #sessionManager(WebSessionManager)}.
* Whether a {@code WebSessionManager} is configured or not, either detected from an
* {@code ApplicationContext} or explicitly configured via {@link #sessionManager}.
* @since 5.0.9
*/
public boolean hasSessionManager() {
return this.sessionManager != null;
return (this.sessionManager != null);
}
/**
@ -260,13 +257,12 @@ public class WebHttpHandlerBuilder { @@ -260,13 +257,12 @@ public class WebHttpHandlerBuilder {
/**
* Whether a {@code ServerCodecConfigurer} is configured or not, either
* detected from an {@code ApplicationContext} or explicitly configured via
* {@link #codecConfigurer(ServerCodecConfigurer)}.
* Whether a {@code ServerCodecConfigurer} is configured or not, either detected from an
* {@code ApplicationContext} or explicitly configured via {@link #codecConfigurer}.
* @since 5.0.9
*/
public boolean hasCodecConfigurer() {
return this.codecConfigurer != null;
return (this.codecConfigurer != null);
}
/**
@ -280,13 +276,12 @@ public class WebHttpHandlerBuilder { @@ -280,13 +276,12 @@ public class WebHttpHandlerBuilder {
}
/**
* Whether a {@code LocaleContextResolver} is configured or not, either
* detected from an {@code ApplicationContext} or explicitly configured via
* {@link #localeContextResolver(LocaleContextResolver)}.
* Whether a {@code LocaleContextResolver} is configured or not, either detected from an
* {@code ApplicationContext} or explicitly configured via {@link #localeContextResolver}.
* @since 5.0.9
*/
public boolean hasLocaleContextResolver() {
return this.localeContextResolver != null;
return (this.localeContextResolver != null);
}

4
spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java

@ -244,7 +244,7 @@ public class RedirectView extends AbstractUrlBasedView { @@ -244,7 +244,7 @@ public class RedirectView extends AbstractUrlBasedView {
while (found) {
String name = matcher.group(1);
Object value = (model.containsKey(name) ? model.get(name) : uriVariables.get(name));
Assert.notNull(value, "No value for URI variable '" + name + "'");
Assert.notNull(value, () -> "No value for URI variable '" + name + "'");
result.append(targetUrl.substring(endLastMatch, matcher.start()));
result.append(encodeUriVariable(value.toString()));
endLastMatch = matcher.end();
@ -283,7 +283,7 @@ public class RedirectView extends AbstractUrlBasedView { @@ -283,7 +283,7 @@ public class RedirectView extends AbstractUrlBasedView {
}
/**
* Send a redirect back to the HTTP client
* Send a redirect back to the HTTP client.
* @param targetUrl the target URL to redirect to
* @param exchange current exchange
*/

6
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java

@ -111,8 +111,8 @@ class ReactiveTypeHandler { @@ -111,8 +111,8 @@ class ReactiveTypeHandler {
/**
* Process the given reactive return value and decide whether to adapt it
* to a {@link ResponseBodyEmitter} or a {@link DeferredResult}.
* @return an emitter for streaming or {@code null} if handled internally
* with a {@link DeferredResult}.
* @return an emitter for streaming, or {@code null} if handled internally
* with a {@link DeferredResult}
*/
@Nullable
public ResponseBodyEmitter handleValue(Object returnValue, MethodParameter returnType,
@ -120,7 +120,7 @@ class ReactiveTypeHandler { @@ -120,7 +120,7 @@ class ReactiveTypeHandler {
Assert.notNull(returnValue, "Expected return value");
ReactiveAdapter adapter = this.reactiveRegistry.getAdapter(returnValue.getClass());
Assert.state(adapter != null, "Unexpected return value: " + returnValue);
Assert.state(adapter != null, () -> "Unexpected return value: " + returnValue);
ResolvableType elementType = ResolvableType.forMethodParameter(returnType).getGeneric();
Class<?> elementClass = elementType.resolve(Object.class);

21
spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java

@ -1,5 +1,5 @@ @@ -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.
@ -120,7 +120,6 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser { @@ -120,7 +120,6 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
@Override
public BeanDefinition parse(Element element, ParserContext context) {
Object source = context.extractSource(element);
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
context.pushContainingComponent(compDefinition);
@ -151,19 +150,18 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser { @@ -151,19 +150,18 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
for (Element endpointElem : DomUtils.getChildElementsByTagName(element, "stomp-endpoint")) {
RuntimeBeanReference requestHandler = registerRequestHandler(endpointElem, stompHandler, context, source);
String pathAttribute = endpointElem.getAttribute("path");
Assert.state(StringUtils.hasText(pathAttribute), "Invalid <stomp-endpoint> (no path mapping)");
List<String> paths = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ","));
for (String path : paths) {
Assert.hasText(pathAttribute, "Invalid <stomp-endpoint> (no path mapping)");
for (String path : StringUtils.tokenizeToStringArray(pathAttribute, ",")) {
path = path.trim();
Assert.state(StringUtils.hasText(path), "Invalid <stomp-endpoint> path attribute: " + pathAttribute);
Assert.hasText(path, () -> "Invalid <stomp-endpoint> path attribute: " + pathAttribute);
if (DomUtils.getChildElementByTagName(endpointElem, "sockjs") != null) {
path = path.endsWith("/") ? path + "**" : path + "/**";
path = (path.endsWith("/") ? path + "**" : path + "/**");
}
urlMap.put(path, requestHandler);
}
}
Map<String, Object> scopeMap = Collections.<String, Object>singletonMap("websocket", new SimpSessionScope());
Map<String, Object> scopeMap = Collections.singletonMap("websocket", new SimpSessionScope());
RootBeanDefinition scopeConfigurer = new RootBeanDefinition(CustomScopeConfigurer.class);
scopeConfigurer.getPropertyValues().add("scopes", scopeMap);
registerBeanDefByName("webSocketScopeConfigurer", scopeConfigurer, context, source);
@ -243,6 +241,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser { @@ -243,6 +241,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
}
}
}
ConstructorArgumentValues cargs = new ConstructorArgumentValues();
if (executor != null) {
executor.getPropertyValues().add("threadNamePrefix", name + "-");
@ -250,6 +249,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser { @@ -250,6 +249,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
registerBeanDefByName(executorName, executor, context, source);
cargs.addIndexedArgumentValue(0, new RuntimeBeanReference(executorName));
}
RootBeanDefinition channelDef = new RootBeanDefinition(ExecutorSubscribableChannel.class, cargs, null);
ManagedList<? super Object> interceptors = new ManagedList<>();
if (element != null) {
@ -441,6 +441,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser { @@ -441,6 +441,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
// Should not happen
throw new IllegalStateException("Neither <simple-broker> nor <stomp-broker-relay> elements found.");
}
registerBeanDef(brokerDef, context, source);
return brokerDef;
}
@ -660,20 +661,20 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser { @@ -660,20 +661,20 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
context.registerComponent(new BeanComponentDefinition(beanDef, name));
}
private static class DecoratingFactoryBean implements FactoryBean<WebSocketHandler> {
private final WebSocketHandler handler;
private final List<WebSocketHandlerDecoratorFactory> factories;
private DecoratingFactoryBean(WebSocketHandler handler, List<WebSocketHandlerDecoratorFactory> factories) {
this.handler = handler;
this.factories = factories;
}
@Override
public WebSocketHandler getObject() throws Exception {
public WebSocketHandler getObject() {
WebSocketHandler result = this.handler;
for (WebSocketHandlerDecoratorFactory factory : this.factories) {
result = factory.decorate(result);

Loading…
Cancel
Save