Trim tokenized strings in websocket namespace

Issue: SPR-11307
This commit is contained in:
Rossen Stoyanchev 2014-01-14 12:44:46 -05:00
parent 2dfd69bbb3
commit ea0825c0a6
5 changed files with 22 additions and 13 deletions

View File

@ -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.
@ -19,6 +19,7 @@ package org.springframework.web.socket.config;
import java.util.Arrays;
import java.util.List;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.BeanDefinition;
@ -131,7 +132,8 @@ class HandlersBeanDefinitionParser implements BeanDefinitionParser {
ManagedMap<String, Object> urlMap = new ManagedMap<String, Object>();
Object source = parserContext.extractSource(mappingElement);
List<String> mappings = Arrays.asList(mappingElement.getAttribute("path").split(","));
String path = mappingElement.getAttribute("path");
List<String> mappings = Arrays.asList(StringUtils.tokenizeToStringArray(path, ","));
RuntimeBeanReference webSocketHandlerReference = new RuntimeBeanReference(mappingElement.getAttribute("handler"));
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
@ -168,7 +170,8 @@ class HandlersBeanDefinitionParser implements BeanDefinitionParser {
ManagedMap<String, Object> urlMap = new ManagedMap<String, Object>();
Object source = parserContext.extractSource(mappingElement);
List<String> mappings = Arrays.asList(mappingElement.getAttribute("path").split(","));
String pathValue = mappingElement.getAttribute("path");
List<String> mappings = Arrays.asList(StringUtils.tokenizeToStringArray(pathValue, ","));
RuntimeBeanReference webSocketHandlerReference = new RuntimeBeanReference(mappingElement.getAttribute("handler"));
ConstructorArgumentValues cavs = new ConstructorArgumentValues();

View File

@ -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.
@ -135,7 +135,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
String pathAttribute = stompEndpointElem.getAttribute("path");
Assert.state(StringUtils.hasText(pathAttribute), "Invalid <stomp-endpoint> (no path mapping)");
List<String> paths = Arrays.asList(pathAttribute.split(","));
List<String> paths = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ","));
for(String path : paths) {
path = path.trim();
Assert.state(StringUtils.hasText(path), "Invalid <stomp-endpoint> path attribute: " + pathAttribute);
@ -286,14 +286,14 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
if (simpleBrokerElem != null) {
String prefix = simpleBrokerElem.getAttribute("prefix");
cavs.addIndexedArgumentValue(3, Arrays.asList(prefix.split(",")));
cavs.addIndexedArgumentValue(3, Arrays.asList(StringUtils.tokenizeToStringArray(prefix, ",")));
RootBeanDefinition brokerDef = new RootBeanDefinition(SimpleBrokerMessageHandler.class, cavs, null);
registerBeanDef(brokerDef, parserCxt, source);
}
else if (brokerRelayElem != null) {
String prefix = brokerRelayElem.getAttribute("prefix");
cavs.addIndexedArgumentValue(3, Arrays.asList(prefix.split(",")));
cavs.addIndexedArgumentValue(3, Arrays.asList(StringUtils.tokenizeToStringArray(prefix, ",")));
MutablePropertyValues mpvs = new MutablePropertyValues();
String relayHost = brokerRelayElem.getAttribute("relay-host");
@ -397,7 +397,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
RuntimeBeanReference brokerMessageConverterRef, RuntimeBeanReference brokerMessagingTemplateRef,
ParserContext parserCxt, Object source) {
String applicationDestinationPrefix = messageBrokerElement.getAttribute("application-destination-prefix");
String appDestPrefix = messageBrokerElement.getAttribute("application-destination-prefix");
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addIndexedArgumentValue(0, clientInChannelDef);
@ -405,7 +405,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
cavs.addIndexedArgumentValue(2, brokerMessagingTemplateRef);
MutablePropertyValues mpvs = new MutablePropertyValues();
mpvs.add("destinationPrefixes",Arrays.asList(applicationDestinationPrefix.split(",")));
mpvs.add("destinationPrefixes",Arrays.asList(StringUtils.tokenizeToStringArray(appDestPrefix, ",")));
mpvs.add("messageConverter", brokerMessageConverterRef);
RootBeanDefinition annotationMethodMessageHandlerDef =

View File

@ -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.

View File

@ -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.
@ -83,10 +83,12 @@ public class MessageBrokerBeanDefinitionParserTests {
HttpRequestHandler httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/foo");
assertNotNull(httpRequestHandler);
assertThat(httpRequestHandler, Matchers.instanceOf(WebSocketHttpRequestHandler.class));
WebSocketHttpRequestHandler wsHttpRequestHandler = (WebSocketHttpRequestHandler) httpRequestHandler;
WebSocketHandler wsHandler = unwrapWebSocketHandler(wsHttpRequestHandler.getWebSocketHandler());
assertNotNull(wsHandler);
assertThat(wsHandler, Matchers.instanceOf(SubProtocolWebSocketHandler.class));
SubProtocolWebSocketHandler subProtocolWsHandler = (SubProtocolWebSocketHandler) wsHandler;
assertEquals(Arrays.asList("v10.stomp", "v11.stomp", "v12.stomp"), subProtocolWsHandler.getSubProtocols());
@ -97,6 +99,7 @@ public class MessageBrokerBeanDefinitionParserTests {
httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/test/**");
assertNotNull(httpRequestHandler);
assertThat(httpRequestHandler, Matchers.instanceOf(SockJsHttpRequestHandler.class));
SockJsHttpRequestHandler sockJsHttpRequestHandler = (SockJsHttpRequestHandler) httpRequestHandler;
wsHandler = unwrapWebSocketHandler(sockJsHttpRequestHandler.getWebSocketHandler());
assertNotNull(wsHandler);
@ -111,12 +114,15 @@ public class MessageBrokerBeanDefinitionParserTests {
assertThat(userDestResolver, Matchers.instanceOf(DefaultUserDestinationResolver.class));
DefaultUserDestinationResolver defaultUserDestResolver = (DefaultUserDestinationResolver) userDestResolver;
assertEquals("/personal/", defaultUserDestResolver.getDestinationPrefix());
assertSame(stompHandler.getUserSessionRegistry(), defaultUserDestResolver.getUserSessionRegistry());
UserDestinationMessageHandler userDestHandler = this.appContext.getBean(UserDestinationMessageHandler.class);
assertNotNull(userDestHandler);
SimpleBrokerMessageHandler brokerMessageHandler = this.appContext.getBean(SimpleBrokerMessageHandler.class);
assertNotNull(brokerMessageHandler);
assertEquals(Arrays.asList("/topic", "/queue"), brokerMessageHandler.getDestinationPrefixes());
List<Class<? extends MessageHandler>> subscriberTypes =
Arrays.<Class<? extends MessageHandler>>asList(SimpAnnotationMethodMessageHandler.class,
UserDestinationMessageHandler.class, SimpleBrokerMessageHandler.class);

View File

@ -12,7 +12,7 @@
<websocket:handshake-handler ref="myHandler"/>
<websocket:sockjs/>
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/topic"/>
<websocket:simple-broker prefix="/topic, /queue"/>
</websocket:message-broker>
<bean id="myHandler" class="org.springframework.web.socket.config.TestHandshakeHandler"/>