1 17 package org.apache.servicemix.web.jmx; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 22 import javax.management.JMException ; 23 import javax.management.MBeanServer ; 24 import javax.management.ObjectName ; 25 import javax.management.QueryExp ; 26 import javax.servlet.ServletException ; 27 import javax.servlet.http.HttpServletRequest ; 28 import javax.servlet.http.HttpServletResponse ; 29 30 import java.io.IOException ; 31 import java.util.Set ; 32 33 39 public class JMXServlet extends JMXServletSupport { 40 41 private static final Log log = LogFactory.getLog(JMXServlet.class); 42 private static final long serialVersionUID = -5953322364144161756L; 43 44 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 45 try { 46 MBeanServer beanServer = getMBeanServer(); 47 ObjectName name = getObjectName(request); 48 QueryExp query = getQueryExp(request); 49 50 JMXWriter writer = new JMXWriter(response.getWriter(), getManagementContext()); 51 52 String style = request.getParameter("style"); 53 String view = request.getParameter("view"); 54 if (view == null) { 55 view = ""; 56 } 57 58 if (style != null && style.equals("html")) { 59 Set names = beanServer.queryNames(name, query); 60 61 if (log.isDebugEnabled()) { 62 log.debug("ObjectName: " + name); 63 log.debug("Query: " + query); 64 log.debug("Matches ObjectNames: " + names); 65 } 66 67 if (view.equals("properties")) { 68 writer.outputHtmlProperties(names); 69 } 70 else if (view.equals("attributes")) { 71 writer.outputHtmlAttributes(names); 72 } 73 else if (view.equals("flat")) { 74 writer.outputHtmlNames(names); 75 } 76 else { 77 writer.outputHtmlNamesByDomain(names); 78 } 79 } 80 else { 81 writer.outputHeader(); 82 if (view.equals("bean")) { 83 Set mbeans = beanServer.queryMBeans(name, query); 84 writer.outputMBeans(mbeans); 85 } 86 else if (view.equals("detail")) { 87 Set names = beanServer.queryNames(name, query); 88 writer.outputDetail(names); 89 } 90 else { 91 Set names = beanServer.queryNames(name, query); 92 writer.outputNames(names); 93 } 94 writer.outputFooter(); 95 } 96 } 97 catch (JMException e) { 98 throw new ServletException (e); 99 } 100 } 101 } 102 | Popular Tags |