How to close a STOMP websocket in a spring server

Viewed 4845


I am using spring-websocket and spring-messaging (version 4.2.2.RELEASE) to implement STOMP over websockets with a fully-featured broker (Apache ActiveMQ 5.10.0).
My clients are meant to SUBSCRIBE to destinations only - that is they should should not be able to SEND messages. Furthermore, I would like to implement a stricter control over what destinations my clients can subscribe to. In either case (that is when a client tries to send a message or subscribe to an invalid destination) I would like to be able to

  1. send an appropriate error, and/or
  2. close the websocket

Please note that all my destinations are forwarded to ActiveMQ. I thought that I could implement a ChannelInterceptor on the inbound channel, but looking at the API I cannot figure out how to achieve what I want. Is this possible, and what is the best way to go about validating client requests? My websocket configuration is below:

<websocket:message-broker
    application-destination-prefix="/app">
    <websocket:stomp-endpoint path="/pushchannel"/>
    <websocket:stomp-broker-relay relay-host="localhost"
        relay-port="61613" prefix="/topic"
        heartbeat-receive-interval="300000" heartbeat-send-interval="300000" />
    <websocket:client-inbound-channel>
        <websocket:interceptors>
            <bean class="MyClientMessageInterceptor"/>
        </websocket:interceptors>
    </websocket:client-inbound-channel>
</websocket:message-broker>
1 Answers
Related