001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.web.servlets;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.core.CoreConstants;
038: import org.libresource.core.interfaces.LibresourceCoreService;
039:
040: import org.libresource.kernel.KernelConstants;
041: import org.libresource.kernel.interfaces.KernelService;
042:
043: import org.libresource.membership.MembershipConstants;
044: import org.libresource.membership.interfaces.MembershipService;
045:
046: import org.libresource.web.config.Config;
047:
048: import java.util.List;
049: import java.util.StringTokenizer;
050: import java.util.Vector;
051:
052: import javax.management.MBeanServer;
053: import javax.management.MBeanServerFactory;
054: import javax.management.ObjectName;
055:
056: import javax.servlet.http.HttpServletRequest;
057: import javax.servlet.http.HttpServletResponse;
058:
059: public class ServerInfos extends BaseServlet {
060: protected void process(HttpServletRequest request,
061: HttpServletResponse response) throws Exception {
062: KernelService kernelService = (KernelService) Libresource
063: .getService(KernelConstants.SERVICE);
064: LibresourceCoreService libresourceCoreService = (LibresourceCoreService) Libresource
065: .getService(CoreConstants.SERVICE);
066: MembershipService membershipService = (MembershipService) Libresource
067: .getService(MembershipConstants.SERVICE);
068:
069: // ls infos
070: request.setAttribute("lsVersion", kernelService
071: .getLibresourceVersion());
072:
073: // projects
074: request.setAttribute("nbProjects",
075: String
076: .valueOf(libresourceCoreService
077: .listAllProjects().length));
078: request.setAttribute("nbPublicProjects",
079: String.valueOf(libresourceCoreService
080: .listPublicProjects().length));
081:
082: // users
083: request.setAttribute("nbUsers", String
084: .valueOf(membershipService.listUsers().size()));
085:
086: // sessions
087: int connectedUsers = 0;
088: Vector users = new Vector();
089: int guestUsers = 0;
090: String managerName = "jonas:type=Manager,path=/,host=localhost";
091: ObjectName on = new ObjectName(managerName);
092: List mbeanServers = MBeanServerFactory.findMBeanServer(null);
093:
094: if ((mbeanServers != null) && (mbeanServers.size() > 0)) {
095: MBeanServer mbeanServer = (MBeanServer) mbeanServers.get(0);
096: String sessions = (String) mbeanServer.invoke(on,
097: "listSessionIds", null, null);
098: StringTokenizer st = new StringTokenizer(sessions, " ");
099:
100: while (st.hasMoreTokens()) {
101: String token = st.nextToken();
102: Object[] params = { token, "security_username" };
103: String[] sign = { "java.lang.String",
104: "java.lang.String" };
105:
106: try {
107: String user = (String) mbeanServer.invoke(on,
108: "getSessionAttribute", params, sign);
109:
110: if (user != null) {
111: if (!users.contains(user)) {
112: connectedUsers++;
113: users.add(user);
114: }
115: } else {
116: guestUsers++;
117: }
118: } catch (Exception e) {
119: // TODO: handle exception
120: }
121: }
122: }
123:
124: request.setAttribute("connectedUsers", new Integer(
125: connectedUsers));
126: request.setAttribute("connectedUsersList", users);
127: request.setAttribute("guestUsers", new Integer(guestUsers));
128:
129: // technicals infos
130: // application server (ejb is made in jsp code)
131: request.setAttribute("webServerInfos", Config.getInstance(null)
132: .getServletContext().getServerInfo());
133:
134: // os infos
135: Vector infos = new Vector();
136: Object[] property = new Object[2];
137: property[0] = "os.name";
138: property[1] = System.getProperty("os.name");
139: infos.add(property);
140: property = new Object[2];
141: property[0] = "os.version";
142: property[1] = System.getProperty("os.version");
143: infos.add(property);
144: request.setAttribute("osInfos", infos);
145:
146: // java infos
147: infos = new Vector();
148: property = new Object[2];
149: property[0] = "java.runtime.name";
150: property[1] = System.getProperty("java.runtime.name");
151: infos.add(property);
152: property = new Object[2];
153: property[0] = "java.vm.version";
154: property[1] = System.getProperty("java.vm.version");
155: infos.add(property);
156: property = new Object[2];
157: property[0] = "java.vm.vendor";
158: property[1] = "<a href=\""
159: + System.getProperty("java.vendor.url") + "\">"
160: + System.getProperty("java.vm.vendor") + "</a>";
161: infos.add(property);
162: property = new Object[2];
163: property[0] = "java.version";
164: property[1] = System.getProperty("java.version");
165: infos.add(property);
166: request.setAttribute("javaInfos", infos);
167:
168: request.getRequestDispatcher("/pages/serverInfos.jsp").forward(
169: request, response);
170: }
171: }
|