Reputation: 2459
I would like to have the equivalent of this XML configuration (taken Here), but using Java config:
<bean id="customHandler" class="app.wsock.CustomHandler"/>
<websocket:message-broker application-destination-prefix="/app">
<websocket:stomp-endpoint path="/foo">
<websocket:handshake-handler ref="customHandler"/>
</websocket:stomp-endpoint>
<websocket:simpl-broker prefix="/topic,/queue" />
</websocket:message-broker>
My goal is to build a class that limits the connection to my STOMP endpoint (i.e.: to his websocket) based on some criteria.
I don't want to use XML to configure my endpoint, how do I convert that snippet to Java Config?
Upvotes: 3
Views: 5955
Reputation: 121550
Something like this:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Bean
public HandshakeHandler handshakeHandler() {
return new app.wsock.CustomHandler();
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/foo").setHandshakeHandler(handshakeHandler());
}
@Override
public void configureMessageBroker(MessageBrokerRegistry configurer) {
configurer.enableStompBrokerRelay("/topic", "/queue");
}
}
Upvotes: 6