Controller component issue with Spring and SockJs
<p>I have a problem with a configuration of a WebSocket using Spring and SockJs.</p>

<p>I have configured all my app like Spring Documentation, the connection seems to be fine, but when I send a message the Controller is never involved and it doesn't work.</p>

<p>This is the Configuration component:</p>

<pre><code>@Configuration
@EnableWebMvc
@EnableWebSocketMessageBroker
public class MyWebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer implements WebSocketConfigurer {

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/mySocket").withSockJS().setInterceptors(new MySocketHandshakeInterceptor());;
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.setApplicationDestinationPrefixes("/app").enableSimpleBroker("/topic");
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {

    }

}
</code></pre>

<p>This is the HandshakeInterceptor implementation:</p>

<pre><code>public class MySocketHandshakeInterceptor implements HandshakeInterceptor {

    @Override
    public void afterHandshake(ServerHttpRequest paramServerHttpRequest, ServerHttpResponse paramServerHttpResponse, WebSocketHandler paramWebSocketHandler, Exception paramException) {
        // TODO Auto-generated method stub
        System.out.println("MySocketHandshakeInterceptor afterHandshake");
    }

    @Override
    public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map&lt;String, Object&gt; paramMap)
            throws Exception {
        System.out.println("MySocketHandshakeInterceptor beforeHandshake");
        return true;
    }

}
</code></pre>

<p>This is the Controller component:</p>

<pre><code>@Controller
public class MySocketController {

    @MessageMapping("/testsocket")
    @SendTo("/topic/testresponse")
    public MessageOut test(MessageIn message) throws Exception {
        System.out.println("MySocketController start");
        System.out.println("MySocketController test "+ message);
        return new MessageOut("test OK");
    }

}
</code></pre>

<p>These are MessageIn and MessageOut:</p>

<pre><code>public class MessageIn {

    private String test;

    /**
     * @return the test
     */
    public String getTest() {
        return test;
    }

}


public class MessageOut {

    private String result;

    public MessageOut(String result) {
        super();
        this.result = result;
    }

    /**
     * @return the test
     */
    public String getResult() {
        return result;
    }

    /**
     * @param result the result to set
     */
    public void setResult(String result) {
        this.result = result;
    }

}
</code></pre>

<p>Finally, this is the client side (javascript):</p>

<pre><code>var socketSession = {};

connectToMySocket();

function connectToVideoSocket() {
    socketSession.socket = new SockJS("/mySocket");
    socketSession.socket.stomp = Stomp.over(socketSession.socket);
    socketSession.socket.stomp.debug = null;

    socketSession.socket.stomp.connect({}, function () {
        socketSession.socket.stomp.subscribe("/topic/testresponse", function (data) {
            console.log(data);
        });
    });

}
</code></pre>

<p>This is the command that I launch to test the socket:</p>

<pre><code>socketSession.socket.stomp.send("app/testsocket", {}, JSON.stringify({'test': 'test'}));
</code></pre>

<p>In the system out console I can only see the two rows:</p>

<pre><code>MySocketHandshakeInterceptor beforeHandshake
MySocketHandshakeInterceptor afterHandshake
</code></pre>

<p>The interceptor works fine, but I don't see any print by the Controller component.</p>

<p>What's wrong?
Thanks.</p>