1 Reply Latest reply: Apr 12, 2012 1:06 AM by murali veligeti - oracle RSS

    Obtains a list of session ID

    833318
      Hello,

      I would like obtains a list of active session (session id) on weblogic.

      Is it possible?

      Thanks!
        • 1. Re: Obtains a list of session ID
          murali veligeti - oracle
          Hi,

          There is no way to list all the sessionIds present in weblogic server.

          But you need to implement your own mechanism where you can retrieve all the session IDs. For this you need to implement HttpSessionListener where when ever you create a session store the session id in ArrayList and when ever the session is destroyed remove from the ArrayList and this ArrayList will have the sessionids present in weblogic server. Please find the implementation below.

          import javax.servlet.*;
          import javax.servlet.http.*;
          import java.util.Map;
          import java.util.HashMap;
          public class ListenerSession
          implements HttpSessionListener {

          public List sessionIDList = new ArrayList();
          public ListenerSession() {
          }
          public void sessionCreated(HttpSessionEvent sessionEvent) {
          // Get the session that was created
          HttpSession session = sessionEvent.getSession();
          sessionIDList.add(session.getId);
          }
          public void sessionDestroyed(HttpSessionEvent sessionEvent) {
          // Get the session that was invalidated
          HttpSession session = sessionEvent.getSession();
          sessionIDList.remove(session.getId);
          }
          }

          Please let me know if you face any issues in implemention Listeners.

          Thanks & Regards,
          Murali.
          ===========