title: Spring Boot - websocket controller problems
body: <p>I'm trying to implement some websocket stuff in my app. I'm using Spring Boot and Groovy to achieve that. But I have some troubles with websocket messages that are sent but not handled correctly by Spring controller. I tried to search for the same issue but didn't find any useful information.</p>
  
  <p>Currently, to simplify I used the same classes as here: <a href="https://github.com/spring-guides/gs-messaging-stomp-websocket" rel="nofollow">https://github.com/spring-guides/gs-messaging-stomp-websocket</a></p>
  
  <p>When I run my application, in console I see this:</p>
  
  <blockquote>
    <p>INFO 3778 --- [           main] s.a.s.SimpAnnotationMethodMessageHandler : Mapped "{[/hello/**],messageType=[MESSAGE]}" onto public org.myapp.Greeting org.myapp.GreetingController.greeting(org.myapp.HelloMessage) throws java.lang.Exception</p>
  </blockquote>
  
  <p>so it looks good. But in fact, it isn't. My controller code:</p>
  
  <pre class="lang-groovy prettyprint-override"><code>@Controller
  class GreetingController {
  
  @MessageMapping("/hello/**")
  @SendTo("/topic/greetings")
  Greeting greeting(HelloMessage message) throws Exception {
    return new Greeting("Hello, " + message.getName() + "!")
  }
  
  }
  </code></pre>
  
  <p>and my websocket configuration is:</p>
  
  <pre class="lang-groovy prettyprint-override"><code>@Configuration
  @EnableWebSocketMessageBroker
  class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
  
    @Override
    void configureMessageBroker(MessageBrokerRegistry config) {
      config.enableSimpleBroker("/topic")
      config.setApplicationDestinationPrefixes("/app")
    }
  
    @Override
    void registerStompEndpoints(StompEndpointRegistry registry) {
      registry.addEndpoint("/hello").withSockJS()
    }
  
  }
  </code></pre>
  
  <p>I can connect to above websocket but sending any messages doesn't give any effects. I'm doing it with the following javascript code:</p>
  
  <pre class="lang-js prettyprint-override"><code>var stompClient = null;
  var socket = new SockJS('/hello');
  
  stompClient = Stomp.over(socket);
  stompClient.connect({}, function (frame) {
    console.log('Connected: ' + frame);
    stompClient.subscribe('/topic/greetings', function (greeting) {
      console.log('received message');
      console.log(greeting);
    });
    stompClient.send("app/hello", {}, JSON.stringify({'name': 'my name'}));
  });
  </code></pre>
  
  <p>It sends messages but there is no reply. I added printing messages in controller method and it doesn't print anything so sent greeting message isn't passed to the controller method, it isn't even invoked. I tried even  setting mapping to handle all messages <code>@MessageMapping('/**')</code> but it didn't work.</p>
  
  <p>This is Spring log (debug level) after invoking above javascript code:</p>
  
  <blockquote>
    <p>2015-09-02 21:47:49.593 DEBUG 3778 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/hello/info]
    2015-09-02 21:47:49.593 DEBUG 3778 --- [nio-8080-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /hello/info
    2015-09-02 21:47:49.593 DEBUG 3778 --- [nio-8080-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/hello/info]
    2015-09-02 21:47:49.593 DEBUG 3778 --- [nio-8080-exec-5] o.s.w.s.handler.SimpleUrlHandlerMapping  : Matching patterns for request [/hello/info] are [/hello/<strong>]
    2015-09-02 21:47:49.593 DEBUG 3778 --- [nio-8080-exec-5] o.s.w.s.handler.SimpleUrlHandlerMapping  : URI Template variables for request [/hello/info] are {}
    2015-09-02 21:47:49.593 DEBUG 3778 --- [nio-8080-exec-5] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapping [/hello/info] to HandlerExecutionChain with handler [org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler@31e2232f] and 1 interceptor
    2015-09-02 21:47:49.593 DEBUG 3778 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/hello/info] is: -1
    2015-09-02 21:47:49.594 DEBUG 3778 --- [nio-8080-exec-5] o.s.w.s.s.t.h.DefaultSockJsService       : GET <a href="http://localhost:8080/hello/info?t=1441223269561" rel="nofollow">http://localhost:8080/hello/info?t=1441223269561</a>
    2015-09-02 21:47:49.594 DEBUG 3778 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
    2015-09-02 21:47:49.594 DEBUG 3778 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Successfully completed request
    2015-09-02 21:47:49.600 DEBUG 3778 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/hello/721/4hmzc45f/websocket]
    2015-09-02 21:47:49.601 DEBUG 3778 --- [nio-8080-exec-8] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /hello/721/4hmzc45f/websocket
    2015-09-02 21:47:49.601 DEBUG 3778 --- [nio-8080-exec-8] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/hello/721/4hmzc45f/websocket]
    2015-09-02 21:47:49.601 DEBUG 3778 --- [nio-8080-exec-8] o.s.w.s.handler.SimpleUrlHandlerMapping  : Matching patterns for request [/hello/721/4hmzc45f/websocket] are [/hello/</strong>]
    2015-09-02 21:47:49.601 DEBUG 3778 --- [nio-8080-exec-8] o.s.w.s.handler.SimpleUrlHandlerMapping  : URI Template variables for request [/hello/721/4hmzc45f/websocket] are {}
    2015-09-02 21:47:49.601 DEBUG 3778 --- [nio-8080-exec-8] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapping [/hello/721/4hmzc45f/websocket] to HandlerExecutionChain with handler [org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler@31e2232f] and 1 interceptor
    2015-09-02 21:47:49.601 DEBUG 3778 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/hello/721/4hmzc45f/websocket] is: -1
    2015-09-02 21:47:49.603 DEBUG 3778 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
    2015-09-02 21:47:49.603 DEBUG 3778 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet        : Successfully completed request
    2015-09-02 21:47:49.604 DEBUG 3778 --- [nio-8080-exec-8] s.w.s.h.LoggingWebSocketHandlerDecorator : New WebSocketServerSockJsSession[id=4hmzc45f]</p>
  </blockquote>
  
  <p>I tried to use the same dependencies (I'm using Gradle if that's important) and classes as gs-messaging-stomp-websocket (<a href="https://github.com/spring-guides/gs-messaging-stomp-websocket" rel="nofollow">https://github.com/spring-guides/gs-messaging-stomp-websocket</a>) but didn't help.</p>
  
  <p>I don't have any idea what's going on here and why isn't that code working.</p>
  
  <p>I would appreciate any help. Thanks in advance.</p>