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