KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sessionViewer > SessionViewer


1 /*
2  * sessionViewer
3  * A sample Enhydra Application
4  *
5  */

6
7 package sessionViewer;
8
9 import com.lutris.appserver.server.*;
10 import com.lutris.appserver.server.httpPresentation.*;
11 import com.lutris.appserver.server.session.*;
12 import com.lutris.util.*;
13
14 import com.lutris.http.BasicAuth;
15 import com.lutris.http.BasicAuthResult;
16 import sessionViewer.spec.*;
17 /**
18  * Main application startup.
19  *
20  * Application-wide data would go here.
21  */

22 public class SessionViewer extends StandardApplication {
23     
24
25    // The user who is allowed to run this application. Used with basic auth.
26
//private String username, password, locale;
27
// For the password prompt. Used with basic auth.
28
private String JavaDoc relm = "SessionViewer";
29
30
31
32     public static String JavaDoc refresh = "0";
33     /*
34      * A few methods you might want to add to.
35      * See StandardApplication for more details.
36      */

37     public void startup(Config appConfig) throws ApplicationException {
38   
39       super.startup(appConfig);
40       try {
41         refresh = appConfig.getString("SessionViewer.Refresh");
42         Integer.parseInt(refresh);
43       } catch (Exception JavaDoc ex){
44         refresh = "0";
45       }
46      
47    }
48
49     public boolean requestPreprocessor(HttpPresentationComms comms)
50                    throws Exception JavaDoc {
51       super.requestPreprocessor(comms);
52       if (comms.session == null) {
53          // Session not setup; so its not a presentation object.
54
return false;
55       }
56
57       /*
58       * Ensure that the username/password are being sent.
59       * If both the username and password are empty strings, then
60       * do not require a login.
61       */

62    /* BasicAuthResult auth = BasicAuth.getAuthentication(comms.request);
63       if (((username.length() != 0) || (password.length() != 0)) &&
64             ((auth == null) ||
65             !username.equals(auth.username) ||
66             !password.equals(auth.password))) {
67          throw new PageUnauthorizedException(relm);
68        }
69        
70        if (comms.session.getUser() == null) {
71           comms.session.setUser(EnhydraManagerUser.sharedUser);
72        }
73     */

74     
75       String JavaDoc user = comms.request.getRemoteUser();
76      
77         if(user!=null)
78          {
79          if (comms.session.getUser() == null)
80           {
81             SessionViewerUser enhydraUser = new SessionViewerUser(user);
82             comms.session.setUser(enhydraUser);
83      
84           }
85          }
86          
87        // Proceed normally.
88
return false;
89    }
90    
91
92     /**
93      * This is an optional function, used only by the Multiserver's graphical
94      * administration. This bit of HTML appears in the status page for this
95      * application. You could add extra status info, for example
96      * a list of currently logged in users.
97      *
98      * @return HTML that is displayed in the status page of the Multiserver.
99      */

100     public String JavaDoc toHtml() {
101         return "This is <I>SessionViewer</I>";
102     }
103 }
104
105
Popular Tags