Add path-helper attribute for websocket namespace

Issue: SPR-11771
This commit is contained in:
Rossen Stoyanchev 2015-04-13 22:39:50 -04:00
parent e4acbae270
commit a3df66931f
3 changed files with 25 additions and 5 deletions

View File

@ -112,13 +112,21 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
context.pushContainingComponent(compDefinition);
RootBeanDefinition handlerMappingDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
String orderAttribute = element.getAttribute("order");
int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute);
handlerMappingDef.getPropertyValues().add("order", order);
String pathHelper = element.getAttribute("path-helper");
if (StringUtils.hasText(pathHelper)) {
handlerMappingDef.getPropertyValues().add("urlPathHelper", new RuntimeBeanReference(pathHelper));
}
ManagedMap<String, Object> urlMap = new ManagedMap<String, Object>();
urlMap.setSource(source);
RootBeanDefinition handlerMappingDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
handlerMappingDef.getPropertyValues().add("order", order);
handlerMappingDef.getPropertyValues().add("urlMap", urlMap);
registerBeanDef(handlerMappingDef, context, source);
Element channelElem = DomUtils.getChildElementByTagName(element, "client-inbound-channel");
@ -172,7 +180,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
}
private RuntimeBeanReference getMessageChannel(String name, Element element, ParserContext context, Object source) {
RootBeanDefinition executor = null;
RootBeanDefinition executor;
if (element == null) {
executor = getDefaultExecutorBeanDefinition(name);
}
@ -526,7 +534,6 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
context.registerComponent(new BeanComponentDefinition(beanDef, name));
}
private static class DecoratingFactoryBean implements FactoryBean<WebSocketHandler> {
private final WebSocketHandler handler;
@ -534,6 +541,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
private final List<WebSocketHandlerDecoratorFactory> factories;
@SuppressWarnings("unused")
private DecoratingFactoryBean(WebSocketHandler handler, List<WebSocketHandlerDecoratorFactory> factories) {
this.handler = handler;
this.factories = factories;

View File

@ -891,6 +891,13 @@
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="path-helper" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
The bean name of the UrlPathHelper to use for the HandlerMapping used to map handshake requests.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:schema>

View File

@ -6,7 +6,8 @@
<websocket:message-broker application-destination-prefix="/app"
user-destination-prefix="/personal"
path-matcher="pathMatcher">
path-matcher="pathMatcher"
path-helper="urlPathHelper">
<!-- message-size=128*1024, send-buffer-size=1024*1024 -->
<websocket:transport message-size="131072" send-timeout="25000" send-buffer-size="1048576">
@ -40,6 +41,10 @@
<property name="pathSeparator" value="." />
</bean>
<bean id="urlPathHelper" class="org.springframework.web.util.UrlPathHelper">
<property name="alwaysUseFullPath" value="true"/>
</bean>
<bean id="myHandler" class="org.springframework.web.socket.config.TestHandshakeHandler"/>
<bean id="barTestInterceptor" class="org.springframework.web.socket.config.BarTestInterceptor"/>
<bean id="scheduler" class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler"/>