resetting http session time out with httpSession.setMaxInactiveInterval(sec) is not working

419 views Asked by At

setMaxInactiveInterval(10*60); to set maximum inactive interval to 10 minutes when user logged in, and reseeting it to -1 (undefined) when user opened websocket, since web socket is a protected resource in the web application, that is to say, required an authorized user to access it. I am able to make other request when websocket connecttion is opened, once user closes web socket connection i am re-setting httpsession timeout to 10 mins but httpsession invalidated immediatly after web socket closed. how to keep httpsession alive after closing websocket connection? here is code snippet

@OnOpen
public void onOpen(final Session s, EndpointConfig config)throws IOException   {
    this.httpSession = (HttpSession)   
    config.getUserProperties().get(HttpSession.class.getName());

    //maintaining all opened websocket for httpsession in one map 
    webSession.put(s,httpsession)
    httpSession.setMaxInactiveInterval(-1);
}

@OnClose
public void onClose( Session session,CloseReason reason) {
    try {
        HttpSession http_session= webSession.get(Session);
            http_session.setMaxInactiveInterval(10*60);     

    } catch (IOException e) {
        e.printStackTrace();
    }
}
0

There are 0 answers