diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketMessageBrokerConfigurer.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketMessageBrokerConfigurer.java index cce19e37e4f..68ce23640e3 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketMessageBrokerConfigurer.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketMessageBrokerConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -30,8 +30,11 @@ import org.springframework.messaging.simp.config.MessageBrokerRegistry; * * @author Rossen Stoyanchev * @since 4.0.1 + * @deprecated in favor of simply using {@link WebSocketMessageBrokerConfigurer} + * which has default methods, made possible by a Java 8 baseline. */ -public abstract class AbstractWebSocketMessageBrokerConfigurer implements WebSocketMessageBrokerConfigurer { +@Deprecated +public abstract class /*AbstractWebSocketMessageBrokerConfigurer*/ implements WebSocketMessageBrokerConfigurer { @Override diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/EnableWebSocketMessageBroker.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/EnableWebSocketMessageBroker.java index e9d4d85ee91..8b64c58c73f 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/EnableWebSocketMessageBroker.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/EnableWebSocketMessageBroker.java @@ -37,13 +37,12 @@ import org.springframework.context.annotation.Import; * * *

Customize the imported configuration by implementing the - * {@link WebSocketMessageBrokerConfigurer} interface or more likely extend the - * convenient base class {@link AbstractWebSocketMessageBrokerConfigurer}: + * {@link WebSocketMessageBrokerConfigurer} interface: * *

  * @Configuration
  * @EnableWebSocketMessageBroker
- * public class MyConfiguration extends AbstractWebSocketMessageBrokerConfigurer {
+ * public class MyConfiguration implements WebSocketMessageBrokerConfigurer {
  *
  *     @Override
  *     public void registerStompEndpoints(StompEndpointRegistry registry) {
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurer.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurer.java
index 9ddd898f5f0..85f8f1a0a08 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurer.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurer.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2014 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.
@@ -40,13 +40,15 @@ public interface WebSocketMessageBrokerConfigurer {
 	 * Register STOMP endpoints mapping each to a specific URL and (optionally)
 	 * enabling and configuring SockJS fallback options.
 	 */
-	void registerStompEndpoints(StompEndpointRegistry registry);
+	default void registerStompEndpoints(StompEndpointRegistry registry) {
+	}
 
 	/**
 	 * Configure options related to the processing of messages received from and
 	 * sent to WebSocket clients.
 	 */
-	void configureWebSocketTransport(WebSocketTransportRegistration registry);
+	default void configureWebSocketTransport(WebSocketTransportRegistration registry) {
+	}
 
 	/**
 	 * Configure the {@link org.springframework.messaging.MessageChannel} used for
@@ -54,7 +56,8 @@ public interface WebSocketMessageBrokerConfigurer {
 	 * by a thread pool of size 1. It is recommended to customize thread pool
 	 * settings for production use.
 	 */
-	void configureClientInboundChannel(ChannelRegistration registration);
+	default void configureClientInboundChannel(ChannelRegistration registration) {
+	}
 
 	/**
 	 * Configure the {@link org.springframework.messaging.MessageChannel} used for
@@ -62,7 +65,8 @@ public interface WebSocketMessageBrokerConfigurer {
 	 * by a thread pool of size 1. It is recommended to customize thread pool
 	 * settings for production use.
 	 */
-	void configureClientOutboundChannel(ChannelRegistration registration);
+	default void configureClientOutboundChannel(ChannelRegistration registration) {
+	}
 
 	/**
 	 * Add resolvers to support custom controller method argument types.
@@ -72,7 +76,8 @@ public interface WebSocketMessageBrokerConfigurer {
 	 * @param argumentResolvers the resolvers to register (initially an empty list)
 	 * @since 4.1.1
 	 */
-	void addArgumentResolvers(List argumentResolvers);
+	default void addArgumentResolvers(List argumentResolvers) {
+	}
 
 	/**
 	 * Add handlers to support custom controller method return value types.
@@ -82,7 +87,8 @@ public interface WebSocketMessageBrokerConfigurer {
 	 * @param returnValueHandlers the handlers to register (initially an empty list)
 	 * @since 4.1.1
 	 */
-	void addReturnValueHandlers(List returnValueHandlers);
+	default void addReturnValueHandlers(List returnValueHandlers) {
+	}
 
 	/**
 	 * Configure the message converters to use when extracting the payload of
@@ -94,11 +100,14 @@ public interface WebSocketMessageBrokerConfigurer {
 	 * @param messageConverters the converters to configure (initially an empty list)
 	 * @return whether to also add default converter or not
 	 */
-	boolean configureMessageConverters(List messageConverters);
+	default boolean configureMessageConverters(List messageConverters) {
+		return true;
+	}
 
 	/**
 	 * Configure message broker options.
 	 */
-	void configureMessageBroker(MessageBrokerRegistry registry);
+	default void configureMessageBroker(MessageBrokerRegistry registry) {
+	}
 
 }
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 51f69532cee..aa67273e08b 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
@@ -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;
@@ -64,6 +61,13 @@ 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.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
 /**
  * Test fixture for
  * {@link org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurationSupport}.
@@ -219,7 +223,7 @@ public class WebSocketMessageBrokerConfigurationSupportTests {
 	}
 
 	@Configuration
-	static class TestConfigurer extends AbstractWebSocketMessageBrokerConfigurer {
+	static class TestConfigurer implements WebSocketMessageBrokerConfigurer {
 
 		@Bean
 		public TestController subscriptionController() {
diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java
index 231e9bb283c..d8332bed299 100644
--- a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java
+++ b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java
@@ -51,14 +51,14 @@ import org.springframework.web.socket.UndertowTestServer;
 import org.springframework.web.socket.WebSocketSession;
 import org.springframework.web.socket.client.jetty.JettyWebSocketClient;
 import org.springframework.web.socket.client.standard.StandardWebSocketClient;
-import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
 import org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration;
 import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
+import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
 import org.springframework.web.socket.handler.TextWebSocketHandler;
 import org.springframework.web.socket.server.HandshakeHandler;
 
-import static org.junit.Assert.*;
-import static org.springframework.web.socket.messaging.StompTextMessageBuilder.*;
+import static org.junit.Assert.assertTrue;
+import static org.springframework.web.socket.messaging.StompTextMessageBuilder.create;
 
 /**
  * Integration tests with annotated message-handling methods.
@@ -318,7 +318,7 @@ public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegration
 			basePackageClasses=StompWebSocketIntegrationTests.class,
 			useDefaultFilters=false,
 			includeFilters=@ComponentScan.Filter(IntegrationTestController.class))
-	static class TestMessageBrokerConfigurer extends AbstractWebSocketMessageBrokerConfigurer {
+	static class TestMessageBrokerConfigurer implements WebSocketMessageBrokerConfigurer {
 
 		@Autowired
 		private HandshakeHandler handshakeHandler;  // can't rely on classpath for server detection
diff --git a/src/docs/asciidoc/web/websocket.adoc b/src/docs/asciidoc/web/websocket.adoc
index 4205ae02b23..f9dee3775f6 100644
--- a/src/docs/asciidoc/web/websocket.adoc
+++ b/src/docs/asciidoc/web/websocket.adoc
@@ -1458,7 +1458,7 @@ In Java config:
 ----
 	@Configuration
 	@EnableWebSocketMessageBroker
-	public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
+	public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
 
 		// ...
 
@@ -1611,7 +1611,7 @@ user and associate it with subsequent STOMP messages on the same session:
 ----
 	@Configuration
 	@EnableWebSocketMessageBroker
-	public class MyConfig extends AbstractWebSocketMessageBrokerConfigurer {
+	public class MyConfig implements WebSocketMessageBrokerConfigurer {
 
 		@Override
 		public void configureClientInboundChannel(ChannelRegistration registration) {
@@ -1634,7 +1634,7 @@ user and associate it with subsequent STOMP messages on the same session:
 Also note that when using Spring Security's authorization for messages, at present
 you will need to ensure that the authentication `ChannelInterceptor` config is ordered
 ahead of Spring Security's. This is best done by declaring the custom interceptor in
-its own sub-class of `AbstractWebSocketMessageBrokerConfigurer` marked with
+its own implementation of `WebSocketMessageBrokerConfigurer` marked with
 `@Order(Ordered.HIGHEST_PRECEDENCE + 99)`.
 
 
@@ -1811,7 +1811,7 @@ to intercept inbound messages:
 ----
 	@Configuration
 	@EnableWebSocketMessageBroker
-	public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
+	public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
 
 		@Override
 		public void configureClientInboundChannel(ChannelRegistration registration) {