manveen     02/02/13 13:37:45

  Modified:    webapps/admin/WEB-INF struts-config.xml
               webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service
                        SetUpDeleteServiceAction.java
  Added:       webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host
                        HostAction.java HostForm.java SetUpHostAction.java
               webapps/admin/WEB-INF/classes/org/apache/webapp/admin/logger
                        LoggerAction.java LoggerForm.java
                        SetUpLoggerAction.java
  Removed:     webapps/admin/WEB-INF/classes/org/apache/webapp/admin
                        HostAction.java HostForm.java LoggerAction.java
                        LoggerForm.java SetUpHostAction.java
                        SetUpLoggerAction.java
  Log:
  * Throw (and log) meangingful exceptions/error messages if there is an exception in 
setting or getting attributes from mBeans, or invoking operations on mBeans.
  
  * Moved logger and host files to their own packages.
  
  Revision  Changes    Path
  1.30      +6 -9      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.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- struts-config.xml 13 Feb 2002 00:13:11 -0000      1.29
  +++ struts-config.xml 13 Feb 2002 21:37:44 -0000      1.30
  @@ -37,7 +37,7 @@
   
       <!-- Host form bean -->
       <form-bean      name="hostForm"
  -                    type="org.apache.webapp.admin.HostForm"/>
  +                    type="org.apache.webapp.admin.host.HostForm"/>
   
       <!-- Context form bean -->
       <form-bean      name="contextForm"
  @@ -45,7 +45,7 @@
                       
       <!-- Logger form bean -->
       <form-bean      name="loggerForm"
  -                    type="org.apache.webapp.admin.LoggerForm"/>
  +                    type="org.apache.webapp.admin.logger.LoggerForm"/>
   
       <!-- Set Locale form bean -->
       <form-bean      name="setLocaleForm"
  @@ -259,9 +259,6 @@
                  type="org.apache.webapp.admin.SetUpServerAction"
                  name="serverForm"
                  scope="session">
  -      <forward        name="SetUpServer"
  -                      path="/server.jsp"
  -                  redirect="true"/>
       </action>
   
      <!-- Set up Service datastructure -->
  @@ -294,7 +291,7 @@
   
        <!-- Set up Host datastructure -->
       <action    path="/setUpHost"
  -               type="org.apache.webapp.admin.SetUpHostAction"
  +               type="org.apache.webapp.admin.host.SetUpHostAction"
                  name="hostForm"
                  scope="session">
       </action>
  @@ -308,7 +305,7 @@
       
       <!-- Set up Logger datastructure -->
       <action    path="/setUpLogger"
  -               type="org.apache.webapp.admin.SetUpLoggerAction"
  +               type="org.apache.webapp.admin.logger.SetUpLoggerAction"
                  name="loggerForm"
                  scope="session">
       </action>
  @@ -375,7 +372,7 @@
   
       <!-- Process a host change -->
       <action    path="/host"
  -               type="org.apache.webapp.admin.HostAction"
  +               type="org.apache.webapp.admin.host.HostAction"
                  name="hostForm"
                 scope="session"
                 input="/host.jsp">
  @@ -391,7 +388,7 @@
       
        <!-- Process a logger change -->
       <action    path="/logger"
  -               type="org.apache.webapp.admin.LoggerAction"
  +               type="org.apache.webapp.admin.logger.LoggerAction"
                  name="loggerForm"
                 scope="session"
                 input="/logger.jsp">
  
  
  
  1.1                  
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/HostAction.java
  
  Index: HostAction.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/HostAction.java,v
 1.1 2002/02/13 21:37:44 manveen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/13 21:37:44 $
   *
   * ====================================================================
   *
   * 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 [EMAIL PROTECTED]
   *
   * 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.host;
  
  import java.util.Iterator;
  import java.util.Locale;
  import java.io.IOException;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  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;
  import javax.management.Attribute;
  import javax.management.MBeanServer;
  import javax.management.MBeanServerFactory;
  import javax.management.QueryExp;
  import javax.management.Query;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  
  import org.apache.struts.util.MessageResources;
  import org.apache.webapp.admin.ApplicationServlet;
  
  /**
   * Implementation of <strong>Action</strong> that validates
   * actions on a Host.
   *
   * @author Manveen Kaur
   * @version $Revision: 1.1 $Date: 2002/02/13 21:37:44 $
   */
  
  public final class HostAction extends Action {
      /**
       * The MBeanServer we will be interacting with.
       */
      private static MBeanServer mBServer = null;
      
      /**
       * The MessageResources we will be retrieving messages from.
       */
      private MessageResources resources = null;
      // --------------------------------------------------------- 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 {
          
          if (resources == null) {
              resources = getServlet().getResources();
          }
          Locale locale = (Locale)request.getSession().getAttribute(Action.LOCALE_KEY);
          
          // Validate the request parameters specified by the user
          ActionErrors errors = new ActionErrors();
          
          // Report any errors we have discovered back to the original form
          if (!errors.empty()) {
              saveErrors(request, errors);
              return (new ActionForward(mapping.getInput()));
          }
          
          // Acquire a reference to the MBeanServer containing our MBeans
          try {
              mBServer = ((ApplicationServlet) getServlet()).getServer();
          } catch (Throwable t) {
              throw new ServletException
              ("Cannot acquire MBeanServer reference", t);
          }
          
          /**
           * Get the host Name from the form.
           * This is used to lookup the MBeanServer and
           * retrieve this host's MBean.
           */
          String hostName = request.getParameter("hostName");
          ObjectName hostObjName = null;
          try{
              Iterator hostItr =
              mBServer.queryMBeans(new
              ObjectName(hostName), null).iterator();
              
              ObjectInstance objInstance = (ObjectInstance)hostItr.next();
              hostObjName = (objInstance).getObjectName();
          } catch (Throwable t) {
              throw new ServletException
              ("Cannot acquire MBean reference " + hostName, t);
          }
          
          /**
           * Extracting the values from the form and
           * updating the MBean with the new values.
           */
          String attribute = null;
          try{
              
              String nameText = request.getParameter("name");
              if(nameText != null) {
                  mBServer.setAttribute(hostObjName,
                  new Attribute(attribute=SetUpHostAction.NAME_PROP_NAME,
                  nameText));
              }
              
              String appBaseText = request.getParameter("appBase");
              if(appBaseText != null) {
                  mBServer.setAttribute(hostObjName,
                  new Attribute(attribute=SetUpHostAction.APPBASE_PROP_NAME,
                  appBaseText));
              }
              
              String debugLvlText = request.getParameter("debugLvl");
              if(debugLvlText != null) {
                  Integer debugLvl = new Integer(debugLvlText);
                  mBServer.setAttribute(hostObjName,
                  new Attribute(attribute=SetUpHostAction.DEBUG_PROP_NAME,
                  debugLvl));
              }
              
              String unpackWARsText = request.getParameter("unpackWARs");
              if(unpackWARsText != null) {
                  Boolean unpackWARs = Boolean.valueOf(unpackWARsText);
                  mBServer.setAttribute(hostObjName,
                  new Attribute(attribute=SetUpHostAction.UNPACKWARS_PROP_NAME,
                  unpackWARs));
              }
              
          }catch(Exception e){
              getServlet().log
              (resources.getMessage(locale, "users.error.attribute.set",
              attribute), e);
              response.sendError
              (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              resources.getMessage(locale, "users.error.attribute.set",
              attribute));
              return (null);
          }
          
          if (servlet.getDebug() >= 1)
              servlet.log(" Forwarding to success page");
          // Forward back to the test page
          return (mapping.findForward("Save Successful"));
          
      }
      
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/HostForm.java
  
  Index: HostForm.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/HostForm.java,v
 1.1 2002/02/13 21:37:44 manveen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/13 21:37:44 $
   *
   * ====================================================================
   *
   * 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 [EMAIL PROTECTED]
   *
   * 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.host;
  
  import javax.servlet.http.HttpServletRequest;
  import org.apache.struts.action.ActionError;
  import org.apache.struts.action.ActionErrors;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionMapping;
  import java.net.InetAddress;
  import java.util.ArrayList;
  
  /**
   * Form bean for the host page.
   *
   * @author Manveen Kaur
   * @version $Revision: 1.1 $ $Date: 2002/02/13 21:37:44 $
   */
  
  public final class HostForm extends ActionForm {
      
      // ----------------------------------------------------- Instance Variables
      
      /**
       * The text for the node label.
       */
      private String nodeLabel = null;
      
      /**
       * The text for the hostName.
       */
      private String name = null;
      
      /**
       * The text for the selected host name that is used to lookup the MBean info.
       * This contains all information including the service name to which this host 
belongs etc.
       */
      private String hostName = null;
      
      /**
       * The directory for the appBase.
       */
      private String appBase = null;
      
      /**
       * The text for the debug level.
       */
      private String debugLvl = "0";
      
      /**
       * Boolean for unpack WARs.
       */
      private String unpackWARs = "false";
      
      /**
       * The text for the port. -- TBD
       */
      private String findAliases = null;
      
      /**
       * Set of valid values for debug level.
       */
      private ArrayList debugLvlVals = null;
      
      /*
       * Represent boolean (true, false) values for unpackWARs etc.
       */
      private ArrayList booleanVals = null;
      
      /*
       * Represent aliases as a List.
       */    
      private ArrayList aliasVals = null;
     
      // ------------------------------------------------------------- Properties
      /**
       * Return the label of the node that was clicked.
       */
      public String getNodeLabel() {
          
          return this.nodeLabel;
          
      }
      
      /**
       * Set the node label.
       */
      public void setNodeLabel(String nodeLabel) {
          
          this.nodeLabel = nodeLabel;
          
      }
      
      /**
       * Return the selected node host name to lookup mBean.
       */
      public String getHostName() {
          
          return this.hostName;
          
      }
      
      /**
       * Set the selected node host name to lookup mBean.
       */
      public void setHostName(String hostName) {
          
          this.hostName = hostName;
          
      }
      
      /**
       * Return the host name.
       */
      public String getName() {
          
          return this.name;
          
      }
      
      /**
       * Set the host name.
       */
      public void setName(String name) {
          
          this.name = name;
          
      }
      
      /**
       * Return the appBase.
       */
      public String getAppBase() {
          
          return this.appBase;
          
      }
      
      
      /**
       * Set the appBase.
       */
      
      public void setAppBase(String appBase) {
          
          this.appBase = appBase;
          
      }
      
      /**
       * Return the unpackWARs.
       */
      public String getUnpackWARs() {
          
          return this.unpackWARs;
          
      }
      
      /**
       * Set the unpackWARs.
       */
      
      public void setUnpackWARs(String unpackWARs) {
          
          this.unpackWARs = unpackWARs;
          
      }
      
      /**
       * Return the debugVals.
       */
      public ArrayList getDebugLvlVals() {
          
          return this.debugLvlVals;
          
      }
      
      /**
       * Set the debugVals.
       */
      public void setDebugLvlVals(ArrayList debugLvlVals) {
          
          this.debugLvlVals = debugLvlVals;
          
      }
      
      
      /**
       * Return the Debug Level Text.
       */
      
      public String getDebugLvl() {
          
          return this.debugLvl;
          
      }
      
      /**
       * Set the Debug Level Text.
       */
      public void setDebugLvl(String debugLvl) {
          
          this.debugLvl = debugLvl;
          
      }
      
      /**
       * Return the booleanVals.
       */
      public ArrayList getBooleanVals() {
          
          return this.booleanVals;
          
      }
      
      /**
       * Set the booleanVals.
       */
      public void setBooleanVals(ArrayList booleanVals) {
          
          this.booleanVals = booleanVals;
          
      }
      
      /**
       * Return the List of alias Vals.
       */
      public ArrayList getAliasVals() {
          
          return this.aliasVals;
          
      }
      
      /**
       * Set the alias Vals.
       */
      public void setAliasVals(ArrayList aliasVals) {
          
          this.aliasVals = aliasVals;
          
      }
      
      // --------------------------------------------------------- Public Methods
      
      /**
       * Reset all properties to their default values.
       *
       * @param mapping The mapping used to select this instance
       * @param request The servlet request we are processing
       */
      public void reset(ActionMapping mapping, HttpServletRequest request) {
          
          this.name = null;
          this.appBase = null;
          this.debugLvl = "0";
          this.unpackWARs = "false";
          
      }
      
      /**
       * Validate the properties that have been set from this HTTP request,
       * and return an <code>ActionErrors</code> object that encapsulates any
       * validation errors that have been found.  If no errors are found, return
       * <code>null</code> or an <code>ActionErrors</code> object with no
       * recorded error messages.
       *
       * @param mapping The mapping used to select this instance
       * @param request The servlet request we are processing
       */
      
      public ActionErrors validate(ActionMapping mapping,
      HttpServletRequest request) {
          
          ActionErrors errors = new ActionErrors();
          
          String submit = request.getParameter("submit");
          
          // front end validation when save is clicked.
          if (submit != null) {
              
              // name cannot be null
              if ((name== null) || (name.length() < 1)) {
                  errors.add("name", new ActionError("error.hostName.required"));
              }
              
              // appBase cannot be null
              if ((appBase == null) || (appBase.length() < 1)) {
                  errors.add("appBase", new ActionError("error.appBase.required"));
              }
              
          }        
          return errors;
          
      }
      
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/SetUpHostAction.java
  
  Index: SetUpHostAction.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/SetUpHostAction.java,v
 1.1 2002/02/13 21:37:44 manveen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/13 21:37:44 $
   *
   * ====================================================================
   *
   * 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", "Tomcat", 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 [EMAIL PROTECTED]
   *
   * 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.host;
  
  
  import java.io.IOException;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Locale;
  import java.util.Arrays;
  import java.util.ArrayList;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  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;
  import javax.management.MBeanServer;
  import javax.management.MBeanServerFactory;
  import javax.management.QueryExp;
  import javax.management.Query;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  
  import org.apache.webapp.admin.LabelValueBean;
  import org.apache.webapp.admin.ApplicationServlet;
  import org.apache.webapp.admin.TomcatTreeBuilder;
  import org.apache.struts.util.MessageResources;
  
  /**
   * Test <code>Action</code> that handles events from the tree control test
   * page when a node linking to a host is selected.
   * @author Manveen Kaur
   * @version $Revision: 1.1 $ $Date: 2002/02/13 21:37:44 $
   */
  
  public class SetUpHostAction extends Action {
      
      private static MBeanServer mBServer = null;
      private MessageResources resources = null;
      
      public final static String NAME_PROP_NAME = "name";
      public final static String APPBASE_PROP_NAME = "appBase";
      public final static String DEBUG_PROP_NAME = "debug";
      public final static String UNPACKWARS_PROP_NAME = "unpackWARs";
      
      public final static String FINDALIASES_OPERATION_NAME = "findAliases";
      
      private ArrayList debugLvlList = null;
      private ArrayList booleanList = null;
      private ArrayList aliasList = null;
      
      // --------------------------------------------------------- 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 {
          
          HttpSession session = request.getSession();
          Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY);
          
          if (resources == null) {
              resources = getServlet().getResources();
          }
          
          if (form == null) {
              getServlet().log(" Creating new hostForm bean under key "
              + mapping.getAttribute());
              form = new HostForm();
              
              if ("request".equals(mapping.getScope()))
                  request.setAttribute(mapping.getAttribute(), form);
              else
                  request.getSession().setAttribute(mapping.getAttribute(), form);
          }
          
          String selectedName = request.getParameter("select");
          // label of the node that was clicked on.
          String nodeLabel = request.getParameter("nodeLabel");
          
          // Do transaction stuff before this
          
          HostForm hostFm = (HostForm) form;
          
          if(debugLvlList == null) {
              debugLvlList = new ArrayList();
              debugLvlList.add(new LabelValueBean("0", "0"));
              debugLvlList.add(new LabelValueBean("1", "1"));
              debugLvlList.add(new LabelValueBean("2", "2"));
              debugLvlList.add(new LabelValueBean("3", "3"));
              debugLvlList.add(new LabelValueBean("4", "4"));
              debugLvlList.add(new LabelValueBean("5", "5"));
              debugLvlList.add(new LabelValueBean("6", "6"));
              debugLvlList.add(new LabelValueBean("7", "7"));
              debugLvlList.add(new LabelValueBean("8", "8"));
              debugLvlList.add(new LabelValueBean("9", "9"));
              
          }
          
          /* Boolean (true.false) list for unpackWARs */
          if(booleanList == null) {
              booleanList = new ArrayList();
              booleanList.add(new LabelValueBean("True", "true"));
              booleanList.add(new LabelValueBean("False", "false"));
          }
          
          String name= null;
          String appBase = null;
          Integer debug = null;
          Boolean unpackWARs = null;
          
          // Acquire a reference to the MBeanServer containing our MBeans
          try {
              mBServer = ((ApplicationServlet) getServlet()).getServer();
          } catch (Throwable t) {
              throw new ServletException
              ("Cannot acquire MBeanServer reference", t);
          }
          
          String attribute = null;
          ObjectName hostObjName = null;
          
          try{
              
              Iterator hostItr =
              mBServer.queryMBeans(new ObjectName(TomcatTreeBuilder.HOST_TYPE +
              TomcatTreeBuilder.WILDCARD),
              null).iterator();
              
              hostObjName =
              ((ObjectInstance)hostItr.next()).getObjectName();
              
              name = (String)mBServer.getAttribute(hostObjName,
              attribute=NAME_PROP_NAME);
              
              appBase = (String)mBServer.getAttribute(hostObjName,
              attribute=APPBASE_PROP_NAME);
              
              debug = (Integer)mBServer.getAttribute(hostObjName,
              attribute=DEBUG_PROP_NAME);
              
              unpackWARs = (Boolean) mBServer.getAttribute(hostObjName,
              attribute=UNPACKWARS_PROP_NAME);
              
          }catch(Throwable t){
              getServlet().log
              (resources.getMessage(locale, "users.error.attribute.get",
              attribute), t);
              response.sendError
              (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              resources.getMessage(locale, "users.error.attribute.get",
              attribute));
              return (null);
          }
          
          try {
              // retrieve all aliases
              String aliases[] = (String[]) mBServer.invoke(hostObjName,
              FINDALIASES_OPERATION_NAME, null, null);
              
              // convert the alias string array into an alias ArrayList
              if (aliasList == null)
                  aliasList = new ArrayList(Arrays.asList(aliases));
              
          } catch (Exception e) {
              getServlet().log
              (resources.getMessage(locale, "users.error.invoke",
              FINDALIASES_OPERATION_NAME), e);
              response.sendError
              (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              resources.getMessage(locale, "users.error.invoke",
              FINDALIASES_OPERATION_NAME));
              return (null);            
          }
                  
          hostFm.setNodeLabel(nodeLabel);
          hostFm.setHostName(selectedName);
          
          hostFm.setName(name);
          hostFm.setAppBase(appBase);
          hostFm.setDebugLvl(debug.toString());
          hostFm.setUnpackWARs(unpackWARs.toString());
          
          hostFm.setDebugLvlVals(debugLvlList);
          hostFm.setBooleanVals(booleanList);
          hostFm.setAliasVals(aliasList);
          
          // Forward back to the test page
          return (mapping.findForward("Host"));
          
      }
      
      
  }
  
  
  
  
  1.1                  
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/logger/LoggerAction.java
  
  Index: LoggerAction.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/logger/LoggerAction.java,v
 1.1 2002/02/13 21:37:44 manveen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/13 21:37:44 $
   *
   * ====================================================================
   *
   * 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 [EMAIL PROTECTED]
   *
   * 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.logger;
  
  import java.util.Iterator;
  import java.util.Locale;
  import java.io.IOException;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  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;
  import javax.management.Attribute;
  import javax.management.MBeanServer;
  import javax.management.MBeanServerFactory;
  import javax.management.QueryExp;
  import javax.management.Query;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  
  import org.apache.struts.util.MessageResources;
  import org.apache.webapp.admin.ApplicationServlet;
  
  
  /**
   * Implementation of <strong>Action</strong> that validates
   * actions on a Logger.
   *
   * @author Manveen Kaur
   * @version $Revision: 1.1 $ $Date: 2002/02/13 21:37:44 $
   */
  
  public final class LoggerAction extends Action {
      
      private static MBeanServer mBServer = null;
      private MessageResources resources = null;
      // --------------------------------------------------------- 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 {
          
          if (resources == null) {
              resources = getServlet().getResources();
          }
          Locale locale = (Locale)request.getSession().getAttribute(Action.LOCALE_KEY);
          
          // Validate the request parameters specified by the user
          ActionErrors errors = new ActionErrors();
          
          // Report any errors we have discovered back to the original form
          if (!errors.empty()) {
              saveErrors(request, errors);
              return (new ActionForward(mapping.getInput()));
          }
          
          // Acquire a reference to the MBeanServer containing our MBeans
          try {
              mBServer = ((ApplicationServlet) getServlet()).getServer();
          } catch (Throwable t) {
              throw new ServletException
              ("Cannot acquire MBeanServer reference", t);
          }
          
          /**
           * Get the logger Name from the form.
           * This is used to lookup the MBeanServer and
           * retrieve this logger's MBean.
           */
          String loggerName = request.getParameter("loggerName");
          ObjectName loggerObjName = null;
          try{
              Iterator loggerItr =
              mBServer.queryMBeans(new
              ObjectName(loggerName), null).iterator();
              
              ObjectInstance objInstance = (ObjectInstance)loggerItr.next();
              loggerObjName = (objInstance).getObjectName();
          } catch (Throwable t) {
              throw new ServletException
              ("Cannot acquire MBean reference " + loggerName, t);
          }
                  
          /**
           * Extracting the values from the form and
           * updating the MBean with the new values.
           */
          String attribute = null;
          try{
              
              String debugLvlText = request.getParameter("debugLvl");
              if(debugLvlText != null) {
                  Integer debugLvl = new Integer(debugLvlText);
                  mBServer.setAttribute(loggerObjName,
                  new Attribute(attribute=SetUpLoggerAction.DEBUG_PROP_NAME,
                  debugLvl));
              }
              
              String verbosityLvlText = request.getParameter("verbosityLvl");
              if(verbosityLvlText != null) {
                  Integer verbosityLvl = new Integer(verbosityLvlText);
                  mBServer.setAttribute(loggerObjName,
                  new Attribute(attribute=SetUpLoggerAction.VERBOSITY_PROP_NAME,
                  verbosityLvl));
              }
              
              String type = request.getParameter("loggerType");
              // the following are specific to FileLogger
              if (type.equalsIgnoreCase(SetUpLoggerAction.FILE_LOGGER)) {
                  String directory = request.getParameter("directory");
                  if(directory != null) {
                      mBServer.setAttribute(loggerObjName,
                      new Attribute(attribute=SetUpLoggerAction.DIR_PROP_NAME,
                      directory));
                  }
                  
                  String prefix = request.getParameter("prefix");
                  if(prefix != null) {
                      mBServer.setAttribute(loggerObjName,
                      new Attribute(attribute=SetUpLoggerAction.PREFIX_PROP_NAME,
                      prefix));
                  }
                  
                  String suffix = request.getParameter("suffix");
                  if(suffix != null) {
                      mBServer.setAttribute(loggerObjName,
                      new Attribute(attribute=SetUpLoggerAction.SUFFIX_PROP_NAME,
                      suffix));
                  }
                  
                  String timestamp = request.getParameter("timestamp");
                  if(timestamp != null) {
                      Boolean tstamp = Boolean.valueOf(timestamp);
                      mBServer.setAttribute(loggerObjName,
                      new Attribute(attribute=SetUpLoggerAction.TIMESTAMP_PROP_NAME,
                      tstamp));
                  }                
              }
          }catch(Exception e){
              getServlet().log
              (resources.getMessage(locale, "users.error.attribute.set",
              attribute), e);
              response.sendError
              (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              resources.getMessage(locale, "users.error.attribute.set",
              attribute));
              return (null);
          }
          
          if (servlet.getDebug() >= 1)
              servlet.log(" Forwarding to success page");
          // Forward back to the test page
          return (mapping.findForward("Save Successful"));
          
      }
      
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/logger/LoggerForm.java
  
  Index: LoggerForm.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/logger/LoggerForm.java,v
 1.1 2002/02/13 21:37:44 manveen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/13 21:37:44 $
   *
   * ====================================================================
   *
   * 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 [EMAIL PROTECTED]
   *
   * 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.logger;
  
  import javax.servlet.http.HttpServletRequest;
  import org.apache.struts.action.ActionError;
  import org.apache.struts.action.ActionErrors;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionMapping;
  import java.net.InetAddress;
  import java.util.ArrayList;
  
  /**
   * Form bean for the logger page.
   *
   * @author Manveen Kaur
   * @version $Revision: 1.1 $ $Date: 2002/02/13 21:37:44 $
   */
  
  public final class LoggerForm extends ActionForm {
      
      // ----------------------------------------------------- Instance Variables
       
      /**
       * The text for the debug level.
       */
      private String debugLvl = "0";
      
      /**
       * The text for the logger name, used to retrieve
       * the corresponding logger mBean.
       */
      private String loggerName = null;
      
      /**
       * The text for the logger type. 
       * Specifies if it is a FileLogger, or SysErr or SysOut Logger.
       */
      private String loggerType = null;
      
      /**
       * The text for the verbosity.
       */
      private String verbosityLvl = null;
      
      /**
       * Set of valid values for debug level.
       */
      private ArrayList debugLvlVals = null;
      
      /**
       * Set of valid values for verbosity level.
       */
      private ArrayList verbosityLvlVals = null;
      
      /*
       * Represent boolean (true, false) values for timestamp.
       */    
      private ArrayList booleanVals = null;
      
      /**
       * The text for the directory.
       */
      private String directory = null;
      
      /**
       * The text for the prefix.
       */
      private String prefix = null;
      
      /**
       * The text for the timestamp.
       */
      private String timestamp = null;
      
      /**
       * The text for the suffix.
       */
      private String suffix = null;
      
      /**
       * The text for the node label.
       */
      private String nodeLabel = null;
      
      
      // ------------------------------------------------------------- Properties
      
      /**
       * Return the Logger Name.
       */
      public String getLoggerName() {
          
          return this.loggerName;
          
      }
      
      /**
       * Set the Logger Name.
       */
      public void setLoggerName(String loggerName) {
          
          this.loggerName = loggerName;
          
      }
          
      /**
       * Return the Logger type.
       */
      public String getLoggerType() {
          
          return this.loggerType;
          
      }
      
      /**
       * Set the Logger type.
       */
      public void setLoggerType(String loggerType) {
          
          this.loggerType = loggerType;
          
      }
      
      /**
       * Return the verbosityLvl.
       */
      public String getVerbosityLvl() {
          
          return this.verbosityLvl;
          
      }
      
      /**
       * Set the verbosityLvl.
       */
      public void setVerbosityLvl(String verbosityLvl) {
          
          this.verbosityLvl = verbosityLvl;
          
      }
      
      /**
       * Return the debugVals.
       */
      public ArrayList getDebugLvlVals() {
          
          return this.debugLvlVals;
          
      }
      
      /**
       * Set the debugVals.
       */
      public void setDebugLvlVals(ArrayList debugLvlVals) {
          
          this.debugLvlVals = debugLvlVals;
          
      }
      
      
      /**
       * Return the verbosityLvl Vals.
       */
      public ArrayList getVerbosityLvlVals() {
          
          return this.verbosityLvlVals;
          
      }
      
      /**
       * Set the verbosityLvl Vals.
       */
      public void setVerbosityLvlVals(ArrayList verbosityLvlVals) {
          
          this.verbosityLvlVals = verbosityLvlVals;
          
      }
      
      /**
       * Return the Debug Level Text.
       */
      public String getDebugLvl() {
          
          return this.debugLvl;
          
      }
      
      /**
       * Set the Debug Level Text.
       */
      public void setDebugLvl(String debugLvl) {
          
          this.debugLvl = debugLvl;
          
      }
      
      /**
       * Return the booleanVals.
       */
      public ArrayList getBooleanVals() {
          
          return this.booleanVals;
          
      }
      
      /**
       * Set the debugVals.
       */
      public void setBooleanVals(ArrayList booleanVals) {
          
          this.booleanVals = booleanVals;
          
      }
      
      /**
       * Return the directory.
       */
      public String getDirectory() {
          
          return this.directory;
          
      }
      
      /**
       * Set the directory.
       */
      public void setDirectory(String directory) {
          
          this.directory = directory;
          
      }
      
      /**
       * Return the prefix.
       */
      public String getPrefix() {
          
          return this.prefix;
          
      }
      
      /**
       * Set the prefix.
       */
      public void setPrefix(String prefix) {
          
          this.prefix = prefix;
          
      }
      /**
       * Return the suffix.
       */
      public String getSuffix() {
          
          return this.suffix;
          
      }
      
      /**
       * Set the suffix.
       */
      public void setSuffix(String suffix) {
          
          this.suffix = suffix;
          
      }
       
      /**
       * Return the label of the node that was clicked.
       */
      public String getNodeLabel() {
          
          return this.nodeLabel;
          
      }
      
      /**
       * Set the node label.
       */
      public void setNodeLabel(String nodeLabel) {
          
          this.nodeLabel = nodeLabel;
          
      }
  
      /**
       * Return the timestamp.
       */
      public String getTimestamp() {
          
          return this.timestamp;
          
      }
      
      /**
       * Set the timestamp.
       */
      public void setTimestamp(String timestamp) {
          
          this.timestamp = timestamp;
          
      }
      
      // --------------------------------------------------------- Public Methods
      
      /**
       * Reset all properties to their default values.
       *
       * @param mapping The mapping used to select this instance
       * @param request The servlet request we are processing
       */
      public void reset(ActionMapping mapping, HttpServletRequest request) {
          
          //FIX ME -- is this needed for debug and verbosity?
          this.debugLvl = "0";
          this.verbosityLvl = "0";
          
          this.directory = null;
          this.prefix = null;
          this.suffix = null;
          this.timestamp = "false";
          
      }
      
      /**
       * Validate the properties that have been set from this HTTP request,
       * and return an <code>ActionErrors</code> object that encapsulates any
       * validation errors that have been found.  If no errors are found, return
       * <code>null</code> or an <code>ActionErrors</code> object with no
       * recorded error messages.
       *
       * @param mapping The mapping used to select this instance
       * @param request The servlet request we are processing
       */
      
      public ActionErrors validate(ActionMapping mapping,
      HttpServletRequest request) {
          
          ActionErrors errors = new ActionErrors();
          
          String submit = request.getParameter("submit");        
          String type = request.getParameter("loggerType");
          
          // front end validation when save is clicked.
          // these checks should be done only if it is FileLogger. 
          // No checks needed otherwise        
          if ((submit != null)
             && (SetUpLoggerAction.FILE_LOGGER).equalsIgnoreCase(type)) {
               
              if ((directory == null) || (directory.length() < 1)) {
                  errors.add("directory",
                  new ActionError("error.directory.required"));
              }
                           
              if ((prefix == null) || (prefix.length() < 1)) {
                  errors.add("prefix",
                  new ActionError("error.prefix.required"));
              }
                           
              if ((suffix == null) || (suffix.length() < 1)) {
                  errors.add("suffix",
                  new ActionError("error.suffix.required"));
              }            
          }
          
          return errors;
      }
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/logger/SetUpLoggerAction.java
  
  Index: SetUpLoggerAction.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/logger/SetUpLoggerAction.java,v
 1.1 2002/02/13 21:37:44 manveen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/13 21:37:44 $
   *
   * ====================================================================
   *
   * 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", "Tomcat", 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 [EMAIL PROTECTED]
   *
   * 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 loggerS; 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.logger;
  
  import java.io.IOException;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Locale;
  import java.util.ArrayList;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  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;
  
  import javax.management.MBeanServer;
  import javax.management.MBeanServerFactory;
  import javax.management.QueryExp;
  import javax.management.Query;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  
  import org.apache.webapp.admin.LabelValueBean;
  import org.apache.webapp.admin.ApplicationServlet;
  import org.apache.webapp.admin.TomcatTreeBuilder;
  import org.apache.struts.util.MessageResources;
  /**
   * Test <code>Action</code> that handles events from the tree control when
   * a logger is chosen.
   *
   * @author Manveen Kaur
   * @version $Revision: 1.1 $ $Date: 2002/02/13 21:37:44 $
   */
  
  public class SetUpLoggerAction extends Action {
      
      private static MBeanServer mBServer = null;
      private MessageResources resources = null;
      
      public final static String CLASSNAME_PROP_NAME = "className";
      public final static String DEBUG_PROP_NAME = "debug";
      public final static String VERBOSITY_PROP_NAME = "verbosity";
      
      // specific to FileLogger
      public final static String DIR_PROP_NAME = "directory";
      public final static String PREFIX_PROP_NAME = "prefix";
      public final static String SUFFIX_PROP_NAME = "suffix";
      public final static String TIMESTAMP_PROP_NAME = "timestamp";
      
      public final static String FILE_LOGGER = "FileLogger";
      
      private ArrayList debugLvlList = null;
      private ArrayList verbosityLvlList = null;
      private ArrayList booleanList = null;
      
      // --------------------------------------------------------- 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 {
          
          HttpSession session = request.getSession();
          Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY);
          
          if (resources == null) {
              resources = getServlet().getResources();
          }        
          if (form == null) {
              getServlet().log("Creating new LoggerForm bean under key "
              + mapping.getAttribute());
              form = new LoggerForm();
              
              if ("request".equals(mapping.getScope()))
                  request.setAttribute(mapping.getAttribute(), form);
              else
                  session.setAttribute(mapping.getAttribute(), form);
              
          }
          
          String selectedName = request.getParameter("select");
          String loggerType = request.getParameter("type");
          // label of the node that was clicked on.
          String nodeLabel = request.getParameter("nodeLabel");
          
          LoggerForm loggerFm = (LoggerForm) form;
          
          if(debugLvlList == null) {
              debugLvlList = new ArrayList();
              debugLvlList.add(new LabelValueBean("0", "0"));
              debugLvlList.add(new LabelValueBean("1", "1"));
              debugLvlList.add(new LabelValueBean("2", "2"));
              debugLvlList.add(new LabelValueBean("3", "3"));
              debugLvlList.add(new LabelValueBean("4", "4"));
              debugLvlList.add(new LabelValueBean("5", "5"));
              debugLvlList.add(new LabelValueBean("6", "6"));
              debugLvlList.add(new LabelValueBean("7", "7"));
              debugLvlList.add(new LabelValueBean("8", "8"));
              debugLvlList.add(new LabelValueBean("9", "9"));
          }
          
          if(verbosityLvlList == null) {
              verbosityLvlList = new ArrayList();
              verbosityLvlList.add(new LabelValueBean("0", "0"));
              verbosityLvlList.add(new LabelValueBean("1", "1"));
              verbosityLvlList.add(new LabelValueBean("2", "2"));
              verbosityLvlList.add(new LabelValueBean("3", "3"));
              verbosityLvlList.add(new LabelValueBean("4", "4"));
          }
          
          /* Boolean (true.false) list for enableLookups */
          if(booleanList == null) {
              booleanList = new ArrayList();
              booleanList.add(new LabelValueBean("True", "true"));
              booleanList.add(new LabelValueBean("False", "false"));
          }
          
          // common for all loggers
          Integer debug = null;
          Integer verbosity = null;
          
          // specific to FileLogger
          String directory = null;
          String prefix = null;
          String suffix = null;
          Boolean timestamp = null;
          
          // Acquire a reference to the MBeanServer containing our MBeans
          try {
              mBServer = ((ApplicationServlet) getServlet()).getServer();
          } catch (Throwable t) {
              throw new ServletException
              ("Cannot acquire MBeanServer reference", t);
          }
          
          String attribute = null;
          try{
              
              Iterator loggerItr =
              mBServer.queryMBeans(new
              ObjectName(selectedName), null).iterator();
              
              ObjectInstance objInstance = (ObjectInstance)loggerItr.next();
              ObjectName loggerObjName = (objInstance).getObjectName();
              
              // common attributes for all logger types.
              debug = (Integer) mBServer.getAttribute(loggerObjName,
              attribute=DEBUG_PROP_NAME);
              
              verbosity = (Integer) mBServer.getAttribute(loggerObjName,
              attribute=VERBOSITY_PROP_NAME);
              
              if (FILE_LOGGER.equalsIgnoreCase(loggerType)) {
                  // Initialize rest of variables.
                  
                  directory = (String) mBServer.getAttribute(loggerObjName,
                  attribute=DIR_PROP_NAME);
                  
                  prefix = (String) mBServer.getAttribute(loggerObjName,
                  attribute=PREFIX_PROP_NAME);
                  
                  suffix = (String) mBServer.getAttribute(loggerObjName,
                  attribute=SUFFIX_PROP_NAME);
                  
                  timestamp = (Boolean) mBServer.getAttribute(loggerObjName,
                  attribute=TIMESTAMP_PROP_NAME);
                  
              }
              
          } catch(Exception e){
              getServlet().log
              (resources.getMessage(locale, "users.error.attribute.get",
              attribute), e);
              response.sendError
              (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              resources.getMessage(locale, "users.error.attribute.get",
              attribute));
              return (null);
          }
          
          //setting values obtained from the mBean to be displayed in the form.
          loggerFm.setLoggerType(loggerType);
          
          loggerFm.setDebugLvl(debug.toString());
          loggerFm.setDebugLvlVals(debugLvlList);
          
          loggerFm.setVerbosityLvl(verbosity.toString());
          loggerFm.setVerbosityLvlVals(verbosityLvlList);
          
          loggerFm.setLoggerName(selectedName);
          loggerFm.setNodeLabel(nodeLabel);
          
          if (FILE_LOGGER.equalsIgnoreCase(loggerType)) {
              
              loggerFm.setDirectory(directory);
              loggerFm.setPrefix(prefix);
              loggerFm.setSuffix(suffix);
              
              loggerFm.setBooleanVals(booleanList);
              loggerFm.setTimestamp(timestamp.toString());
              
          }
          // Forward back to the test page
          return (mapping.findForward("Logger"));
      }
  }
  
  
  
  
  1.4       +5 -7      
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/SetUpDeleteServiceAction.java
  
  Index: SetUpDeleteServiceAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/SetUpDeleteServiceAction.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SetUpDeleteServiceAction.java     13 Feb 2002 00:13:11 -0000      1.3
  +++ SetUpDeleteServiceAction.java     13 Feb 2002 21:37:44 -0000      1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/SetUpDeleteServiceAction.java,v
 1.3 2002/02/13 00:13:11 manveen Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/02/13 00:13:11 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/SetUpDeleteServiceAction.java,v
 1.4 2002/02/13 21:37:44 manveen Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/02/13 21:37:44 $
    *
    * ====================================================================
    *
  @@ -95,7 +95,7 @@
    * Test <code>Action</code> that handles events to delete services.
    *
    * @author Manveen Kaur
  - * @version $Revision: 1.3 $ $Date: 2002/02/13 00:13:11 $
  + * @version $Revision: 1.4 $ $Date: 2002/02/13 21:37:44 $
    */
   
   public class SetUpDeleteServiceAction extends Action {
  @@ -163,9 +163,7 @@
           }
           
           // Forward the Set as a request attribute
  -        request.setAttribute("services", services);
  -        if (deleteThis != null) 
  -            return new ActionForward("/deleteService.jsp");
  +        request.setAttribute("services", services);        
           return (mapping.findForward("Delete Service"));
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to