1 7 package org.jboss.web.tomcat.tc5; 8 9 10 import java.io.IOException ; 11 import java.io.PrintWriter ; 12 import java.util.Enumeration ; 13 import java.util.Iterator ; 14 import java.util.Set ; 15 import java.util.Vector ; 16 17 import javax.management.MBeanServer ; 18 import javax.management.MBeanServerNotification ; 19 import javax.management.Notification ; 20 import javax.management.NotificationListener ; 21 import javax.management.ObjectInstance ; 22 import javax.management.ObjectName ; 23 24 import javax.servlet.ServletException ; 25 import javax.servlet.http.HttpServlet ; 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 29 import org.apache.commons.modeler.Registry; 30 31 import org.apache.catalina.util.ServerInfo; 32 import org.apache.catalina.util.StringManager; 33 import org.apache.catalina.manager.Constants; 34 import org.apache.catalina.manager.StatusTransformer; 35 36 42 43 public class StatusServlet 44 extends HttpServlet implements NotificationListener 45 { 46 47 48 50 51 54 private int debug = 0; 55 56 57 60 protected MBeanServer mBeanServer = null; 61 62 63 66 protected Vector protocolHandlers = new Vector (); 67 68 69 72 protected Vector threadPools = new Vector (); 73 74 75 78 protected Vector requestProcessors = new Vector (); 79 80 81 84 protected Vector globalRequestProcessors = new Vector (); 85 86 87 90 protected static StringManager sm = 91 StringManager.getManager(Constants.Package); 92 93 94 96 97 100 public void init() throws ServletException 101 { 102 103 mBeanServer = Registry.getServer(); 105 106 String value = null; 108 try 109 { 110 value = getServletConfig().getInitParameter("debug"); 111 debug = Integer.parseInt(value); 112 } 113 catch (Throwable t) 114 { 115 ; 116 } 117 118 try 119 { 120 121 String onStr = "*:type=ProtocolHandler,*"; 123 ObjectName objectName = new ObjectName (onStr); 124 Set set = mBeanServer.queryMBeans(objectName, null); 125 Iterator iterator = set.iterator(); 126 while (iterator.hasNext()) 127 { 128 ObjectInstance oi = (ObjectInstance ) iterator.next(); 129 protocolHandlers.addElement(oi.getObjectName()); 130 } 131 132 onStr = "*:type=ThreadPool,*"; 134 objectName = new ObjectName (onStr); 135 set = mBeanServer.queryMBeans(objectName, null); 136 iterator = set.iterator(); 137 while (iterator.hasNext()) 138 { 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 { 150 ObjectInstance oi = (ObjectInstance ) iterator.next(); 151 globalRequestProcessors.addElement(oi.getObjectName()); 152 } 153 154 onStr = "*:type=RequestProcessor,*"; 156 objectName = new ObjectName (onStr); 157 set = mBeanServer.queryMBeans(objectName, null); 158 iterator = set.iterator(); 159 while (iterator.hasNext()) 160 { 161 ObjectInstance oi = (ObjectInstance ) iterator.next(); 162 requestProcessors.addElement(oi.getObjectName()); 163 } 164 165 onStr = "JMImplementation:type=MBeanServerDelegate"; 167 objectName = new ObjectName (onStr); 168 mBeanServer.addNotificationListener(objectName, this, null, null); 169 170 } 171 catch (Exception e) 172 { 173 e.printStackTrace(); 174 } 175 176 } 177 178 179 182 public void destroy() 183 { 184 185 ; 187 } 188 189 190 198 public void doGet(HttpServletRequest request, 199 HttpServletResponse response) 200 throws IOException , ServletException 201 { 202 203 int mode = 0; 205 if ("true".equals(request.getParameter("XML"))) 207 { 208 mode = 1; 209 } 210 StatusTransformer.setContentType(response, mode); 211 212 PrintWriter writer = response.getWriter(); 213 214 boolean completeStatus = false; 215 if ("true".equals(request.getParameter("full"))) 216 { 217 completeStatus = true; 218 } 219 220 if (mode == 0) 222 { 223 writer.print(HTML_HEADER); 225 } 226 else if (mode == 1) 227 { 228 writer.write(Constants.XML_DECLARATION); 229 writer.write 230 (Constants.XML_STYLE); 231 writer.write("<status>"); 232 } 233 234 try 235 { 236 237 StatusTransformer.writeVMState(writer, mode); 239 240 Enumeration i = threadPools.elements(); 241 while (i.hasMoreElements()) 242 { 243 ObjectName objectName = (ObjectName ) i.nextElement(); 244 String name = objectName.getKeyProperty("name"); 245 StatusTransformer.writeConnectorState 247 (writer, objectName, 248 name, mBeanServer, globalRequestProcessors, 249 requestProcessors, mode); 250 } 251 252 if (completeStatus) 253 { 254 StatusTransformer.writeDetailedState 257 (writer, mBeanServer, mode); 258 } 259 260 } 261 catch (Exception e) 262 { 263 throw new ServletException (e); 264 } 265 266 if (mode == 0) 267 { 268 writer.print(HTML_FOOTER); 269 } 270 else if (mode == 1) 271 { 272 writer.write("</status>"); 273 } 274 275 } 276 277 279 280 public void handleNotification(Notification notification, 281 java.lang.Object handback) 282 { 283 284 if (notification instanceof MBeanServerNotification ) 285 { 286 ObjectName objectName = 287 ((MBeanServerNotification ) notification).getMBeanName(); 288 if (notification.getType().equals 289 (MBeanServerNotification.REGISTRATION_NOTIFICATION)) 290 { 291 String type = objectName.getKeyProperty("type"); 292 if (type != null) 293 { 294 if (type.equals("ProtocolHandler")) 295 { 296 protocolHandlers.addElement(objectName); 297 } 298 else if (type.equals("ThreadPool")) 299 { 300 threadPools.addElement(objectName); 301 } 302 else if (type.equals("GlobalRequestProcessor")) 303 { 304 globalRequestProcessors.addElement(objectName); 305 } 306 else if (type.equals("RequestProcessor")) 307 { 308 requestProcessors.addElement(objectName); 309 } 310 } 311 } 312 else if (notification.getType().equals 313 (MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) 314 { 315 String type = objectName.getKeyProperty("type"); 316 if (type != null) 317 { 318 if (type.equals("ProtocolHandler")) 319 { 320 protocolHandlers.removeElement(objectName); 321 } 322 else if (type.equals("ThreadPool")) 323 { 324 threadPools.removeElement(objectName); 325 } 326 else if (type.equals("GlobalRequestProcessor")) 327 { 328 globalRequestProcessors.removeElement(objectName); 329 } 330 else if (type.equals("RequestProcessor")) 331 { 332 requestProcessors.removeElement(objectName); 333 } 334 } 335 String j2eeType = objectName.getKeyProperty("j2eeType"); 336 if (j2eeType != null) 337 { 338 339 } 340 } 341 } 342 343 } 344 345 346 348 349 private static final String HTML_HEADER = 350 "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" 351 + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" 352 + "<html xmlns=\"http://www.w3.org/1999/xhtml\">" 353 + "<head>" 354 + "<title>Tomcat Status</title>" 355 + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />" 356 + "<link rel=\"StyleSheet\" HREF=\"jboss.css\" type=\"text/css\"/>" 357 + "</head>" 358 + "<body>" 359 + "<!-- header begin -->" 360 + "<a HREF=\"http://www.jboss.org\">" 361 + "<img SRC=\"logo.gif\" alt=\"JBoss\" id=\"logo\" width=\"226\" height=\"105\" />" 362 + "</a>" 363 + "<div id=\"header\"> </div>" 364 + "<div id=\"navigation_bar\">" 365 + "</div>" 366 + "<!-- header end -->"; 367 368 private static final String HTML_FOOTER = 369 "<!-- footer begin -->" 370 + "<div id=\"footer\">" 371 + "<div id=\"credits\">JBoss™ Application Server</div>" 372 + "<div id=\"footer_bar\"> </div>" 373 + "</div>" 374 + "<!-- footer end -->" 375 + "</body>" 376 + "</html>"; 377 378 379 } 380 | Popular Tags |