1 17 package org.apache.servicemix.web.jmx; 18 19 import javax.management.MBeanServer ; 20 import javax.management.MalformedObjectNameException ; 21 import javax.management.ObjectName ; 22 import javax.management.QueryExp ; 23 import javax.servlet.ServletException ; 24 import javax.servlet.http.HttpServlet ; 25 import javax.servlet.http.HttpServletRequest ; 26 27 34 public abstract class JMXServletSupport extends HttpServlet { 35 36 protected static final String MANAGEMENT_CONTEXT_PROPERTY = "org.activemq.jmx.ManagementContext"; 37 38 private ManagementContext managementContext; 39 40 public void init() throws ServletException { 41 if (managementContext == null) { 42 managementContext = (ManagementContext) getServletContext().getAttribute(MANAGEMENT_CONTEXT_PROPERTY); 43 if (managementContext == null) { 44 managementContext = new ManagementContext(); 45 } 46 } 47 } 48 49 public MBeanServer getMBeanServer() { 50 return managementContext.getMBeanServer(); 51 } 52 53 public ManagementContext getManagementContext() { 54 return managementContext; 55 } 56 57 public void setManagementContext(ManagementContext managementContext) { 58 this.managementContext = managementContext; 59 } 60 61 protected QueryExp getQueryExp(HttpServletRequest request) throws ServletException { 62 QueryExp answer = null; 63 String value = request.getParameter("query"); 64 if (value != null) { 65 try { 66 answer = new ObjectName (value); 67 } 68 catch (MalformedObjectNameException e) { 69 throw new ServletException (e); 70 } 71 } 72 return answer; 73 } 74 75 protected ObjectName getObjectName(HttpServletRequest request) throws ServletException { 76 String value = request.getParameter("name"); 77 ObjectName answer = null; 78 if (value != null) { 79 try { 80 answer = new ObjectName (value); 81 } 82 catch (MalformedObjectNameException e) { 83 throw new ServletException ("Failed to parse object name: " + value + ". Reason: " + e, e); 84 } 85 } 86 return answer; 87 } 88 89 92 protected boolean asBoolean(HttpServletRequest request, String name) { 93 String param = request.getParameter(name); 94 return param != null && param.equalsIgnoreCase("true"); 95 } 96 } 97 | Popular Tags |