Search in sources :

Example 1 with SimpSessionScope

use of org.springframework.messaging.simp.SimpSessionScope in project spring-framework by spring-projects.

the class MessageBrokerBeanDefinitionParser method parse.

@Override
public BeanDefinition parse(Element element, ParserContext context) {
    Object source = context.extractSource(element);
    CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
    context.pushContainingComponent(compDefinition);
    Element channelElem = DomUtils.getChildElementByTagName(element, "client-inbound-channel");
    RuntimeBeanReference inChannel = getMessageChannel("clientInboundChannel", channelElem, context, source);
    channelElem = DomUtils.getChildElementByTagName(element, "client-outbound-channel");
    RuntimeBeanReference outChannel = getMessageChannel("clientOutboundChannel", channelElem, context, source);
    channelElem = DomUtils.getChildElementByTagName(element, "broker-channel");
    RuntimeBeanReference brokerChannel = getMessageChannel("brokerChannel", channelElem, context, source);
    RuntimeBeanReference userRegistry = registerUserRegistry(element, context, source);
    Object userDestHandler = registerUserDestHandler(element, userRegistry, inChannel, brokerChannel, context, source);
    RuntimeBeanReference converter = registerMessageConverter(element, context, source);
    RuntimeBeanReference template = registerMessagingTemplate(element, brokerChannel, converter, context, source);
    registerAnnotationMethodMessageHandler(element, inChannel, outChannel, converter, template, context, source);
    RootBeanDefinition broker = registerMessageBroker(element, inChannel, outChannel, brokerChannel, userDestHandler, template, userRegistry, context, source);
    // WebSocket and sub-protocol handling
    ManagedMap<String, Object> urlMap = registerHandlerMapping(element, context, source);
    RuntimeBeanReference stompHandler = registerStompHandler(element, inChannel, outChannel, context, source);
    for (Element endpointElem : DomUtils.getChildElementsByTagName(element, "stomp-endpoint")) {
        RuntimeBeanReference requestHandler = registerRequestHandler(endpointElem, stompHandler, context, source);
        String pathAttribute = endpointElem.getAttribute("path");
        Assert.state(StringUtils.hasText(pathAttribute), "Invalid <stomp-endpoint> (no path mapping)");
        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);
            if (DomUtils.getChildElementByTagName(endpointElem, "sockjs") != null) {
                path = path.endsWith("/") ? path + "**" : path + "/**";
            }
            urlMap.put(path, requestHandler);
        }
    }
    Map<String, Object> scopeMap = Collections.<String, Object>singletonMap("websocket", new SimpSessionScope());
    RootBeanDefinition scopeConfigurer = new RootBeanDefinition(CustomScopeConfigurer.class);
    scopeConfigurer.getPropertyValues().add("scopes", scopeMap);
    registerBeanDefByName("webSocketScopeConfigurer", scopeConfigurer, context, source);
    registerWebSocketMessageBrokerStats(broker, inChannel, outChannel, context, source);
    context.popAndRegisterContainingComponent();
    return null;
}
Also used : CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) Element(org.w3c.dom.Element) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) SimpSessionScope(org.springframework.messaging.simp.SimpSessionScope) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 2 with SimpSessionScope

use of org.springframework.messaging.simp.SimpSessionScope in project spring-framework by spring-projects.

the class WebSocketMessageBrokerConfigurationSupport method webSocketScopeConfigurer.

@Bean
public static CustomScopeConfigurer webSocketScopeConfigurer() {
    CustomScopeConfigurer configurer = new CustomScopeConfigurer();
    configurer.addScope("websocket", new SimpSessionScope());
    return configurer;
}
Also used : SimpSessionScope(org.springframework.messaging.simp.SimpSessionScope) CustomScopeConfigurer(org.springframework.beans.factory.config.CustomScopeConfigurer) Bean(org.springframework.context.annotation.Bean)

Aggregations

SimpSessionScope (org.springframework.messaging.simp.SimpSessionScope)2 CustomScopeConfigurer (org.springframework.beans.factory.config.CustomScopeConfigurer)1 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)1 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)1 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)1 Bean (org.springframework.context.annotation.Bean)1 Element (org.w3c.dom.Element)1