1 17 18 19 package org.apache.catalina.manager; 20 21 22 import java.io.IOException ; 23 import java.io.PrintWriter ; 24 import java.util.Enumeration ; 25 import java.util.Iterator ; 26 import java.util.Set ; 27 import java.util.Vector ; 28 29 import javax.management.MBeanServer ; 30 import javax.management.MBeanServerNotification ; 31 import javax.management.Notification ; 32 import javax.management.NotificationListener ; 33 import javax.management.ObjectInstance ; 34 import javax.management.ObjectName ; 35 import javax.servlet.ServletException ; 36 import javax.servlet.http.HttpServlet ; 37 import javax.servlet.http.HttpServletRequest ; 38 import javax.servlet.http.HttpServletResponse ; 39 40 import org.apache.catalina.util.ServerInfo; 41 import org.apache.catalina.util.StringManager; 42 import org.apache.tomcat.util.modeler.Registry; 43 44 50 51 public class StatusManagerServlet 52 extends HttpServlet implements NotificationListener { 53 54 55 57 58 61 private int debug = 0; 62 63 64 67 protected MBeanServer mBeanServer = null; 68 69 70 73 protected Vector protocolHandlers = new Vector (); 74 75 76 79 protected Vector threadPools = new Vector (); 80 81 82 85 protected Vector requestProcessors = new Vector (); 86 87 88 91 protected Vector globalRequestProcessors = new Vector (); 92 93 94 97 protected static StringManager sm = 98 StringManager.getManager(Constants.Package); 99 100 101 103 104 107 public void init() throws ServletException { 108 109 mBeanServer = Registry.getRegistry(null, null).getMBeanServer(); 111 112 String value = null; 114 try { 115 value = getServletConfig().getInitParameter("debug"); 116 debug = Integer.parseInt(value); 117 } catch (Throwable t) { 118 ; 119 } 120 121 try { 122 123 String onStr = "*:type=ProtocolHandler,*"; 125 ObjectName objectName = new ObjectName (onStr); 126 Set set = mBeanServer.queryMBeans(objectName, null); 127 Iterator iterator = set.iterator(); 128 while (iterator.hasNext()) { 129 ObjectInstance oi = (ObjectInstance ) iterator.next(); 130 protocolHandlers.addElement(oi.getObjectName()); 131 } 132 133 onStr = "*:type=ThreadPool,*"; 135 objectName = new ObjectName (onStr); 136 set = mBeanServer.queryMBeans(objectName, null); 137 iterator = set.iterator(); 138 while (iterator.hasNext()) { 139 ObjectInstance oi = (ObjectInstance ) iterator.next(); 140 threadPools.addElement(oi.getObjectName()); 141 } 142 143 onStr = "*:type=GlobalRequestProcessor,*"; 145 objectName = new ObjectName (onStr); 146 set = mBeanServer.queryMBeans(objectName, null); 147 iterator = set.iterator(); 148 while (iterator.hasNext()) { 149 ObjectInstance oi = (ObjectInstance ) iterator.next(); 150 globalRequestProcessors.addElement(oi.getObjectName()); 151 } 152 153 onStr = "*:type=RequestProcessor,*"; 155 objectName = new ObjectName (onStr); 156 set = mBeanServer.queryMBeans(objectName, null); 157 iterator = set.iterator(); 158 while (iterator.hasNext()) { 159 ObjectInstance oi = (ObjectInstance ) iterator.next(); 160 requestProcessors.addElement(oi.getObjectName()); 161 } 162 163 onStr = "JMImplementation:type=MBeanServerDelegate"; 165 objectName = new ObjectName (onStr); 166 mBeanServer.addNotificationListener(objectName, this, null, null); 167 168 } catch (Exception e) { 169 e.printStackTrace(); 170 } 171 172 } 173 174 175 178 public void destroy() { 179 180 ; 182 } 183 184 185 194 public void doGet(HttpServletRequest request, 195 HttpServletResponse response) 196 throws IOException , ServletException { 197 198 int mode = 0; 200 if (request.getParameter("XML") != null 202 && request.getParameter("XML").equals("true")) { 203 mode = 1; 204 } 205 StatusTransformer.setContentType(response, mode); 206 207 PrintWriter writer = response.getWriter(); 208 209 boolean completeStatus = false; 210 if ((request.getPathInfo() != null) 211 && (request.getPathInfo().equals("/all"))) { 212 completeStatus = true; 213 } 214 StatusTransformer.writeHeader(writer,mode); 216 217 Object [] args = new Object [2]; 219 args[0] = request.getContextPath(); 220 if (completeStatus) { 221 args[1] = sm.getString("statusServlet.complete"); 222 } else { 223 args[1] = sm.getString("statusServlet.title"); 224 } 225 StatusTransformer.writeBody(writer,args,mode); 227 228 args = new Object [9]; 230 args[0] = sm.getString("htmlManagerServlet.manager"); 231 args[1] = response.encodeURL(request.getContextPath() + "/html/list"); 232 args[2] = sm.getString("htmlManagerServlet.list"); 233 args[3] = response.encodeURL 234 (request.getContextPath() + "/" + 235 sm.getString("htmlManagerServlet.helpHtmlManagerFile")); 236 args[4] = sm.getString("htmlManagerServlet.helpHtmlManager"); 237 args[5] = response.encodeURL 238 (request.getContextPath() + "/" + 239 sm.getString("htmlManagerServlet.helpManagerFile")); 240 args[6] = sm.getString("htmlManagerServlet.helpManager"); 241 if (completeStatus) { 242 args[7] = response.encodeURL 243 (request.getContextPath() + "/status"); 244 args[8] = sm.getString("statusServlet.title"); 245 } else { 246 args[7] = response.encodeURL 247 (request.getContextPath() + "/status/all"); 248 args[8] = sm.getString("statusServlet.complete"); 249 } 250 StatusTransformer.writeManager(writer,args,mode); 252 253 args = new Object [7]; 255 args[0] = sm.getString("htmlManagerServlet.serverTitle"); 256 args[1] = sm.getString("htmlManagerServlet.serverVersion"); 257 args[2] = sm.getString("htmlManagerServlet.serverJVMVersion"); 258 args[3] = sm.getString("htmlManagerServlet.serverJVMVendor"); 259 args[4] = sm.getString("htmlManagerServlet.serverOSName"); 260 args[5] = sm.getString("htmlManagerServlet.serverOSVersion"); 261 args[6] = sm.getString("htmlManagerServlet.serverOSArch"); 262 StatusTransformer.writePageHeading(writer,args,mode); 264 265 args = new Object [6]; 267 args[0] = ServerInfo.getServerInfo(); 268 args[1] = System.getProperty("java.runtime.version"); 269 args[2] = System.getProperty("java.vm.vendor"); 270 args[3] = System.getProperty("os.name"); 271 args[4] = System.getProperty("os.version"); 272 args[5] = System.getProperty("os.arch"); 273 StatusTransformer.writeServerInfo(writer, args, mode); 275 276 try { 277 278 StatusTransformer.writeOSState(writer,mode); 280 281 StatusTransformer.writeVMState(writer,mode); 283 284 Enumeration enumeration = threadPools.elements(); 285 while (enumeration.hasMoreElements()) { 286 ObjectName objectName = (ObjectName ) enumeration.nextElement(); 287 String name = objectName.getKeyProperty("name"); 288 StatusTransformer.writeConnectorState 290 (writer, objectName, 291 name, mBeanServer, globalRequestProcessors, 292 requestProcessors, mode); 293 } 294 295 if ((request.getPathInfo() != null) 296 && (request.getPathInfo().equals("/all"))) { 297 StatusTransformer.writeDetailedState 300 (writer, mBeanServer, mode); 301 } 302 303 } catch (Exception e) { 304 throw new ServletException (e); 305 } 306 307 StatusTransformer.writeFooter(writer, mode); 309 310 } 311 312 314 315 public void handleNotification(Notification notification, 316 java.lang.Object handback) { 317 318 if (notification instanceof MBeanServerNotification ) { 319 ObjectName objectName = 320 ((MBeanServerNotification ) notification).getMBeanName(); 321 if (notification.getType().equals 322 (MBeanServerNotification.REGISTRATION_NOTIFICATION)) { 323 String type = objectName.getKeyProperty("type"); 324 if (type != null) { 325 if (type.equals("ProtocolHandler")) { 326 protocolHandlers.addElement(objectName); 327 } else if (type.equals("ThreadPool")) { 328 threadPools.addElement(objectName); 329 } else if (type.equals("GlobalRequestProcessor")) { 330 globalRequestProcessors.addElement(objectName); 331 } else if (type.equals("RequestProcessor")) { 332 requestProcessors.addElement(objectName); 333 } 334 } 335 } else if (notification.getType().equals 336 (MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) { 337 String type = objectName.getKeyProperty("type"); 338 if (type != null) { 339 if (type.equals("ProtocolHandler")) { 340 protocolHandlers.removeElement(objectName); 341 } else if (type.equals("ThreadPool")) { 342 threadPools.removeElement(objectName); 343 } else if (type.equals("GlobalRequestProcessor")) { 344 globalRequestProcessors.removeElement(objectName); 345 } else if (type.equals("RequestProcessor")) { 346 requestProcessors.removeElement(objectName); 347 } 348 } 349 String j2eeType = objectName.getKeyProperty("j2eeType"); 350 if (j2eeType != null) { 351 352 } 353 } 354 } 355 356 } 357 358 359 } 360 | Popular Tags |