tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject cvs commit: jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin DumpRegistryAction.java ApplicationServlet.java
Date Sat, 27 Oct 2001 22:18:50 GMT
craigmcc    01/10/27 15:18:50

  Modified:    webapps/admin build.xml
               webapps/admin/WEB-INF struts-config.xml
               webapps/admin/WEB-INF/classes/org/apache/webapp/admin
                        ApplicationServlet.java
  Added:       webapps/admin dumpRegistry.jsp
               webapps/admin/WEB-INF/classes/org/apache/webapp/admin
                        DumpRegistryAction.java
  Log:
  Add a simple debugging action that will dump out the contents of the
  Registry passed by Catalina.
  
  FIXME:  Do something similar to dump out the MBeanServer's contents.
  
  Revision  Changes    Path
  1.2       +8 -0      jakarta-tomcat-4.0/webapps/admin/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/build.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- build.xml	2001/10/25 16:36:06	1.1
  +++ build.xml	2001/10/27 22:18:49	1.2
  @@ -18,6 +18,7 @@
   
     <!-- Construct Admin classpath -->
     <path id="admin.classpath">
  +    <pathelement location="${commons-modeler.jar}"/>
       <pathelement location="${jmxri.jar}"/>
       <pathelement location="${servlet.jar}"/>
       <pathelement location="${struts.jar}"/>
  @@ -49,6 +50,9 @@
       <available property="jmx.present"
        classname="javax.management.MBeanServer"
        classpath="${jmxri.jar}" />
  +    <available property="modeler.present"
  +     classname="org.apache.commons.modeler.Registry"
  +     classpath="${commons-modeler.jar}"/>
       <available property="servlet.present"
        classname="javax.servlet.Servlet"
        classpath="${servlet.jar}" />
  @@ -58,6 +62,7 @@
   
       <!-- JAR files availability flags -->
       <available property="jmxri.jar.present"   file="${jmxri.jar}" />
  +    <available property="modeler.jar.present" file="${commons-modeler.jar}" />
       <available property="servlet.jar.present" file="${servlet.jar}" />
       <available property="struts.jar.present"  file="${struts.jar}" />
   
  @@ -68,6 +73,7 @@
           <and>
             <equals arg1="${struts.present}" arg2="true" />
             <equals arg1="${jmx.present}" arg2="true" />
  +          <equals arg1="${modeler.present}" arg2="true" />
             <available file="${struts.lib}/struts-bean.tld" />
             <available file="${struts.lib}/struts-html.tld" />
             <available file="${struts.lib}/struts-logic.tld" />
  @@ -111,10 +117,12 @@
       <echo message="--- Required Libraries ---" />
       <echo message="jaxp.present=${jaxp.present}" />
       <echo message="jmx.present=${jmx.present}" />
  +    <echo message="modeler.present=${modeler.present}" />
       <echo message="servlet.present=${servlet.present}" />
   
       <echo message="--- Required JARs ---" />
       <echo message="jmxri.jar.present=${jmxri.jar.present}" />
  +    <echo message="modeler.jar.present=${modeler.jar.present}" />
       <echo message="servlet.jar.present=${servlet.jar.present}" />
       <echo message="struts.jar.present=${struts.jar.present}" />
   
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/admin/dumpRegistry.jsp
  
  Index: dumpRegistry.jsp
  ===================================================================
  <!-- Standard Struts Entries -->
  
  <%@ page language="java" %>
  <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
  <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
  <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
  
  <html:html locale="true">
  
  <!-- Standard Content -->
  
  <%@ include file="header.jsp" %>
  
  <!-- Body -->
  
  <table border="1" cellpadding="5">
  
    <tr>
      <th align="center" colspan="3">
        Registered Managed Beans
      </th>
    </tr>
  
    <tr>
      <th align="center">Name</th>
      <th align="center">Group</th>
      <th align="center">Description</th>
    </tr>
  
    <logic:iterate id="bean" name="beans">
      <tr>
        <td><bean:write name="bean" property="name"/></td>
        <td><bean:write name="bean" property="group"/></td>
        <td><bean:write name="bean" property="description"/></td>
      </tr>
    </logic:iterate>
  
  </table>
  
  <!-- Standard Footer -->
  
  <%@ include file="footer.jsp" %>
  
  </body>
  
  </html:html>
  
  
  
  1.2       +8 -0      jakarta-tomcat-4.0/webapps/admin/WEB-INF/struts-config.xml
  
  Index: struts-config.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/struts-config.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- struts-config.xml	2001/10/25 16:36:06	1.1
  +++ struts-config.xml	2001/10/27 22:18:50	1.2
  @@ -30,6 +30,10 @@
   
     <global-forwards>
   
  +    <forward        name="Dump Registry Results"
  +                    path="/dumpRegistry.jsp"
  +                redirect="false"/>
  +
       <forward        name="Main Menu"
                       path="/index.jsp"
                   redirect="false"/>
  @@ -40,6 +44,10 @@
     <!-- ========== Action Mapping Definitions ============================== -->
   
     <action-mappings>
  +
  +    <!-- Dump registry information (debugging) -->
  +    <action    path="/dumpRegistry"
  +               type="org.apache.webapp.admin.DumpRegistryAction"/>
   
       <!-- Log out of the application -->
       <action    path="/logOut"
  
  
  
  1.2       +104 -6    jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationServlet.java
  
  Index: ApplicationServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationServlet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ApplicationServlet.java	2001/10/25 16:37:38	1.1
  +++ ApplicationServlet.java	2001/10/27 22:18:50	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationServlet.java,v
