2017-01-30 124 views
0

是否有任何內置屬性來獲取Spring WebSocketSession的開始時間?開始的時候,我指的是會話開始的時間或websocket連接打開的時間?春季websocket會話開始時間

UPDATE:

我有一個TestWebSocketService哪裏 「存儲」 WebSocket的會話。在這裏,我想獲得有關會話的信息,如會話開始時間(連接開始時間)等。

WebSocketHandler:

@Component 
public class TestWebsocketHandler extends TextWebSocketHandler{ 

    private final TestWebSocketService testWebSocketService; 

    @Autowired 
    public TestWebsocketHandler(TestWebSocketService testWebSocketService){ 
     this.testWebSocketService = testWebSocketService; 
    } 


    @Override 
    public void afterConnectionEstablished(WebSocketSession session) throws Exception {   

     this.testWebSocketService.setSession(session); 
    } 

    @Override 
    protected void handleTextMessage(WebSocketSession session, TextMessage requestMessage) throws Exception {  
     ... 
    } 
} 

WebSocketService:

@Component 
public class TestWebSocketServiceImpl implements TestWebSocketService { 

    private WebSocketSession session; 

    public TestWebSocketServiceImpl() {} 


    @Override 
    public void setSession(WebSocketSession session) { 
     this.session = session; 
    } 
} 
+0

你可以使用'HttpSession#getCreationTime()'http://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpSession.html#getCreationTime-- –

+0

@ redflar3我怎樣才能獲得HttpSession? – CPA

+0

你可以給你一些代碼的例子,你想獲得會話開始時間 –

回答