Java Code Examples for org.springframework.web.socket.config.annotation.StompWebSocketEndpointRegistration

Following code examples demonstrate how to use org.springframework.web.socket.config.annotation.StompWebSocketEndpointRegistrationfrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.web.socket.config.annotation.StompWebSocketEndpointRegistrationand various code implementation of this class.

    public void registerStompEndPoints_isCalled_wasConfiguredCorrectly() {
        StompEndpointRegistry registry = mock(StompEndpointRegistry.class);
        StompWebSocketEndpointRegistration registration = mock(StompWebSocketEndpointRegistration.class);
        when(registry.addEndpoint(anyString())).thenReturn(registration);
        when(registration.setAllowedOrigins(anyString())).thenReturn(registration);

        config.registerStompEndpoints(registry);

        verify(registry).addEndpoint(anyString());
        verify(registration).withSockJS();
    } 


    public void stompEndpointIsRegistered() {

        StompWebSocketEndpointRegistration registration = mock(StompWebSocketEndpointRegistration.class);
        OngoingStubbing<StompWebSocketEndpointRegistration> registry =
                when(mock(StompEndpointRegistry.class).addEndpoint(any())).thenReturn(registration);

        testSubject.registerStompEndpoints(registry.getMock());

        verify(registration).withSockJS();
    } 

    public void registerStompEndpoints(StompEndpointRegistry registry) {
        final StompWebSocketEndpointRegistration stompWebSocketEndpointRegistration = registry
                .addEndpoint("*", Topics.WS.ROOT.IOT_DISPATCHER_WEBSOCKET);
        stompWebSocketEndpointRegistration.setAllowedOrigins("*");
        stompWebSocketEndpointRegistration.withSockJS();
    } 

    public void shouldRegisterStompEndpoints() {

        when(stompEndpointRegistry.addEndpoint(WEBSOCKET_ENDPOINT_ALERTS))
                .thenReturn(stompWebSocketEndpointRegistration);

        config.registerStompEndpoints(stompEndpointRegistry);

        verify(stompEndpointRegistry, atLeastOnce()).addEndpoint(WEBSOCKET_ENDPOINT_ALERTS);
        verify(stompWebSocketEndpointRegistration, atLeastOnce()).withSockJS();
    } 

    public void registerStompEndpoints(StompEndpointRegistry registry) {
        StompWebSocketEndpointRegistration endPoint = registry.addEndpoint("/sns_ws");
        endPoint.setAllowedOrigins("*");
        endPoint.addInterceptors(new HttpSessionHandshakeInterceptor());
        endPoint.withSockJS();
        
        AbstractSubscribableChannel clientOutboundChannel = configuration.clientOutboundChannel();
		clientOutboundChannel.addInterceptor(new MemberInitChannelInterceptorAdapter());
    } 

Advertisement
Javadoc
A contract for configuring a STOMP over WebSocket endpoint. @author Rossen Stoyanchev @since 4.0
Advertisement