1.1 2001/10/25 16:37:38 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/10/25 16:37:38 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationServlet.java,v
1.2 2001/10/27 22:18:50 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/10/27 22:18:50 $
    *
    * ====================================================================
    *
  @@ -62,12 +62,14 @@
   
   package org.apache.webapp.admin;
   
  -
   import java.text.DateFormat;
   import java.util.HashSet;
   import java.util.Locale;
   import java.util.ResourceBundle;
  +import javax.management.MBeanServer;
   import javax.servlet.ServletException;
  +import javax.servlet.UnavailableException;
  +import org.apache.commons.modeler.Registry;
   import org.apache.struts.action.ActionServlet;
   import org.apache.struts.util.MessageResources;
   
  @@ -77,7 +79,7 @@
    * ApplicationLocales class.
    *
    * @author Patrick Luby
  - * @version $Revision: 1.1 $ $Date: 2001/10/25 16:37:38 $
  + * @version $Revision: 1.2 $ $Date: 2001/10/27 22:18:50 $
    */
   
   public class ApplicationServlet extends ActionServlet {
  @@ -93,19 +95,115 @@
       public static final String LOCALES_KEY = "applicationLocales";
   
   
  +    // ----------------------------------------------------- Instance Variables
  +
  +
  +    /**
  +     * The managed beans Registry used to look up metadata.
  +     */
  +    protected Registry registry = null;
  +
  +
  +    /**
  +     * The JMX MBeanServer we will use to look up management beans.
  +     */
  +    protected MBeanServer server = null;
  +
  +
       // --------------------------------------------------------- Public Methods
   
  +
  +    /**
  +     * Convenience method to make the managed beans Registry available.
  +     *
  +     * @exception ServletException if the Registry is not available
  +     */
  +    public Registry getRegistry() throws ServletException {
  +
  +        if (registry == null)
  +            initRegistry();
  +        return (this.registry);
  +
  +    }
  +
  +
  +    /**
  +     * Convenience method to make the JMX MBeanServer available.
  +     *
  +     * @exception ServletException if the MBeanServer is not available
  +     */
  +    public MBeanServer getServer() throws ServletException {
  +
  +        if (server == null)
  +            initServer();
  +        return (this.server);
  +
  +    }
  +
  +
       /**
        * Initialize this servlet.
  +     *
  +     * @exception ServletException if an initialization error occurs.
        */
       public void init() throws javax.servlet.ServletException {
   
           // Perform normal superclass initialization
           super.init();
  +
  +        // Perform initialization specific to this application
  +        initApplicationLocales();
  +
  +    }
  +
  +
  +    // ---------------------------------------------------- Protected Methods
   
  -        // Create an ApplicationLocales object 
  +
  +    /**
  +     * Create and initialize the ApplicationLocales object, and make it
  +     * available as a servlet context attribute.
  +     */
  +    protected void initApplicationLocales() {
  +
           ApplicationLocales locales = new ApplicationLocales(this);
           getServletContext().setAttribute(LOCALES_KEY, locales);
  +
  +    }
  +
  +
  +    /**
  +     * Validate the existence of the Registry that should have been
  +     * provided to us by an instance of
  +     * <code>org.apache.catalina.mbean.ServerLifecycleListener</code>
  +     * enabled at startup time.
  +     *
  +     * @exception ServletException if we cannot find the Registry
  +     */
  +    protected void initRegistry() throws ServletException {
  +
  +        registry = (Registry) getServletContext().getAttribute
  +            ("org.apache.catalina.Registry");
  +        if (registry == null)
  +            throw new UnavailableException("Registry is not available");
  +
  +    }
  +
  +
  +    /**
  +     * Validate the existence of the MBeanServer that should have been
  +     * provided to us by an instance of
  +     * <code>org.apache.catalina.mbean.ServerLifecycleListener</code>
  +     * enabled at startup time.
  +     *
  +     * @exception ServletException if we cannot find the MBeanServer
  +     */
  +    protected void initServer() throws ServletException {
  +
  +        server = (MBeanServer) getServletContext().getAttribute
  +            ("org.apache.catalina.MBeanServer");
  +        if (server == null)
  +            throw new UnavailableException("MBeanServer is not available");
   
       }
   
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/DumpRegistryAction.java
  
  Index: DumpRegistryAction.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/DumpRegistryAction.java,v
1.1 2001/10/27 22:18:50 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2001/10/27 22:18:50 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Struts", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  package org.apache.webapp.admin;
  
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.Arrays;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  import org.apache.commons.modeler.ManagedBean;
  import org.apache.commons.modeler.Registry;
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionErrors;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionForward;
  import org.apache.struts.action.ActionMapping;
  
  
  /**
   * Simple debugging action that dumps a list of the managed beans that are
   * visible in our Registry.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2001/10/27 22:18:50 $
   */
  
  public final class DumpRegistryAction extends Action {
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Process the specified HTTP request, and create the corresponding HTTP
       * response (or forward to another web component that will create it).
       * Return an <code>ActionForward</code> instance describing where and how
       * control should be forwarded, or <code>null</code> if the response has
       * already been completed.
       *
       * @param mapping The ActionMapping used to select this instance
       * @param actionForm The optional ActionForm bean for this request (if any)
       * @param request The HTTP request we are processing
       * @param response The HTTP response we are creating
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet exception occurs
       */
      public ActionForward perform(ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response)
          throws IOException, ServletException {
  
          // Create a request attribute with our collection of beans
          Registry registry = ((ApplicationServlet) getServlet()).getRegistry();
          String names[] = registry.findManagedBeans();
          Arrays.sort(names);
          ManagedBean beans[] = new ManagedBean[names.length];
          for (int i = 0; i < names.length; i++)
              beans[i] = registry.findManagedBean(names[i]);
          request.setAttribute("beans", beans);
  
          // Forward to the corresponding display page
          return (mapping.findForward("Dump Registry Results"));
  
      }
  
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message