Spring websocket无法进入handleMessage方法
如题,通过调试可以看到进入了handspake的interceptor和handle类的afterConnectionEstablished方法,但无法进入handleMessage方法造成无法转发消息,求高人指点。附上代码。
package com.angularjs.utils;
import java.util.HashMap;
import java.util.Map;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;
public class TestHandler extends TextWebSocketHandler {
private static Map<String,WebSocketSession> sessionList = new HashMap<String,WebSocketSession>();
@Override
public void afterConnectionEstablished(WebSocketSession session)
throws Exception {
// TODO Auto-generated method stub
super.afterConnectionEstablished(session);
sessionList.put(session.getAttributes().get("username").toString(), session);
}
@Override
protected void handleTextMessage(WebSocketSession session,
TextMessage message) throws Exception {
// TODO Auto-generated method stub
super.handleTextMessage(session, message);
System.out.println("begin send msg");
WebSocketSession usersession = sessionList.get(session.getAttributes().get("username").toString());
if(usersession!=null && usersession.isOpen()){
usersession.sendMessage(message);
}
}
@Override
public void handleTransportError(WebSocketSession session,
Throwable exception) throws Exception {
// TODO Auto-generated method stub
super.handleTransportError(session, exception);
if (session.isOpen()){
sessionList.remove(session.getAttributes().get("username").toString());
}
}
@Override
public void afterConnectionClosed(WebSocketSession session,
CloseStatus status) throws Exception {
super.afterConnectionClosed(session, status);
if (session.isOpen()){
sessionList.remove(session.getAttributes().get("username").toString());
}
}
}
websocket java webapp java-ee spring