Skip to content

Commit 070642c

Browse files
committed
Introduced addScope convenience method on CustomScopeConfigurer (for use in WebSocket configuration)
1 parent 3836aa0 commit 070642c

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.beans.factory.config;
1818

19+
import java.util.LinkedHashMap;
1920
import java.util.Map;
2021

2122
import org.springframework.beans.BeanUtils;
@@ -61,6 +62,20 @@ public void setScopes(Map<String, Object> scopes) {
6162
this.scopes = scopes;
6263
}
6364

65+
/**
66+
* Add the given scope to this configurer's map of scopes.
67+
* @param scopeName the name of the scope
68+
* @param scope the scope implementation
69+
* @since 4.1.1
70+
*/
71+
public void addScope(String scopeName, Scope scope) {
72+
if (this.scopes == null) {
73+
this.scopes = new LinkedHashMap<String, Object>(1);
74+
}
75+
this.scopes.put(scopeName, scope);
76+
}
77+
78+
6479
public void setOrder(int order) {
6580
this.order = order;
6681
}

spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationSupport.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,7 +51,6 @@ protected void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
5151
* }
5252
*
5353
* // ...
54-
*
5554
* }
5655
* </pre>
5756
*/

spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupport.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616

1717
package org.springframework.web.socket.config.annotation;
1818

19-
import java.util.Collections;
20-
2119
import org.springframework.beans.factory.config.CustomScopeConfigurer;
2220
import org.springframework.context.annotation.Bean;
2321
import org.springframework.messaging.simp.SimpSessionScope;
22+
import org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler;
2423
import org.springframework.messaging.simp.config.AbstractMessageBrokerConfiguration;
2524
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
2625
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@@ -32,8 +31,8 @@
3231
/**
3332
* Extends {@link AbstractMessageBrokerConfiguration} and adds configuration for
3433
* receiving and responding to STOMP messages from WebSocket clients.
35-
* <p>
36-
* Typically used in conjunction with
34+
*
35+
* <p>Typically used in conjunction with
3736
* {@link EnableWebSocketMessageBroker @EnableWebSocketMessageBroker} but can
3837
* also be extended directly.
3938
*
@@ -46,16 +45,10 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac
4645
private WebSocketTransportRegistration transportRegistration;
4746

4847

49-
protected WebSocketMessageBrokerConfigurationSupport() {
50-
}
51-
52-
5348
@Bean
5449
public HandlerMapping stompWebSocketHandlerMapping() {
55-
5650
WebMvcStompEndpointRegistry registry = new WebMvcStompEndpointRegistry(subProtocolWebSocketHandler(),
5751
getTransportRegistration(), userSessionRegistry(), messageBrokerSockJsTaskScheduler());
58-
5952
registry.setApplicationContext(getApplicationContext());
6053
registerStompEndpoints(registry);
6154
return registry.getHandlerMapping();
@@ -92,7 +85,6 @@ protected void configureWebSocketTransport(WebSocketTransportRegistration regist
9285
* }
9386
*
9487
* // ...
95-
*
9688
* }
9789
* </pre>
9890
*/
@@ -108,15 +100,15 @@ public ThreadPoolTaskScheduler messageBrokerSockJsTaskScheduler() {
108100
@Bean
109101
public static CustomScopeConfigurer webSocketScopeConfigurer() {
110102
CustomScopeConfigurer configurer = new CustomScopeConfigurer();
111-
configurer.setScopes(Collections.<String, Object>singletonMap("websocket", new SimpSessionScope()));
103+
configurer.addScope("websocket", new SimpSessionScope());
112104
return configurer;
113105
}
114106

115107
@Bean
116108
public WebSocketMessageBrokerStats webSocketMessageBrokerStats() {
117-
StompBrokerRelayMessageHandler brokerRelay =
118-
stompBrokerRelayMessageHandler() instanceof StompBrokerRelayMessageHandler ?
119-
(StompBrokerRelayMessageHandler) stompBrokerRelayMessageHandler() : null;
109+
AbstractBrokerMessageHandler relayBean = stompBrokerRelayMessageHandler();
110+
StompBrokerRelayMessageHandler brokerRelay = (relayBean instanceof StompBrokerRelayMessageHandler ?
111+
(StompBrokerRelayMessageHandler) relayBean : null);
120112

121113
// Ensure STOMP endpoints are registered
122114
stompWebSocketHandlerMapping();

0 commit comments

Comments
 (0)