0
Client Code:
$scope.socket = new SockJS("ws/ws"); 
$scope.stompClient = Stomp.over($scope.socket); 
$scope.stompClient.connect("guest", "guest",connectCallback, errorCallback);

//in connectCallback
$scope.stompClient.subscribe('/topic/agent-sendstatus', showScreenPop);

Java Code:
    @MessageMapping("/agent-sendstatus")
        public void testmethod()
        {
            //How do i get ServletContext here to further implement solution?
            template.convertAndSend("/topic/agent-sendstatus","bcd");
        }

Please suggest. I am getting session using SimpMessageHeaderAccessor in the controller but i need ServletContext too. Is there some way in Spring?

abcd
  • 95
  • 2
  • 8
  • What are you really expecting from the context? – Rafa Sep 25 '14 at 06:06
  • Well, i need all the attributes from the Context. – abcd Sep 25 '14 at 08:31
  • Your answer was already clear for me, but what exactly do you need? The answer from sergi is true. in websockets there is HTTP only at the very beginning (in the handshake), and all the further communication goes through a socket. Maybe there is another way to get the information that you need (considering that you know the information that you need) – Rafa Sep 25 '14 at 11:28

1 Answers1

1

When you upgrade to WebSocket there's no HTTP involved in the communication, the only place where you have HTTP is during the handshake. You could implement a HandshakeInterceptor to get the ServletContext and expose any parameter to the WebSocket session, so you can get them in your message handler method with a HeaderAccessor. Check out the HttpSessionHandshakeInterceptor for an example.

Sergi Almar
  • 8,054
  • 3
  • 32
  • 30