[jboss-cvs] JBossAS SVN: r97446 - in trunk/profileservice/src/main/java/org/jboss/profileservice: web and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 4 05:45:45 EST 2009


Author: emuckenhuber
Date: 2009-12-04 05:45:45 -0500 (Fri, 04 Dec 2009)
New Revision: 97446

Added:
   trunk/profileservice/src/main/java/org/jboss/profileservice/web/
   trunk/profileservice/src/main/java/org/jboss/profileservice/web/DebugServlet.java
Log:
[JBAS-7500] debug servlet.

Added: trunk/profileservice/src/main/java/org/jboss/profileservice/web/DebugServlet.java
===================================================================
--- trunk/profileservice/src/main/java/org/jboss/profileservice/web/DebugServlet.java	                        (rev 0)
+++ trunk/profileservice/src/main/java/org/jboss/profileservice/web/DebugServlet.java	2009-12-04 10:45:45 UTC (rev 97446)
@@ -0,0 +1,162 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.profileservice.web;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.Resource;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedDeployment;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class DebugServlet extends HttpServlet
+{
+   private static final long serialVersionUID = 1;
+   @Resource(mappedName="java:ManagementView")
+   private ManagementView mgtView;
+   enum Operations {
+      listDeploymentTree,
+      listOperations
+   };
+
+   
+   @Override
+   public void init(ServletConfig config) throws ServletException
+   {
+      super.init(config);
+      if(mgtView == null)
+      {
+         try
+         {
+            InitialContext ctx = new InitialContext();
+            mgtView = (ManagementView) ctx.lookup("java:ManagementView");
+         }
+         catch (NamingException e)
+         {
+            throw new ServletException("Failed to lookup ManagementView", e);
+         }
+      }
+   }
+
+   @Override
+   protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+         throws ServletException, IOException
+   {
+      if(mgtView == null)
+         throw new ServletException("The ManagementView has not been injected");
+      String op = req.getParameter("op");
+      if(op == null)
+         op = "listOperations";
+      Operations theOP = Enum.valueOf(Operations.class, "listDeploymentTree");
+      String opResult = "";
+      super.log("op="+op);
+      switch(theOP)
+      {
+         case listDeploymentTree:
+            opResult = listDeploymentTree();
+         break;
+         case listOperations:
+            opResult = listOperations();
+            break;
+         default:
+            throw new ServletException("Unknown op: "+op+", valid ops: "+Operations.values());
+      }
+      
+      PrintWriter pw = resp.getWriter();
+      pw.write("<h1>");
+      pw.write(theOP+" Results");
+      pw.write("</h1>");
+      pw.write("<pre>");
+      pw.write(opResult);
+      pw.write("</pre>");
+   }
+
+   protected String listDeploymentTree()
+      throws ServletException
+   {
+      StringBuilder tmp = new StringBuilder();
+      try
+      {
+         mgtView.load();
+         Set<String> names = mgtView.getDeploymentNames();
+         for(String name : names)
+         {
+            ManagedDeployment md = mgtView.getDeployment(name);
+            tmp.append("ManagedDeployment: ");
+            tmp.append(md.getName());
+            tmp.append('\n');
+            Map<String, ManagedComponent> mcs = md.getComponents();
+            if(mcs != null)
+            {
+               for(ManagedComponent mc : mcs.values())
+               {
+                  tmp.append("+++ ManagedComponent(name=");
+                  tmp.append(mc.getName());
+                  tmp.append(", type=(");
+                  tmp.append(mc.getType());
+                  tmp.append("), compName=");
+                  tmp.append(mc.getComponentName());
+                  tmp.append(", attachment: ");
+                  tmp.append(mc.getAttachmentName());
+                  tmp.append("\n++++++ properties: ");
+                  tmp.append(mc.getPropertyNames());
+                  tmp.append('\n');
+               }
+            }
+         }
+      }
+      catch(Exception e)
+      {
+         throw new ServletException("listDeploymentTree failure", e);
+      }
+      return tmp.toString();
+   }
+   protected String listOperations()
+   {
+      StringBuilder tmp = new StringBuilder();
+      tmp.append("Available operations: ");
+      tmp.append("<ul>");
+      for(Operations op : Operations.values())
+      {
+         tmp.append("<li>");
+         tmp.append(op.name());
+         tmp.append("</li>\n");
+      }
+      return tmp.toString();
+   }
+}




More information about the jboss-cvs-commits mailing list