title: How to get websocket response on server with spring+stomp+sockjs?
body: <p>In my javascript I create a websocket:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    /// Create stomp client over sockJS protocol (see Note 1)
    var socket = new SockJS("http://localhost:8080/hello");
    var stompClient = Stomp.over(socket);
  
    // callback function to be called when stomp client is connected to server (see Note 2)
    var connectCallback = function() {
      alert("connected!");
      stompClient.subscribe('http://localhost:8080/topic/greetings', function(greeting){
        alert(JSON.parse(greeting.body).content);
      });
    };
  
    // callback function to be called when stomp client could not connect to server (see Note 3)
    var errorCallback = function(error) {
      // display the error's message header:
      alert(error.headers.toString);
    };
  
    // Connect as guest (Note 4)
    stompClient.connect("guest", "guest", connectCallback, errorCallback);
    &lt;/script&gt;
  </code></pre>
  
  <p>And also I have a simple form(name testWebSocket.jsp) with button and next function:</p>
  
  <pre><code>  // function to send message
   function fnSayHi() {
      stompClient.send("/hello", JSON.stringify({ 'name': 'Joe' }));
   }
   ....
   &lt;input onclick="fnSayHi();" type="button"&gt;
  </code></pre>
  
  <p>When I click on button in my view, in the console browser we see sending data, (you might see on image) and I want to get sent data websocket and display them in server console(like System.out.println(..))? Thanks.!</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>@Controller
  public class MessageController {
  
  @RequestMapping("/test")
  public ModelAndView getBodyPage() throws SQLException {
      ModelAndView modelAndView = new ModelAndView("testWebSocket");
      return modelAndView;
  }
  
  @MessageMapping("/hello")
  @SendTo("/topic/greetings")
  public Greeting greeting(String name) throws Exception {
      System.out.println(name);//here!
      return new Greeting("Hello, " + name + "!");
  }
  }
  </code></pre>
  
  <p><strong>part of spring-config:</strong></p>
  
  <pre><code>    &lt;!-- WebSocket --&gt;
  &lt;websocket:message-broker application-destination-prefix="/app"&gt;
      &lt;websocket:stomp-endpoint path="/hello"&gt;
          &lt;websocket:sockjs/&gt;
      &lt;/websocket:stomp-endpoint&gt;
      &lt;websocket:simple-broker prefix="/topic"/&gt;
  &lt;/websocket:message-broker&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/bp0JM.png" alt="enter image description here"></p>