diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java index a0243a3396..a54a3dd658 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -28,32 +28,26 @@ import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver; import org.springframework.util.StringValueResolver; /** - * {@link PlaceholderConfigurerSupport} subclass that resolves ${...} placeholders - * against {@link #setLocation local} {@link #setProperties properties} and/or system properties + * {@link PlaceholderConfigurerSupport} subclass that resolves ${...} placeholders against + * {@link #setLocation local} {@link #setProperties properties} and/or system properties * and environment variables. * *

As of Spring 3.1, {@link org.springframework.context.support.PropertySourcesPlaceholderConfigurer * PropertySourcesPlaceholderConfigurer} should be used preferentially over this implementation; it is - * more flexible through taking advantage of the {@link org.springframework.core.env.Environment Environment} and - * {@link org.springframework.core.env.PropertySource PropertySource} mechanisms also made available in Spring 3.1. + * more flexible through taking advantage of the {@link org.springframework.core.env.Environment} and + * {@link org.springframework.core.env.PropertySource} mechanisms also made available in Spring 3.1. * *

{@link PropertyPlaceholderConfigurer} is still appropriate for use when: *

* - *

Prior to Spring 3.1, the {@code } namespace element - * registered an instance of {@code PropertyPlaceholderConfigurer}. It will still do so if - * using the {@code spring-context-3.0.xsd} definition of the namespace. That is, you can preserve - * registration of {@code PropertyPlaceholderConfigurer} through the namespace, even if using Spring 3.1; - * simply do not update your {@code xsi:schemaLocation} and continue using the 3.0 XSD. - * * @author Juergen Hoeller * @author Chris Beams * @since 02.10.2003 @@ -92,7 +86,6 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport * Set the system property mode by the name of the corresponding constant, * e.g. "SYSTEM_PROPERTIES_MODE_OVERRIDE". * @param constantName name of the constant - * @throws java.lang.IllegalArgumentException if an invalid constant was specified * @see #setSystemPropertiesMode */ public void setSystemPropertiesModeName(String constantName) throws IllegalArgumentException { @@ -124,14 +117,9 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport * against system environment variables. Note that it is generally recommended * to pass external values in as JVM system properties: This can easily be * achieved in a startup script, even for existing environment variables. - *

NOTE: Access to environment variables does not work on the - * Sun VM 1.4, where the corresponding {@link System#getenv} support was - * disabled - before it eventually got re-enabled for the Sun VM 1.5. - * Please upgrade to 1.5 (or higher) if you intend to rely on the - * environment variable support. * @see #setSystemPropertiesMode - * @see java.lang.System#getProperty(String) - * @see java.lang.System#getenv(String) + * @see System#getProperty(String) + * @see System#getenv(String) */ public void setSearchSystemEnvironment(boolean searchSystemEnvironment) { this.searchSystemEnvironment = searchSystemEnvironment; @@ -264,7 +252,7 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport } - private class PropertyPlaceholderConfigurerResolver implements PlaceholderResolver { + private final class PropertyPlaceholderConfigurerResolver implements PlaceholderResolver { private final Properties props; @@ -274,7 +262,8 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport @Override public String resolvePlaceholder(String placeholderName) { - return PropertyPlaceholderConfigurer.this.resolvePlaceholder(placeholderName, props, systemPropertiesMode); + return PropertyPlaceholderConfigurer.this.resolvePlaceholder(placeholderName, + this.props, systemPropertiesMode); } } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java index 0b650df823..4e3162b72b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -164,7 +164,7 @@ abstract class AutowireUtils { * on the given method itself. *

For example, given a factory method with the following signature, if * {@code resolveReturnTypeForFactoryMethod()} is invoked with the reflected - * method for {@code creatProxy()} and an {@code Object[]} array containing + * method for {@code createProxy()} and an {@code Object[]} array containing * {@code MyService.class}, {@code resolveReturnTypeForFactoryMethod()} will * infer that the target return type is {@code MyService}. *

{@code public static  T createProxy(Class clazz)}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java index b3eb9b9e64..7d0fd9b629 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2019 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. @@ -79,12 +79,13 @@ public class ReplaceOverride extends MethodOverride { return true; } // If we get here, we need to insist on precise argument matching... - if (this.typeIdentifiers.size() != method.getParameterTypes().length) { + Class[] parameterTypes = method.getParameterTypes(); + if (this.typeIdentifiers.size() != parameterTypes.length) { return false; } for (int i = 0; i < this.typeIdentifiers.size(); i++) { String identifier = this.typeIdentifiers.get(i); - if (!method.getParameterTypes()[i].getName().contains(identifier)) { + if (!parameterTypes[i].getName().contains(identifier)) { return false; } } diff --git a/spring-beans/src/test/java/org/springframework/beans/DirectFieldAccessorTests.java b/spring-beans/src/test/java/org/springframework/beans/DirectFieldAccessorTests.java index e67bae0c26..bcce5a8677 100644 --- a/spring-beans/src/test/java/org/springframework/beans/DirectFieldAccessorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/DirectFieldAccessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2019 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. @@ -38,7 +38,7 @@ public class DirectFieldAccessorTests extends AbstractPropertyAccessorTests { @Test - public void withShadowedField() throws Exception { + public void withShadowedField() { final StringBuilder sb = new StringBuilder(); @SuppressWarnings("serial") diff --git a/spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java b/spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java index 384be563f6..9190f60615 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -20,7 +20,6 @@ import java.io.Serializable; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; - import org.junit.Test; import org.springframework.aop.interceptor.ExposeInvocationInterceptor; @@ -60,7 +59,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria } @Test - public void testProxyIsJustInterface() throws Throwable { + public void testProxyIsJustInterface() { TestBean raw = new TestBean(); raw.setAge(32); AdvisedSupport pc = new AdvisedSupport(ITestBean.class); @@ -73,7 +72,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria } @Test - public void testInterceptorIsInvokedWithNoTarget() throws Throwable { + public void testInterceptorIsInvokedWithNoTarget() { // Test return value final int age = 25; MethodInterceptor mi = (invocation -> age); @@ -87,7 +86,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria } @Test - public void testTargetCanGetInvocationWithPrivateClass() throws Throwable { + public void testTargetCanGetInvocationWithPrivateClass() { final ExposedInvocationTestBean expectedTarget = new ExposedInvocationTestBean() { @Override protected void assertions(MethodInvocation invocation) { @@ -128,7 +127,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria } @Test - public void testEqualsAndHashCodeDefined() throws Exception { + public void testEqualsAndHashCodeDefined() { AdvisedSupport as = new AdvisedSupport(Named.class); as.setTarget(new Person()); JdkDynamicAopProxy aopProxy = new JdkDynamicAopProxy(as); @@ -139,7 +138,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria } @Test // SPR-13328 - public void testVarargsWithEnumArray() throws Exception { + public void testVarargsWithEnumArray() { ProxyFactory proxyFactory = new ProxyFactory(new VarargTestBean()); VarargTestInterface proxy = (VarargTestInterface) proxyFactory.getProxy(); assertTrue(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C)); diff --git a/spring-core/src/main/java/org/springframework/core/BridgeMethodResolver.java b/spring-core/src/main/java/org/springframework/core/BridgeMethodResolver.java index 45bd0de486..955f9f50a0 100644 --- a/spring-core/src/main/java/org/springframework/core/BridgeMethodResolver.java +++ b/spring-core/src/main/java/org/springframework/core/BridgeMethodResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -226,8 +226,8 @@ public abstract class BridgeMethodResolver { if (bridgeMethod == bridgedMethod) { return true; } - return (Arrays.equals(bridgeMethod.getParameterTypes(), bridgedMethod.getParameterTypes()) && - bridgeMethod.getReturnType().equals(bridgedMethod.getReturnType())); + return (bridgeMethod.getReturnType().equals(bridgedMethod.getReturnType()) && + Arrays.equals(bridgeMethod.getParameterTypes(), bridgedMethod.getParameterTypes())); } } diff --git a/spring-core/src/main/java/org/springframework/core/ResolvableType.java b/spring-core/src/main/java/org/springframework/core/ResolvableType.java index 155236d50a..bff73147ab 100644 --- a/spring-core/src/main/java/org/springframework/core/ResolvableType.java +++ b/spring-core/src/main/java/org/springframework/core/ResolvableType.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -559,8 +559,8 @@ public class ResolvableType implements Serializable { } /** - * Return a {@link ResolvableType} for the specified nesting level. See - * {@link #getNested(int, Map)} for details. + * Return a {@link ResolvableType} for the specified nesting level. + * See {@link #getNested(int, Map)} for details. * @param nestingLevel the nesting level * @return the {@link ResolvableType} type, or {@code #NONE} */ @@ -569,11 +569,11 @@ public class ResolvableType implements Serializable { } /** - * Return a {@link ResolvableType} for the specified nesting level. The nesting level - * refers to the specific generic parameter that should be returned. A nesting level - * of 1 indicates this type; 2 indicates the first nested generic; 3 the second; and so - * on. For example, given {@code List>} level 1 refers to the - * {@code List}, level 2 the {@code Set}, and level 3 the {@code Integer}. + * Return a {@link ResolvableType} for the specified nesting level. + *

The nesting level refers to the specific generic parameter that should be returned. + * A nesting level of 1 indicates this type; 2 indicates the first nested generic; + * 3 the second; and so on. For example, given {@code List>} level 1 refers + * to the {@code List}, level 2 the {@code Set}, and level 3 the {@code Integer}. *

The {@code typeIndexesPerLevel} map can be used to reference a specific generic * for the given level. For example, an index of 0 would refer to a {@code Map} key; * whereas, 1 would refer to the value. If the map does not contain a value for a @@ -582,11 +582,11 @@ public class ResolvableType implements Serializable { * {@code String[]}, a nesting level of 2 refers to {@code String}. *

If a type does not {@link #hasGenerics() contain} generics the * {@link #getSuperType() supertype} hierarchy will be considered. - * @param nestingLevel the required nesting level, indexed from 1 for the current - * type, 2 for the first nested generic, 3 for the second and so on - * @param typeIndexesPerLevel a map containing the generic index for a given nesting - * level (may be {@code null}) - * @return a {@link ResolvableType} for the nested level or {@link #NONE} + * @param nestingLevel the required nesting level, indexed from 1 for the + * current type, 2 for the first nested generic, 3 for the second and so on + * @param typeIndexesPerLevel a map containing the generic index for a given + * nesting level (may be {@code null}) + * @return a {@link ResolvableType} for the nested level, or {@link #NONE} */ public ResolvableType getNested(int nestingLevel, Map typeIndexesPerLevel) { ResolvableType result = this; @@ -608,17 +608,17 @@ public class ResolvableType implements Serializable { } /** - * Return a {@link ResolvableType} representing the generic parameter for the given - * indexes. Indexes are zero based; for example given the type + * Return a {@link ResolvableType} representing the generic parameter for the + * given indexes. Indexes are zero based; for example given the type * {@code Map>}, {@code getGeneric(0)} will access the * {@code Integer}. Nested generics can be accessed by specifying multiple indexes; - * for example {@code getGeneric(1, 0)} will access the {@code String} from the nested - * {@code List}. For convenience, if no indexes are specified the first generic is - * returned. + * for example {@code getGeneric(1, 0)} will access the {@code String} from the + * nested {@code List}. For convenience, if no indexes are specified the first + * generic is returned. *

If no generic is available at the specified indexes {@link #NONE} is returned. - * @param indexes the indexes that refer to the generic parameter (may be omitted to - * return the first generic) - * @return a {@link ResolvableType} for the specified generic or {@link #NONE} + * @param indexes the indexes that refer to the generic parameter + * (may be omitted to return the first generic) + * @return a {@link ResolvableType} for the specified generic, or {@link #NONE} * @see #hasGenerics() * @see #getGenerics() * @see #resolveGeneric(int...) @@ -693,9 +693,8 @@ public class ResolvableType implements Serializable { * Convenience method that will {@link #getGenerics() get} and {@link #resolve() * resolve} generic parameters, using the specified {@code fallback} if any type * cannot be resolved. - * @param fallback the fallback class to use if resolution fails (may be {@code null}) - * @return an array of resolved generic parameters (the resulting array will never be - * {@code null}, but it may contain {@code null} elements}) + * @param fallback the fallback class to use if resolution fails + * @return an array of resolved generic parameters * @see #getGenerics() * @see #resolve() */ @@ -740,7 +739,7 @@ public class ResolvableType implements Serializable { * {@code fallback} if the type cannot be resolved. This method will consider bounds * of {@link TypeVariable}s and {@link WildcardType}s if direct resolution fails; * however, bounds of {@code Object.class} will be ignored. - * @param fallback the fallback class to use if resolution fails (may be {@code null}) + * @param fallback the fallback class to use if resolution fails * @return the resolved {@link Class} or the {@code fallback} * @see #resolve() * @see #resolveGeneric(int...) @@ -935,8 +934,8 @@ public class ResolvableType implements Serializable { } /** - * Return a {@link ResolvableType} for the specified {@link Class}, doing - * assignability checks against the raw class only (analogous to + * Return a {@link ResolvableType} for the specified {@link Class}, + * doing assignability checks against the raw class only (analogous to * {@link Class#isAssignableFrom}, which this serves as a wrapper for. * For example: {@code ResolvableType.forRawClass(List.class)}. * @param clazz the class to introspect ({@code null} is semantically @@ -1286,7 +1285,7 @@ public class ResolvableType implements Serializable { /** * Return a {@link ResolvableType} for the specified {@link Type}. * Note: The resulting {@link ResolvableType} may not be {@link Serializable}. - * @param type the source type or {@code null} + * @param type the source type (potentially {@code null}) * @return a {@link ResolvableType} for the specified {@link Type} * @see #forType(Type, ResolvableType) */ diff --git a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java index d5d595dd9c..011e90dea1 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -323,7 +323,9 @@ public class FormHttpMessageConverter implements HttpMessageConverter parts, HttpOutputMessage outputMessage) throws IOException { + private void writeMultipart(final MultiValueMap parts, HttpOutputMessage outputMessage) + throws IOException { + final byte[] boundary = generateMultipartBoundary(); Map parameters = Collections.singletonMap("boundary", new String(boundary, "US-ASCII")); @@ -381,7 +383,6 @@ public class FormHttpMessageConverter implements HttpMessageConverterThis implementation delegates to diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java index 3e64830aa9..4266312836 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -38,7 +38,7 @@ import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler; * {@code @EnableWebSocketMessageBroker} for Java config and * {@code } for XML. * - *

By default aggregated information is logged every 15 minutes at INFO level. + *

By default aggregated information is logged every 30 minutes at INFO level. * The frequency of logging can be changed via {@link #setLoggingPeriod(long)}. * *

This class is declared as a Spring bean by the above configuration with the @@ -189,7 +189,7 @@ public class WebSocketMessageBrokerStats { ", stompSubProtocol[" + getStompSubProtocolStatsInfo() + "]" + ", stompBrokerRelay[" + getStompBrokerRelayStatsInfo() + "]" + ", inboundChannel[" + getClientInboundExecutorStatsInfo() + "]" + - ", outboundChannel" + getClientOutboundExecutorStatsInfo() + "]" + + ", outboundChannel[" + getClientOutboundExecutorStatsInfo() + "]" + ", sockJsScheduler[" + getSockJsTaskSchedulerStatsInfo() + "]"; } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java index 38badb53ce..59c636225a 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -22,6 +22,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.concurrent.ScheduledThreadPoolExecutor; import org.hamcrest.Matchers; import org.junit.Test; @@ -92,8 +93,8 @@ import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; /** - * Test fixture for MessageBrokerBeanDefinitionParser. - * See test configuration files websocket-config-broker-*.xml. + * Test fixture for {@link MessageBrokerBeanDefinitionParser}. + * Also see test configuration files websocket-config-broker-*.xml. * * @author Brian Clozel * @author Artem Bilan @@ -174,8 +175,9 @@ public class MessageBrokerBeanDefinitionParserTests { assertFalse(defaultSockJsService.shouldSuppressCors()); ThreadPoolTaskScheduler scheduler = (ThreadPoolTaskScheduler) defaultSockJsService.getTaskScheduler(); - assertEquals(Runtime.getRuntime().availableProcessors(), scheduler.getScheduledThreadPoolExecutor().getCorePoolSize()); - assertTrue(scheduler.getScheduledThreadPoolExecutor().getRemoveOnCancelPolicy()); + ScheduledThreadPoolExecutor executor = scheduler.getScheduledThreadPoolExecutor(); + assertEquals(Runtime.getRuntime().availableProcessors(), executor.getCorePoolSize()); + assertTrue(executor.getRemoveOnCancelPolicy()); interceptors = defaultSockJsService.getHandshakeInterceptors(); assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class), @@ -199,14 +201,13 @@ public class MessageBrokerBeanDefinitionParserTests { SimpleBrokerMessageHandler brokerMessageHandler = this.appContext.getBean(SimpleBrokerMessageHandler.class); assertNotNull(brokerMessageHandler); Collection prefixes = brokerMessageHandler.getDestinationPrefixes(); - assertEquals(Arrays.asList("/topic", "/queue"), new ArrayList(prefixes)); + assertEquals(Arrays.asList("/topic", "/queue"), new ArrayList<>(prefixes)); DefaultSubscriptionRegistry registry = (DefaultSubscriptionRegistry) brokerMessageHandler.getSubscriptionRegistry(); assertEquals("my-selector", registry.getSelectorHeaderName()); assertNotNull(brokerMessageHandler.getTaskScheduler()); assertArrayEquals(new long[] {15000, 15000}, brokerMessageHandler.getHeartbeatValue()); - List> subscriberTypes = - Arrays.>asList(SimpAnnotationMethodMessageHandler.class, + List> subscriberTypes = Arrays.asList(SimpAnnotationMethodMessageHandler.class, UserDestinationMessageHandler.class, SimpleBrokerMessageHandler.class); testChannel("clientInboundChannel", subscriberTypes, 2); testExecutor("clientInboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60); @@ -215,8 +216,7 @@ public class MessageBrokerBeanDefinitionParserTests { testChannel("clientOutboundChannel", subscriberTypes, 1); testExecutor("clientOutboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60); - subscriberTypes = Arrays.>asList( - SimpleBrokerMessageHandler.class, UserDestinationMessageHandler.class); + subscriberTypes = Arrays.asList(SimpleBrokerMessageHandler.class, UserDestinationMessageHandler.class); testChannel("brokerChannel", subscriberTypes, 1); try { this.appContext.getBean("brokerChannelExecutor", ThreadPoolTaskExecutor.class); @@ -228,8 +228,9 @@ public class MessageBrokerBeanDefinitionParserTests { assertNotNull(this.appContext.getBean("webSocketScopeConfigurer", CustomScopeConfigurer.class)); - DirectFieldAccessor subscriptionRegistryAccessor = new DirectFieldAccessor(brokerMessageHandler.getSubscriptionRegistry()); - String pathSeparator = (String) new DirectFieldAccessor(subscriptionRegistryAccessor.getPropertyValue("pathMatcher")).getPropertyValue("pathSeparator"); + DirectFieldAccessor accessor = new DirectFieldAccessor(registry); + Object pathMatcher = accessor.getPropertyValue("pathMatcher"); + String pathSeparator = (String) new DirectFieldAccessor(pathMatcher).getPropertyValue("pathSeparator"); assertEquals(".", pathSeparator); } @@ -274,9 +275,8 @@ public class MessageBrokerBeanDefinitionParserTests { assertEquals(5000, messageBroker.getSystemHeartbeatSendInterval()); assertThat(messageBroker.getDestinationPrefixes(), Matchers.containsInAnyOrder("/topic","/queue")); - List> subscriberTypes = - Arrays.>asList(SimpAnnotationMethodMessageHandler.class, - UserDestinationMessageHandler.class, StompBrokerRelayMessageHandler.class); + List> subscriberTypes = Arrays.asList(SimpAnnotationMethodMessageHandler.class, + UserDestinationMessageHandler.class, StompBrokerRelayMessageHandler.class); testChannel("clientInboundChannel", subscriberTypes, 2); testExecutor("clientInboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60); @@ -284,8 +284,7 @@ public class MessageBrokerBeanDefinitionParserTests { testChannel("clientOutboundChannel", subscriberTypes, 1); testExecutor("clientOutboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60); - subscriberTypes = Arrays.>asList( - StompBrokerRelayMessageHandler.class, UserDestinationMessageHandler.class); + subscriberTypes = Arrays.asList(StompBrokerRelayMessageHandler.class, UserDestinationMessageHandler.class); testChannel("brokerChannel", subscriberTypes, 1); try { this.appContext.getBean("brokerChannelExecutor", ThreadPoolTaskExecutor.class); @@ -316,10 +315,14 @@ public class MessageBrokerBeanDefinitionParserTests { String expected = "WebSocketSession\\[0 current WS\\(0\\)-HttpStream\\(0\\)-HttpPoll\\(0\\), " + "0 total, 0 closed abnormally \\(0 connect failure, 0 send limit, 0 transport error\\)\\], " + "stompSubProtocol\\[processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " + - "stompBrokerRelay\\[0 sessions, relayhost:1234 \\(not available\\), processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " + - "inboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " + - "outboundChannelpool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " + - "sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\]"; + "stompBrokerRelay\\[0 sessions, relayhost:1234 \\(not available\\), " + + "processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " + + "inboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, " + + "completed tasks = \\d\\], " + + "outboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, " + + "completed tasks = \\d\\], " + + "sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, " + + "completed tasks = \\d\\]"; assertTrue("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual, actual.matches(expected)); } @@ -355,7 +358,8 @@ public class MessageBrokerBeanDefinitionParserTests { assertEquals(MimeTypeUtils.APPLICATION_JSON, ((DefaultContentTypeResolver) resolver).getDefaultMimeType()); DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(annotationMethodMessageHandler); - String pathSeparator = (String) new DirectFieldAccessor(handlerAccessor.getPropertyValue("pathMatcher")).getPropertyValue("pathSeparator"); + Object pathMatcher = handlerAccessor.getPropertyValue("pathMatcher"); + String pathSeparator = (String) new DirectFieldAccessor(pathMatcher).getPropertyValue("pathSeparator"); assertEquals(".", pathSeparator); } @@ -371,9 +375,8 @@ public class MessageBrokerBeanDefinitionParserTests { assertSame(this.appContext.getBean("myValidator"), validator); assertThat(validator, Matchers.instanceOf(TestValidator.class)); - List> subscriberTypes = - Arrays.>asList(SimpAnnotationMethodMessageHandler.class, - UserDestinationMessageHandler.class, SimpleBrokerMessageHandler.class); + List> subscriberTypes = Arrays.asList(SimpAnnotationMethodMessageHandler.class, + UserDestinationMessageHandler.class, SimpleBrokerMessageHandler.class); testChannel("clientInboundChannel", subscriberTypes, 3); testExecutor("clientInboundChannel", 100, 200, 600); @@ -383,16 +386,13 @@ public class MessageBrokerBeanDefinitionParserTests { testChannel("clientOutboundChannel", subscriberTypes, 3); testExecutor("clientOutboundChannel", 101, 201, 601); - subscriberTypes = Arrays.>asList(SimpleBrokerMessageHandler.class, - UserDestinationMessageHandler.class); + subscriberTypes = Arrays.asList(SimpleBrokerMessageHandler.class, UserDestinationMessageHandler.class); testChannel("brokerChannel", subscriberTypes, 1); testExecutor("brokerChannel", 102, 202, 602); } - // SPR-11623 - - @Test + @Test // SPR-11623 public void customChannelsWithDefaultExecutor() { loadBeanDefinitions("websocket-config-broker-customchannels-default-executor.xml"); @@ -441,27 +441,23 @@ public class MessageBrokerBeanDefinitionParserTests { } - private void testChannel(String channelName, List> subscriberTypes, - int interceptorCount) { + private void testChannel( + String channelName, List> subscriberTypes, int interceptorCount) { AbstractSubscribableChannel channel = this.appContext.getBean(channelName, AbstractSubscribableChannel.class); - for (Class subscriberType : subscriberTypes) { MessageHandler subscriber = this.appContext.getBean(subscriberType); - assertNotNull("No subsription for " + subscriberType, subscriber); + assertNotNull("No subscription for " + subscriberType, subscriber); assertTrue(channel.hasSubscription(subscriber)); } - List interceptors = channel.getInterceptors(); assertEquals(interceptorCount, interceptors.size()); assertEquals(ImmutableMessageChannelInterceptor.class, interceptors.get(interceptors.size()-1).getClass()); } private void testExecutor(String channelName, int corePoolSize, int maxPoolSize, int keepAliveSeconds) { - ThreadPoolTaskExecutor taskExecutor = this.appContext.getBean(channelName + "Executor", ThreadPoolTaskExecutor.class); - assertEquals(corePoolSize, taskExecutor.getCorePoolSize()); assertEquals(maxPoolSize, taskExecutor.getMaxPoolSize()); assertEquals(keepAliveSeconds, taskExecutor.getKeepAliveSeconds()); @@ -479,6 +475,7 @@ public class MessageBrokerBeanDefinitionParserTests { return (handler instanceof WebSocketHandlerDecorator) ? ((WebSocketHandlerDecorator) handler).getLastHandler() : handler; } + } @@ -505,7 +502,6 @@ class CustomReturnValueHandler implements HandlerMethodReturnValueHandler { @Override public void handleReturnValue(Object returnValue, MethodParameter returnType, Message message) throws Exception { - } } @@ -536,12 +532,15 @@ class TestWebSocketHandlerDecorator extends WebSocketHandlerDecorator { class TestStompErrorHandler extends StompSubProtocolErrorHandler { } + class TestValidator implements Validator { + @Override public boolean supports(Class clazz) { return false; } @Override - public void validate(Object target, Errors errors) { } + public void validate(Object target, Errors errors) { + } } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java index 51f69532ce..8364a2268d 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2019 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. @@ -16,9 +16,6 @@ package org.springframework.web.socket.config.annotation; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -51,7 +48,6 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.stereotype.Controller; import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; -import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.WebSocketHandler; import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.config.WebSocketMessageBrokerStats; @@ -64,9 +60,11 @@ import org.springframework.web.socket.messaging.SubProtocolHandler; import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler; import org.springframework.web.socket.server.support.WebSocketHttpRequestHandler; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + /** - * Test fixture for - * {@link org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurationSupport}. + * Test fixture for {@link WebSocketMessageBrokerConfigurationSupport}. * * @author Rossen Stoyanchev */ @@ -96,8 +94,8 @@ public class WebSocketMessageBrokerConfigurationSupportTests { session.setOpen(true); webSocketHandler.afterConnectionEstablished(session); - TextMessage textMessage = StompTextMessageBuilder.create(StompCommand.SEND).headers("destination:/foo").build(); - webSocketHandler.handleMessage(session, textMessage); + webSocketHandler.handleMessage(session, + StompTextMessageBuilder.create(StompCommand.SEND).headers("destination:/foo").build()); Message message = channel.messages.get(0); StompHeaderAccessor accessor = StompHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); @@ -173,7 +171,7 @@ public class WebSocketMessageBrokerConfigurationSupportTests { "stompSubProtocol\\[processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " + "stompBrokerRelay\\[null\\], " + "inboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " + - "outboundChannelpool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " + + "outboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " + "sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\]"; assertTrue("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual, actual.matches(expected));