1 17 18 package org.apache.geronimo.jmxdebug.web.velocity; 19 20 import java.io.IOException ; 21 import java.net.URLDecoder ; 22 import java.net.URLEncoder ; 23 import javax.servlet.ServletException ; 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 27 import org.apache.geronimo.jmxdebug.web.beanlib.GBeanInfoHelper; 28 import org.apache.geronimo.jmxdebug.web.beanlib.KernelHelper; 29 import org.apache.velocity.VelocityContext; 30 31 36 public class DebugServlet extends BasicVelocityActionServlet { 37 public static String OBJECT_NAME_FILTER_KEY = "ObjectNameFilter"; 38 39 protected String getActionVerb() { 40 return "action"; 41 } 42 43 48 public void defaultAction(HttpServletRequest req, HttpServletResponse res) 49 throws ServletException , IOException { 50 51 String beanName = req.getParameter("MBeanName"); 52 String filterKey = req.getParameter(OBJECT_NAME_FILTER_KEY); 53 54 if (filterKey == null || "".equals(filterKey)) { 55 filterKey = "*:*"; 56 } 57 58 VelocityContext vc = new VelocityContext(); 59 60 KernelHelper kernelHelper = new KernelHelper(); 61 vc.put("mbctx", kernelHelper); 62 vc.put("encoder", new KickSunInHead()); 63 vc.put(OBJECT_NAME_FILTER_KEY, filterKey); 64 65 if (beanName == null) { 66 vc.put("template", "nobean.vm"); 67 } else { 68 try { 69 vc.put("beanInfo", new GBeanInfoHelper(kernelHelper, beanName)); 70 } catch (Exception e) { 71 e.printStackTrace(); 72 } 73 vc.put("template", "mbeaninfo.vm"); 74 } 75 76 renderTemplate(req, res, vc, "index.vm"); 77 } 78 79 public void unknownAction(HttpServletRequest req, HttpServletResponse res) 80 throws ServletException , IOException { 81 defaultAction(req, res); 82 } 83 84 85 88 public class KickSunInHead { 89 public String decode(String string) { 90 return decode(string, "UTF-8"); 91 } 92 93 public String decode(String string, String encoding) { 94 if (string != null) { 95 try { 96 return URLDecoder.decode(string, encoding); 97 } catch (Exception e) { 98 e.printStackTrace(); 99 } 100 } 101 return null; 102 } 103 104 public String encode(String string) { 105 return encode(string, "UTF-8"); 106 } 107 108 public String encode(String string, String encoding) { 109 if (string != null) { 110 try { 111 return URLEncoder.encode(string, encoding); 112 } catch (Exception e) { 113 e.printStackTrace(); 114 } 115 } 116 117 return null; 118 } 119 120 } 121 } 122 | Popular Tags |