Search code examples
spring-websocketspring-messagingspring-session

spring-messaging xml config with stomp and spring-sessions


I'm trying to set up WebSockets with spring-messaging using stomp, and using redis-backed sessions with spring-session. Our application context is wired via xml, and spring-session is working with the non-websocket portion of the application. The relevant config for websocket is as follows

    <websocket:message-broker application-destination-prefix="/streaming" >
    <websocket:stomp-endpoint path="/data"> 
        <websocket:sockjs session-cookie-needed="false" />
    </websocket:stomp-endpoint>
    <websocket:stomp-broker-relay prefix="/topic" relay-host="${jms_hostname}" relay-port="${jms_stomp_port}" />
    <websocket:client-inbound-channel>
        <websocket:interceptors>
            <ref bean="sessionRepoMessageInterceptor"/>
            <ref bean="authenticationValidationInterceptor" />
            <ref bean="selectorValidationInterceptor" />
            <ref bean="selectorQuotingInterceptor" /> <!-- comes after we have validated the selector, we now shim it so JMS understands it -->
        </websocket:interceptors>
    </websocket:client-inbound-channel>
</websocket:message-broker>

I have defined what I think are the necessary beans for spring-session's integration with web sockets here:

<bean id="redisSessionBackedWebsocketHandler" class="org.springframework.session.web.socket.server.">
</bean>

<bean id="sessionRepoMessageInterceptor" class="org.springframework.session.web.socket.server.SessionRepositoryMessageInterceptor">
</bean>

 <bean id="webSocketRegistryListener" class="org.springframework.session.web.socket.handler.WebSocketRegistryListener">
 </bean>

but I'm not sure where I would wire them in to the web socket configuration, and have not been able to find any doc on how to do it this way.

Thoughts?


Solution

  • The Spring Session WebSocket contains the config just only for the Java & Annotation variant.

    And according to the Spring Session Docs the AbstractSessionWebSocketMessageBrokerConfigurer does the stuff for seamless integration between Spring Session and Spring WebSockets. However there we can see some paragraph, what it does:

    To hook in the Spring Session support, we need to ensure ...

    To be honest it isn't so easy to configure that stuff from XML.

    Feel free to follow with the issue: https://github.com/spring-projects/spring-session/issues/101