1 package enhydraManager.business; 2 3 import java.util.Vector ; 4 import java.util.Enumeration ; 5 6 import com.lutris.appserver.server.httpPresentation.servlet.*; 7 8 import com.lutris.appserver.server.*; 9 import com.lutris.appserver.server.session.*; 10 import com.lutris.appserver.server.session.Session; 11 import com.lutris.appserver.server.sessionContainerAdapter.*; 12 import enhydraManager.spec.*; 13 14 import javax.servlet.*; 15 import javax.servlet.http.*; 16 import org.apache.catalina.*; 17 import org.apache.catalina.core.StandardContext; 18 import org.apache.catalina.core.*; 19 20 import java.util.Date ; 21 22 public class AppDetailSessionListImpl implements AppDetailSessionList{ 23 24 25 public Vector [] getList(String service,String host,String application) throws Exception { 26 27 Vector [] result = new Vector [5]; 28 result[0] = new Vector (); 29 result[1] = new Vector (); 30 result[2] = new Vector (); 31 result[3] = new Vector (); 32 result[4] = new Vector (); 33 34 Application app = null; 35 SessionManager sessionManager = null; 36 String sessionID=null; 37 Session session = null; 38 39 StandardContext sc=GlobalImpl.getServlet(service,host,application); 40 41 try{ 42 43 Container[] wrappers=sc.findChildren(); 44 45 46 StandardWrapper sw=(StandardWrapper)wrappers[0]; 47 48 Servlet s=sw.allocate(); 49 50 51 if (s instanceof HttpPresentationServlet){ 52 app = ((HttpPresentationServlet)s).getApplication(); 53 54 sessionManager = app.getSessionManager(); 55 56 if ((sessionManager instanceof ContainerAdapterSessionManager) || (sessionManager instanceof JmxContainerAdapterSessionManager)) 57 { 58 Manager manager=sc.getManager(); 59 org.apache.catalina.Session[] ses= manager.findSessions(); 60 try{ 61 for(int i=0;i<ses.length;i++) 62 { 63 64 com.lutris.appserver.server.session.Session es=null; 65 HttpSession httpsession=null; 66 67 httpsession=ses[i].getSession(); 68 es=(com.lutris.appserver.server.session.Session)httpsession.getAttribute("session"); 69 70 try { 71 result[0].addElement(ses[i].getId()); 72 }catch (Exception e){ 73 result[0].addElement("Couldn't get Enhydra Session ID !"); 74 } 75 76 if (httpsession!=null){ 77 manageEnhydraData(es,result); 78 manageTime(httpsession,result); 79 }else { 80 result[1].addElement("Couldn't get Enhydra Session User!"); 81 result[2].addElement("Couldn't get SessionData!"); 82 result[3].addElement("Couldn't get session creation time!"); 83 result[4].addElement("Couldn't get session last access time!"); 84 } 85 } 87 } catch (Exception ex){ 88 System.out.println("Couldn't get number of active sessions for "+application+" servlet!"); 89 result[0].clear(); 90 result[1].clear(); 91 result[2].clear(); 92 result[3].clear(); 93 result[4].clear(); 94 } 95 96 97 }else{ 98 try{ 99 Enumeration sessionKeys = sessionManager.getSessionKeys(); 100 101 while (sessionKeys.hasMoreElements()) { 102 sessionID = (String ) sessionKeys.nextElement(); 103 104 if (sessionManager.sessionExists(sessionID)){ 105 result[0].addElement(sessionID); 106 session = sessionManager.getSession(Thread.currentThread(),sessionID); 107 108 if (session!=null){ 109 110 manageEnhydraData(session,result); 111 manageTime(session.getHttpSession(),result); 112 113 }else { 114 result[1].addElement("Couldn't get Enhydra Session User!"); 115 result[2].addElement("Couldn't get SessionData!"); 116 result[3].addElement("Couldn't get session creation time!"); 117 result[4].addElement("Couldn't get session last access time!"); 118 } 119 }else { 120 result[0].addElement("Couldn't get SessionID!"); 121 result[1].addElement("Couldn't get Enhydra Session User!"); 122 result[2].addElement("Couldn't get SessionData!"); 123 result[3].addElement("Couldn't get session creation time!"); 124 result[4].addElement("Couldn't get session last access time!"); 125 } 126 127 128 } 130 } catch (SessionException ex){ 131 System.out.println("Couldn't get number of active sessions for "+application+" servlet!"); 132 result[0].clear(); 133 result[1].clear(); 134 result[2].clear(); 135 result[3].clear(); 136 result[4].clear(); 137 } 138 139 140 } 142 143 }else{ try{ 145 Manager manager=sc.getManager(); 146 org.apache.catalina.Session[] ses= manager.findSessions(); 147 HttpSession httpsession=null; 148 149 for(int i=0;i<ses.length;i++) 150 { 151 httpsession=ses[i].getSession(); 152 153 try{ 154 result[0].addElement(ses[i].getId()); 155 }catch (Exception e){ 156 result[0].addElement("Couldn't get Session ID !"); 157 } 158 result[1].addElement("Couldn't get Enhydra Session User!"); 159 result[2].addElement("Couldn't get SessionData!"); 160 manageTime(httpsession,result); 161 162 } 163 164 } catch (Exception ex){ 165 System.out.println("Couldn't get number of active sessions for "+application+" servlet!"); 166 result[0].clear(); 167 result[1].clear(); 168 result[2].clear(); 169 result[3].clear(); 170 result[4].clear(); 171 } 172 173 } 174 175 sw.deallocate(s); 176 177 }catch(ServletException e){ 178 179 System.out.println("Couldn't acess to servlet :"+application+" !"); 180 result[0].clear(); 181 result[1].clear(); 182 result[2].clear(); 183 result[3].clear(); 184 result[4].clear(); 185 186 } 187 188 return result; 189 } 190 191 private void manageTime(HttpSession httpsession,Vector [] result){ 192 193 try { 194 Date d = new Date (httpsession.getCreationTime()); 195 result[3].addElement( d.toString()); 196 }catch (Exception e){ 197 result[3].addElement("Couldn't get session creation time!"); 198 } 199 try { 200 Date d = new Date (httpsession.getLastAccessedTime()); 201 result[4].addElement( d.toString()); 202 }catch (Exception e){ 203 result[4].addElement("Couldn't get session last access time!"); 204 } 205 206 } 207 208 209 private void manageEnhydraData(Session session,Vector [] result){ 210 try { 211 result[1].addElement(session.getUser().getName()); 212 }catch (Exception e){ 213 result[1].addElement("Couldn't get Enhydra Session User!"); 214 } 215 try { 216 result[2].addElement(session.getSessionData().toString()); 217 }catch (Exception e){ 218 result[2].addElement("Couldn't get SessionData!"); 219 } 220 221 222 } 223 224 } 225 226 | Popular Tags |