Browse Source

Introduced addScope convenience method on CustomScopeConfigurer (for use in WebSocket configuration)

pull/651/head
Juergen Hoeller 10 years ago
parent
commit
070642c148
  1. 17
      spring-beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java
  2. 3
      spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationSupport.java
  3. 22
      spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupport.java

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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,6 +16,7 @@ @@ -16,6 +16,7 @@
package org.springframework.beans.factory.config;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.beans.BeanUtils;
@ -61,6 +62,20 @@ public class CustomScopeConfigurer implements BeanFactoryPostProcessor, BeanClas @@ -61,6 +62,20 @@ public class CustomScopeConfigurer implements BeanFactoryPostProcessor, BeanClas
this.scopes = scopes;
}
/**
* Add the given scope to this configurer's map of scopes.
* @param scopeName the name of the scope
* @param scope the scope implementation
* @since 4.1.1
*/
public void addScope(String scopeName, Scope scope) {
if (this.scopes == null) {
this.scopes = new LinkedHashMap<String, Object>(1);
}
this.scopes.put(scopeName, scope);
}
public void setOrder(int order) {
this.order = order;
}

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@ -51,7 +51,6 @@ public class WebSocketConfigurationSupport { @@ -51,7 +51,6 @@ public class WebSocketConfigurationSupport {
* }
*
* // ...
*
* }
* </pre>
*/

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

@ -16,11 +16,10 @@ @@ -16,11 +16,10 @@
package org.springframework.web.socket.config.annotation;
import java.util.Collections;
import org.springframework.beans.factory.config.CustomScopeConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.simp.SimpSessionScope;
import org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler;
import org.springframework.messaging.simp.config.AbstractMessageBrokerConfiguration;
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@ -32,8 +31,8 @@ import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler; @@ -32,8 +31,8 @@ import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
/**
* Extends {@link AbstractMessageBrokerConfiguration} and adds configuration for
* receiving and responding to STOMP messages from WebSocket clients.
* <p>
* Typically used in conjunction with
*
* <p>Typically used in conjunction with
* {@link EnableWebSocketMessageBroker @EnableWebSocketMessageBroker} but can
* also be extended directly.
*
@ -46,16 +45,10 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac @@ -46,16 +45,10 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac
private WebSocketTransportRegistration transportRegistration;
protected WebSocketMessageBrokerConfigurationSupport() {
}
@Bean
public HandlerMapping stompWebSocketHandlerMapping() {
WebMvcStompEndpointRegistry registry = new WebMvcStompEndpointRegistry(subProtocolWebSocketHandler(),
getTransportRegistration(), userSessionRegistry(), messageBrokerSockJsTaskScheduler());
registry.setApplicationContext(getApplicationContext());
registerStompEndpoints(registry);
return registry.getHandlerMapping();
@ -92,7 +85,6 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac @@ -92,7 +85,6 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac
* }
*
* // ...
*
* }
* </pre>
*/
@ -108,15 +100,15 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac @@ -108,15 +100,15 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac
@Bean
public static CustomScopeConfigurer webSocketScopeConfigurer() {
CustomScopeConfigurer configurer = new CustomScopeConfigurer();
configurer.setScopes(Collections.<String, Object>singletonMap("websocket", new SimpSessionScope()));
configurer.addScope("websocket", new SimpSessionScope());
return configurer;
}
@Bean
public WebSocketMessageBrokerStats webSocketMessageBrokerStats() {
StompBrokerRelayMessageHandler brokerRelay =
stompBrokerRelayMessageHandler() instanceof StompBrokerRelayMessageHandler ?
(StompBrokerRelayMessageHandler) stompBrokerRelayMessageHandler() : null;
AbstractBrokerMessageHandler relayBean = stompBrokerRelayMessageHandler();
StompBrokerRelayMessageHandler brokerRelay = (relayBean instanceof StompBrokerRelayMessageHandler ?
(StompBrokerRelayMessageHandler) relayBean : null);
// Ensure STOMP endpoints are registered
stompWebSocketHandlerMapping();

Loading…
Cancel
Save