KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > enhydraManager > business > ApplicationSessionImpl


1 package enhydraManager.business;
2
3 import java.util.Vector JavaDoc;
4 import java.util.Enumeration JavaDoc;
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 javax.servlet.http.*;
13 import enhydraManager.spec.*;
14 import javax.servlet.*;
15
16 import java.util.Date JavaDoc;
17
18
19
20 import org.apache.catalina.*;
21 import org.apache.catalina.core.*;
22 import org.apache.catalina.core.StandardContext;
23 import org.apache.catalina.session.StandardSession;
24
25
26 public class ApplicationSessionImpl implements ApplicationSession{
27
28
29     public Vector JavaDoc[] getList(String JavaDoc service, String JavaDoc host,String JavaDoc servletID,String JavaDoc sessionID) throws Exception JavaDoc {
30        
31        Vector JavaDoc[] result = new Vector JavaDoc[2];
32        result[0] = new Vector JavaDoc();
33        result[1] = new Vector JavaDoc();
34        Application app = null;
35        SessionManager sessionManager = null;
36        String JavaDoc sessionParam=null;
37        String JavaDoc sessionValue =null;
38        Session session = null;
39    
40    
41     StandardContext sc=GlobalImpl.getServlet(service,host,servletID);
42    
43     try{
44          
45          Container[] wrappers=sc.findChildren();
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            try{
59                Manager manager=sc.getManager();
60                org.apache.catalina.Session ses= manager.findSession(sessionID);
61                 
62                com.lutris.appserver.server.session.Session es=null;
63                HttpSession httpsession=null;
64                
65           
66               
67                if (ses.isValid()){
68                  httpsession=ses.getSession();
69                  
70                es=(com.lutris.appserver.server.session.Session)httpsession.getAttribute("session");
71                         manageEnhydraData(es,result);
72                         manageData(httpsession,result);
73             }else {
74                   // result[0].addElement("Couldn't get Session Parameters!");
75
// result[1].addElement("Couldn't get session parameter values!");
76
result[0].clear();
77                 result[1].clear();
78              }
79               }catch(Exception JavaDoc e){
80                 System.out.println("Couldn't get active session for "+servletID+" servlet!"+e);
81             
82               }
83            
84            
85             }else{
86              
87               try {
88                 if (sessionManager.sessionExists(sessionID)){
89                     session = sessionManager.getSession(Thread.currentThread(),sessionID);
90                      
91                       if (session!=null){
92                       manageEnhydraData(session,result);
93                       manageData(session.getHttpSession(),result);
94                       
95                       }else {
96                     result[0].addElement("Couldn't get Session Parameters!");
97                     result[1].addElement("Couldn't get session parameter values!");
98                   }
99                 }
100            
101              } catch (SessionException ex){
102                 System.out.println("Couldn't get active session for "+servletID+" servlet!");
103                 result[0].clear();
104                 result[1].clear();
105             }
106             
107             
108             }//else
109

110            
111           
112        }else{
113         try{
114           Manager manager=sc.getManager();
115           org.apache.catalina.Session ses= manager.findSession(sessionID);
116           HttpSession httpsession=null;
117       httpsession=ses.getSession();
118           result[0].addElement("Enhydra Session User");
119           result[1].addElement("Couldn't get session user!");
120           result[0].addElement("Session Data");
121           result[1].addElement("Couldn't get SessionData!");
122           manageData(httpsession,result);
123        
124         }catch(Exception JavaDoc e){
125                 System.out.println("Couldn't get active session for "+servletID+" servlet!");
126                 result[0].clear();
127                 result[1].clear();
128               }
129          
130       }
131           
132      sw.deallocate(s);
133     
134          }catch(ServletException e){
135        
136         System.out.println("Couldn't acess to servlet :"+servletID+" !");
137                 result[0].clear();
138                 result[1].clear();
139         
140         }
141        
142        
143        
144        return result;
145     }
146   
147   
148 private void manageData(HttpSession httpsession,Vector JavaDoc[] result){
149     
150     try {
151         result[0].addElement("Session Creation Time");
152         Date JavaDoc d = new Date JavaDoc(httpsession.getCreationTime());
153         result[1].addElement( d.toString());
154         }catch (Exception JavaDoc e){
155        result[1].addElement("Couldn't get session creation time!");
156         }
157     try {
158             result[0].addElement("Session Last Accessed Time");
159         Date JavaDoc d = new Date JavaDoc(httpsession.getLastAccessedTime());
160         result[1].addElement( d.toString());
161     }catch (Exception JavaDoc e){
162         result[1].addElement("Couldn't get session last access time!");
163     }
164     try {
165         Enumeration JavaDoc attEnum = httpsession.getAttributeNames();
166         String JavaDoc temp = null;
167         while (attEnum.hasMoreElements()) {
168                 temp = (String JavaDoc)attEnum.nextElement();
169             result[0].addElement(temp);
170         try {
171             result[1].addElement(((Object JavaDoc)httpsession.getAttribute(temp)).toString());
172         } catch (Exception JavaDoc exept){
173             result[1].addElement(new String JavaDoc("Couldn't get attribute value!"));
174         }
175     }
176     }catch (Exception JavaDoc e){
177             result[0].addElement("Couldn't get session atributes!");
178             result[1].addElement("Couldn't get session atribute values!");
179         }
180     
181   }
182
183 private void manageEnhydraData(Session session,Vector JavaDoc[] result){
184       try {
185     result[0].addElement("Enhydra Session User");
186         result[1].addElement(session.getUser().getName());
187     }catch (Exception JavaDoc e){
188         result[1].addElement("Couldn't get session user!");
189     }
190     try {
191     result[0].addElement("Session Data");
192     result[1].addElement(session.getSessionData().toString());
193     }catch (Exception JavaDoc e){
194     result[1].addElement("Couldn't get SessionData!");
195     }
196
197 }
198
199     
200 }
201
202
Popular Tags