29
29
30
30
import com .fasterxml .jackson .databind .ObjectMapper ;
31
31
import org .apache .tomcat .websocket .WsWebSocketContainer ;
32
+ import org .assertj .core .api .InstanceOfAssertFactories ;
32
33
import org .junit .jupiter .api .AfterEach ;
33
34
import org .junit .jupiter .api .BeforeEach ;
34
35
import org .junit .jupiter .api .Test ;
40
41
import org .springframework .boot .autoconfigure .task .TaskExecutionAutoConfiguration ;
41
42
import org .springframework .boot .autoconfigure .web .servlet .DispatcherServletAutoConfiguration ;
42
43
import org .springframework .boot .autoconfigure .web .servlet .ServletWebServerFactoryAutoConfiguration ;
44
+ import org .springframework .boot .autoconfigure .websocket .servlet .WebSocketMessagingAutoConfiguration .WebSocketMessageConverterConfiguration ;
43
45
import org .springframework .boot .context .properties .EnableConfigurationProperties ;
44
46
import org .springframework .boot .test .util .TestPropertyValues ;
45
47
import org .springframework .boot .web .embedded .tomcat .TomcatServletWebServerFactory ;
46
48
import org .springframework .boot .web .servlet .context .AnnotationConfigServletWebServerApplicationContext ;
47
49
import org .springframework .context .annotation .Bean ;
48
50
import org .springframework .context .annotation .Configuration ;
51
+ import org .springframework .core .Ordered ;
52
+ import org .springframework .core .annotation .Order ;
49
53
import org .springframework .core .task .AsyncTaskExecutor ;
50
54
import org .springframework .core .task .SimpleAsyncTaskExecutor ;
51
55
import org .springframework .core .task .TaskExecutor ;
62
66
import org .springframework .messaging .simp .stomp .StompSessionHandler ;
63
67
import org .springframework .messaging .simp .stomp .StompSessionHandlerAdapter ;
64
68
import org .springframework .security .util .FieldUtils ;
69
+ import org .springframework .stereotype .Component ;
65
70
import org .springframework .stereotype .Controller ;
66
71
import org .springframework .web .client .RestTemplate ;
67
72
import org .springframework .web .socket .client .standard .StandardWebSocketClient ;
@@ -162,6 +167,26 @@ void predefinedThreadExecutorIsSelectedForOutboundChannel() throws Throwable {
162
167
assertThat (executor ).isEqualTo (expectedExecutor );
163
168
}
164
169
170
+ @ Test
171
+ void webSocketMessageBrokerConfigurerOrdering () throws Throwable {
172
+ TestPropertyValues .of ("server.port:0" , "spring.jackson.serialization.indent-output:true" ).applyTo (this .context );
173
+ this .context .register (WebSocketMessagingConfiguration .class , CustomLowWebSocketMessageBrokerConfigurer .class ,
174
+ CustomHighWebSocketMessageBrokerConfigurer .class );
175
+ this .context .refresh ();
176
+ DelegatingWebSocketMessageBrokerConfiguration delegatingConfiguration = this .context
177
+ .getBean (DelegatingWebSocketMessageBrokerConfiguration .class );
178
+ CustomHighWebSocketMessageBrokerConfigurer high = this .context
179
+ .getBean (CustomHighWebSocketMessageBrokerConfigurer .class );
180
+ WebSocketMessageConverterConfiguration autoConfiguration = this .context
181
+ .getBean (WebSocketMessagingAutoConfiguration .WebSocketMessageConverterConfiguration .class );
182
+ WebSocketMessagingConfiguration configuration = this .context .getBean (WebSocketMessagingConfiguration .class );
183
+ CustomLowWebSocketMessageBrokerConfigurer low = this .context
184
+ .getBean (CustomLowWebSocketMessageBrokerConfigurer .class );
185
+ assertThat (delegatingConfiguration ).extracting ("configurers" )
186
+ .asInstanceOf (InstanceOfAssertFactories .LIST )
187
+ .containsExactly (high , autoConfiguration , configuration , low );
188
+ }
189
+
165
190
private List <MessageConverter > getCustomizedConverters () {
166
191
List <MessageConverter > customizedConverters = new ArrayList <>();
167
192
WebSocketMessagingAutoConfiguration .WebSocketMessageConverterConfiguration configuration = new WebSocketMessagingAutoConfiguration .WebSocketMessageConverterConfiguration (
@@ -246,6 +271,7 @@ static class WebSocketMessagingConfiguration implements WebSocketMessageBrokerCo
246
271
247
272
@ Override
248
273
public void registerStompEndpoints (StompEndpointRegistry registry ) {
274
+
249
275
registry .addEndpoint ("/messaging" ).withSockJS ();
250
276
}
251
277
@@ -271,6 +297,18 @@ TomcatWebSocketServletWebServerCustomizer tomcatCustomizer() {
271
297
272
298
}
273
299
300
+ @ Component
301
+ @ Order (Ordered .HIGHEST_PRECEDENCE )
302
+ static class CustomHighWebSocketMessageBrokerConfigurer implements WebSocketMessageBrokerConfigurer {
303
+
304
+ }
305
+
306
+ @ Component
307
+ @ Order (Ordered .LOWEST_PRECEDENCE )
308
+ static class CustomLowWebSocketMessageBrokerConfigurer implements WebSocketMessageBrokerConfigurer {
309
+
310
+ }
311
+
274
312
@ Controller
275
313
static class MessagingController {
276
314
0 commit comments