Add messaging.simp.user package
This commit is contained in:
@@ -57,7 +57,7 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String
|
|||||||
/**
|
/**
|
||||||
* Configure the prefix to use for destinations targeting a specific user.
|
* Configure the prefix to use for destinations targeting a specific user.
|
||||||
* <p>The default value is "/user/".
|
* <p>The default value is "/user/".
|
||||||
* @see org.springframework.messaging.simp.handler.UserDestinationMessageHandler
|
* @see org.springframework.messaging.simp.user.UserDestinationMessageHandler
|
||||||
*/
|
*/
|
||||||
public void setUserDestinationPrefix(String prefix) {
|
public void setUserDestinationPrefix(String prefix) {
|
||||||
Assert.notNull(prefix, "UserDestinationPrefix must not be null");
|
Assert.notNull(prefix, "UserDestinationPrefix must not be null");
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
|||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
* @see org.springframework.messaging.handler.annotation.SendTo
|
* @see org.springframework.messaging.handler.annotation.SendTo
|
||||||
* @see org.springframework.messaging.simp.handler.UserDestinationMessageHandler
|
* @see org.springframework.messaging.simp.user.UserDestinationMessageHandler
|
||||||
*/
|
*/
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
/**
|
/**
|
||||||
* Annotations and for handling messages from simple messaging protocols
|
* Annotations and for handling messages from SImple Messaging Protocols such as STOMP.
|
||||||
* (like STOMP).
|
|
||||||
*/
|
*/
|
||||||
package org.springframework.messaging.simp.annotation;
|
package org.springframework.messaging.simp.annotation;
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ import org.springframework.messaging.simp.SimpMessageType;
|
|||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Abstract base class for implementations of {@link SubscriptionRegistry} that
|
||||||
|
* looks up information in messages but delegates to abstract methods for the
|
||||||
|
* actual storage and retrieval.
|
||||||
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ import org.springframework.util.LinkedMultiValueMap;
|
|||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* A default, simple in-memory implementation of {@link SubscriptionRegistry}.
|
||||||
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -30,12 +30,12 @@ import org.springframework.messaging.converter.StringMessageConverter;
|
|||||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||||
import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler;
|
import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler;
|
||||||
import org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler;
|
import org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler;
|
||||||
import org.springframework.messaging.simp.handler.DefaultUserDestinationResolver;
|
import org.springframework.messaging.simp.user.DefaultUserDestinationResolver;
|
||||||
import org.springframework.messaging.simp.handler.DefaultUserSessionRegistry;
|
import org.springframework.messaging.simp.user.DefaultUserSessionRegistry;
|
||||||
import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler;
|
import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler;
|
||||||
import org.springframework.messaging.simp.handler.UserDestinationMessageHandler;
|
import org.springframework.messaging.simp.user.UserDestinationMessageHandler;
|
||||||
import org.springframework.messaging.simp.handler.UserDestinationResolver;
|
import org.springframework.messaging.simp.user.UserDestinationResolver;
|
||||||
import org.springframework.messaging.simp.handler.UserSessionRegistry;
|
import org.springframework.messaging.simp.user.UserSessionRegistry;
|
||||||
import org.springframework.messaging.support.AbstractSubscribableChannel;
|
import org.springframework.messaging.support.AbstractSubscribableChannel;
|
||||||
import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/**
|
||||||
* Generic support for SImple Messaging Protocols such as STOMP.
|
* Generic support for SImple Messaging Protocols including protocols such as STOMP.
|
||||||
*/
|
*/
|
||||||
package org.springframework.messaging.simp;
|
package org.springframework.messaging.simp;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.messaging.simp.handler;
|
package org.springframework.messaging.simp.user;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.messaging.simp.handler;
|
package org.springframework.messaging.simp.user;
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.messaging.simp.handler;
|
package org.springframework.messaging.simp.user;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.messaging.simp.handler;
|
package org.springframework.messaging.simp.user;
|
||||||
|
|
||||||
import org.springframework.messaging.Message;
|
import org.springframework.messaging.Message;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.springframework.messaging.simp.handler;
|
package org.springframework.messaging.simp.user;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* Support for handling messages to "user" destinations (i.e. destinations that are
|
||||||
|
* unique to a user's sessions), primarily translating the destinations and then
|
||||||
|
* forwarding the updated message to the broker.
|
||||||
|
* <p>
|
||||||
|
* Also included is {@link org.springframework.messaging.simp.user.UserSessionRegistry}
|
||||||
|
* for keeping track of connected user sessions.
|
||||||
|
*/
|
||||||
|
package org.springframework.messaging.simp.user;
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.messaging.simp.handler;
|
package org.springframework.messaging.simp.annotation.support;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -35,8 +35,8 @@ import org.springframework.messaging.simp.SimpMessageType;
|
|||||||
import org.springframework.messaging.simp.annotation.SubscribeMapping;
|
import org.springframework.messaging.simp.annotation.SubscribeMapping;
|
||||||
import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler;
|
import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler;
|
||||||
import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler;
|
import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler;
|
||||||
import org.springframework.messaging.simp.handler.UserDestinationMessageHandler;
|
import org.springframework.messaging.simp.user.UserDestinationMessageHandler;
|
||||||
import org.springframework.messaging.simp.handler.UserSessionRegistry;
|
import org.springframework.messaging.simp.user.UserSessionRegistry;
|
||||||
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
|
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
|
||||||
import org.springframework.messaging.simp.stomp.StompCommand;
|
import org.springframework.messaging.simp.stomp.StompCommand;
|
||||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.messaging.simp.handler;
|
package org.springframework.messaging.simp.user;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -22,6 +22,9 @@ import org.springframework.messaging.Message;
|
|||||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||||
import org.springframework.messaging.simp.SimpMessageType;
|
import org.springframework.messaging.simp.SimpMessageType;
|
||||||
import org.springframework.messaging.simp.TestPrincipal;
|
import org.springframework.messaging.simp.TestPrincipal;
|
||||||
|
import org.springframework.messaging.simp.user.DefaultUserDestinationResolver;
|
||||||
|
import org.springframework.messaging.simp.user.DefaultUserSessionRegistry;
|
||||||
|
import org.springframework.messaging.simp.user.UserSessionRegistry;
|
||||||
import org.springframework.messaging.support.MessageBuilder;
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -29,7 +32,7 @@ import java.util.Set;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link DefaultUserDestinationResolver}.
|
* Unit tests for {@link org.springframework.messaging.simp.user.DefaultUserDestinationResolver}.
|
||||||
*/
|
*/
|
||||||
public class DefaultUserDestinationResolverTests {
|
public class DefaultUserDestinationResolverTests {
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.messaging.simp.handler;
|
package org.springframework.messaging.simp.user;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -22,11 +22,12 @@ import java.util.LinkedHashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.springframework.messaging.simp.user.DefaultUserSessionRegistry;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test fixture for {@link DefaultUserSessionRegistry}
|
* Test fixture for {@link org.springframework.messaging.simp.user.DefaultUserSessionRegistry}
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.messaging.simp.handler;
|
package org.springframework.messaging.simp.user;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -28,13 +28,17 @@ import org.springframework.messaging.SubscribableChannel;
|
|||||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||||
import org.springframework.messaging.simp.SimpMessageType;
|
import org.springframework.messaging.simp.SimpMessageType;
|
||||||
import org.springframework.messaging.simp.TestPrincipal;
|
import org.springframework.messaging.simp.TestPrincipal;
|
||||||
|
import org.springframework.messaging.simp.user.DefaultUserDestinationResolver;
|
||||||
|
import org.springframework.messaging.simp.user.DefaultUserSessionRegistry;
|
||||||
|
import org.springframework.messaging.simp.user.UserDestinationMessageHandler;
|
||||||
|
import org.springframework.messaging.simp.user.UserSessionRegistry;
|
||||||
import org.springframework.messaging.support.MessageBuilder;
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link UserDestinationMessageHandler}.
|
* Unit tests for {@link org.springframework.messaging.simp.user.UserDestinationMessageHandler}.
|
||||||
*/
|
*/
|
||||||
public class UserDestinationMessageHandlerTests {
|
public class UserDestinationMessageHandlerTests {
|
||||||
|
|
||||||
@@ -39,10 +39,10 @@ import org.springframework.messaging.converter.MappingJackson2MessageConverter;
|
|||||||
import org.springframework.messaging.converter.StringMessageConverter;
|
import org.springframework.messaging.converter.StringMessageConverter;
|
||||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||||
import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler;
|
import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler;
|
||||||
import org.springframework.messaging.simp.handler.DefaultUserDestinationResolver;
|
import org.springframework.messaging.simp.user.DefaultUserDestinationResolver;
|
||||||
import org.springframework.messaging.simp.handler.DefaultUserSessionRegistry;
|
import org.springframework.messaging.simp.user.DefaultUserSessionRegistry;
|
||||||
import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler;
|
import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler;
|
||||||
import org.springframework.messaging.simp.handler.UserDestinationMessageHandler;
|
import org.springframework.messaging.simp.user.UserDestinationMessageHandler;
|
||||||
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
|
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
|
||||||
import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.messaging.simp.handler.UserSessionRegistry;
|
import org.springframework.messaging.simp.user.UserSessionRegistry;
|
||||||
import org.springframework.scheduling.TaskScheduler;
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.springframework.messaging.Message;
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.MessageChannel;
|
import org.springframework.messaging.MessageChannel;
|
||||||
import org.springframework.messaging.simp.SimpMessageType;
|
import org.springframework.messaging.simp.SimpMessageType;
|
||||||
import org.springframework.messaging.simp.handler.UserSessionRegistry;
|
import org.springframework.messaging.simp.user.UserSessionRegistry;
|
||||||
import org.springframework.messaging.simp.stomp.*;
|
import org.springframework.messaging.simp.stomp.*;
|
||||||
import org.springframework.messaging.support.MessageBuilder;
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
@@ -66,7 +66,7 @@ public class StompSubProtocolHandler implements SubProtocolHandler {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide a registry with which to register active user session ids.
|
* Provide a registry with which to register active user session ids.
|
||||||
* @see org.springframework.messaging.simp.handler.UserDestinationMessageHandler
|
* @see org.springframework.messaging.simp.user.UserDestinationMessageHandler
|
||||||
*/
|
*/
|
||||||
public void setUserSessionRegistry(UserSessionRegistry registry) {
|
public void setUserSessionRegistry(UserSessionRegistry registry) {
|
||||||
this.userSessionRegistry = registry;
|
this.userSessionRegistry = registry;
|
||||||
|
|||||||
@@ -31,11 +31,11 @@ import org.springframework.messaging.converter.CompositeMessageConverter;
|
|||||||
import org.springframework.messaging.converter.MessageConverter;
|
import org.springframework.messaging.converter.MessageConverter;
|
||||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||||
import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler;
|
import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler;
|
||||||
import org.springframework.messaging.simp.handler.DefaultUserDestinationResolver;
|
import org.springframework.messaging.simp.user.DefaultUserDestinationResolver;
|
||||||
import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler;
|
import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler;
|
||||||
import org.springframework.messaging.simp.handler.UserDestinationMessageHandler;
|
import org.springframework.messaging.simp.user.UserDestinationMessageHandler;
|
||||||
import org.springframework.messaging.simp.handler.UserDestinationResolver;
|
import org.springframework.messaging.simp.user.UserDestinationResolver;
|
||||||
import org.springframework.messaging.simp.handler.UserSessionRegistry;
|
import org.springframework.messaging.simp.user.UserSessionRegistry;
|
||||||
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
|
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
|
||||||
import org.springframework.messaging.support.AbstractSubscribableChannel;
|
import org.springframework.messaging.support.AbstractSubscribableChannel;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
|
|||||||
@@ -24,11 +24,10 @@ import org.mockito.Mockito;
|
|||||||
|
|
||||||
import org.springframework.messaging.MessageChannel;
|
import org.springframework.messaging.MessageChannel;
|
||||||
import org.springframework.messaging.SubscribableChannel;
|
import org.springframework.messaging.SubscribableChannel;
|
||||||
import org.springframework.messaging.simp.handler.DefaultUserSessionRegistry;
|
import org.springframework.messaging.simp.user.DefaultUserSessionRegistry;
|
||||||
import org.springframework.messaging.simp.handler.UserSessionRegistry;
|
import org.springframework.messaging.simp.user.UserSessionRegistry;
|
||||||
import org.springframework.scheduling.TaskScheduler;
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
|
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
|
||||||
import org.springframework.web.socket.config.annotation.WebMvcStompEndpointRegistry;
|
|
||||||
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
|
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
|
||||||
import org.springframework.web.socket.messaging.SubProtocolHandler;
|
import org.springframework.web.socket.messaging.SubProtocolHandler;
|
||||||
import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
|
import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
|
||||||
|
|||||||
Reference in New Issue
Block a user