manveen     02/02/15 13:04:37

  Modified:    webapps/admin/WEB-INF struts-config.xml
               webapps/admin/WEB-INF/classes/org/apache/webapp/admin
                        ApplicationResources_en.properties
                        ApplicationResources_es.properties
                        TomcatTreeBuilder.java
               webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host
                        SetUpDeleteHostAction.java
               webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service
                        AddServiceAction.java
               webapps/admin/service service.jsp
  Added:       webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host
                        AddHostAction.java AddHostForm.java
                        SetUpAddHostAction.java
               webapps/admin/host addHost.jsp
  Log:
  Added functionality to add hosts from the admin tool.
  Made necessary changes to properties file and struts-config.xml
  
  Revision  Changes    Path
  1.32      +23 -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.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- struts-config.xml 14 Feb 2002 20:37:21 -0000      1.31
  +++ struts-config.xml 15 Feb 2002 21:04:37 -0000      1.32
  @@ -39,6 +39,10 @@
       <form-bean      name="hostForm"
                       type="org.apache.webapp.admin.host.HostForm"/>
   
  +    <!-- Add Host form bean -->
  +    <form-bean      name="addHostForm"
  +                    type="org.apache.webapp.admin.host.AddHostForm"/>
  +
       <!-- Delete Host form bean -->
       <form-bean      name="deleteHostForm"
                       type="org.apache.webapp.admin.host.DeleteHostForm"/>
  @@ -144,6 +148,10 @@
       <forward        name="Host"
                       path="/host/host.jsp"
                   redirect="false"/>
  +
  +    <forward        name="Add Host"
  +                    path="/host/addHost.jsp"
  +                redirect="false"/>
    
       <forward        name="Delete Host"
                       path="/host/deleteHost.jsp"
  @@ -303,6 +311,13 @@
                  name="hostForm"
                  scope="session">
       </action>
  +
  +    <!-- Set up add Host datastructure -->
  +    <action    path="/setUpAddHost"
  +               type="org.apache.webapp.admin.host.SetUpAddHostAction"
  +               name="addHostForm"
  +               scope="session">
  +    </action>
       
       <!-- Set up delete Host datastructure -->
       <action    path="/setUpDeleteHost"
  @@ -391,6 +406,14 @@
                  name="hostForm"
                 scope="session"
                 input="/host/host.jsp">
  +    </action>
  +
  +    <!-- Process a add host change -->
  +    <action    path="/addHost"
  +               type="org.apache.webapp.admin.host.AddHostAction"
  +               name="addHostForm"
  +              scope="session"
  +              input="/host/addHost.jsp">
       </action>
   
       <!-- Process a delete host change -->
  
  
  
  1.28      +2 -0      
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_en.properties
  
  Index: ApplicationResources_en.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_en.properties,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- ApplicationResources_en.properties        12 Feb 2002 06:10:41 -0000      1.27
  +++ ApplicationResources_en.properties        15 Feb 2002 21:04:37 -0000      1.28
  @@ -55,6 +55,7 @@
   error.proxyPortText.format=<li>Proxy Port Number not a valid integer!</li>
   error.proxyPortText.range=<li>Proxy Port Number seems out of range. Valid range is 
1-65535. </li>
   error.hostName.required=<li>Hostname is required</li>
  +error.hostName.exists=<li>Hostname already exists</li>
   error.appBase.required=<li>Application Base is required</li>
   service.name=Name
   service.engine.props=Engine properties
  @@ -158,6 +159,7 @@
   actions.delete=Delete
   error.defaultHost.required=<li>Default Hostname required</li>
   error.serviceName.required=<li>Service Name required</li>
  +error.serviceName.exists=<li>Service Name already exists</li>
   actions.thisrealm.delete=Delete this User Realm
   realm.driver=Database Driver
   realm.passwd=Database Password
  
  
  
  1.27      +2 -0      
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_es.properties
  
  Index: ApplicationResources_es.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_es.properties,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- ApplicationResources_es.properties        12 Feb 2002 06:10:41 -0000      1.26
  +++ ApplicationResources_es.properties        15 Feb 2002 21:04:37 -0000      1.27
  @@ -55,6 +55,7 @@
   error.proxyPortText.format=<li>Numero del puerto del proxy es un numero entero no 
valido!</li>
   error.proxyPortText.range=<li>El numero del puerto del proxy esta fuera de rango. 
El rango valido es 1-65535.</li>
   error.hostName.required=<li>Se requiere el hostname</li>
  +error.hostName.exists=<li>El hostname ya existe</li>
   error.appBase.required=<li>Se requiere la base de la aplicacion</li>
   service.name=Nombre
   service.engine.props=Propiedades del motor
  @@ -158,6 +159,7 @@
   actions.delete=Delete
   error.defaultHost.required=<li>Default Hostname requerido</li>
   error.serviceName.required=<li>Service name requerido</li>
  +error.serviceName.exists=<li>El ServiceName ya existe.</li>
   actions.thisrealm.delete=Suprima Este User Realm
   realm.driver=Database Driver
   realm.passwd=Database Password
  
  
  
  1.16      +4 -5      
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TomcatTreeBuilder.java
  
  Index: TomcatTreeBuilder.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TomcatTreeBuilder.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TomcatTreeBuilder.java    13 Feb 2002 22:30:20 -0000      1.15
  +++ TomcatTreeBuilder.java    15 Feb 2002 21:04:37 -0000      1.16
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TomcatTreeBuilder.java,v
 1.15 2002/02/13 22:30:20 remm Exp $
  - * $Revision: 1.15 $
  - * $Date: 2002/02/13 22:30:20 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TomcatTreeBuilder.java,v
 1.16 2002/02/15 21:04:37 manveen Exp $
  + * $Revision: 1.16 $
  + * $Date: 2002/02/15 21:04:37 $
    *
    * ====================================================================
    *
  @@ -96,7 +96,7 @@
    *
    * @author Jazmin Jonson
    * @author Manveen Kaur
  - * @version $Revision: 1.15 $ $Date: 2002/02/13 22:30:20 $
  + * @version $Revision: 1.16 $ $Date: 2002/02/15 21:04:37 $
    */
   
   
  @@ -143,7 +143,6 @@
           mBServer.queryMBeans(new ObjectName(FACTORY_TYPE + WILDCARD), 
null).iterator();
           ObjectInstance mBeanFactory = (ObjectInstance)factoryItr.next();
           
  -        System.out.println(" mbean factory= " + 
(mBeanFactory.getObjectName()).toString());
           return mBeanFactory;
       }
       
  
  
  
  1.2       +5 -5      
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/SetUpDeleteHostAction.java
  
  Index: SetUpDeleteHostAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/SetUpDeleteHostAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SetUpDeleteHostAction.java        14 Feb 2002 20:37:21 -0000      1.1
  +++ SetUpDeleteHostAction.java        15 Feb 2002 21:04:37 -0000      1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/SetUpDeleteHostAction.java,v
 1.1 2002/02/14 20:37:21 manveen Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/14 20:37:21 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/SetUpDeleteHostAction.java,v
 1.2 2002/02/15 21:04:37 manveen Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/15 21:04:37 $
    *
    * ====================================================================
    *
  @@ -93,7 +93,7 @@
    * Test <code>Action</code> that handles events to delete hosts.
    *
    * @author Manveen Kaur
  - * @version $Revision: 1.1 $ $Date: 2002/02/14 20:37:21 $
  + * @version $Revision: 1.2 $ $Date: 2002/02/15 21:04:37 $
    */
   
   public class SetUpDeleteHostAction extends Action {
  @@ -147,7 +147,7 @@
           
           // get the parent engine name to get the parent Engine mBean
           // on which the removeHost operation will be invoked.
  -        String serviceName = request.getParameter("serviceName");;
  +        String serviceName = request.getParameter("serviceName");
           String deleteThis = request.getParameter("this");
   
           // get the service name from the host mBean
  
  
  
  1.1                  
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/AddHostAction.java
  
  Index: AddHostAction.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/AddHostAction.java,v
 1.1 2002/02/15 21:04:37 manveen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/15 21:04:37 $
   *
   * ====================================================================
   *
   * 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.io.IOException;
  import java.util.Locale;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpSession;
  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.ObjectInstance;
  import javax.management.ObjectName;
  import javax.management.JMException;
  import org.apache.struts.util.MessageResources;
  
  import org.apache.webapp.admin.ApplicationServlet;
  import org.apache.webapp.admin.TomcatTreeBuilder;
  
  /**
   * Implementation of <strong>Action</strong> that validates
   * add host actions.
   *
   * @author Manveen Kaur
   * @version $Revision: 1.1 $ $Date: 2002/02/15 21:04:37 $
   */
  
  public final class AddHostAction extends Action {
      
      private static MBeanServer mBServer = null;
      private static 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 {
          
          // Look up the components we will be using as needed
          if (mBServer == null) {
              mBServer = ((ApplicationServlet) getServlet()).getServer();
          }
          if (resources == null) {
              resources = getServlet().getResources();
          }
          HttpSession session = request.getSession();
          Locale locale = (Locale) session.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()));
          }
          
          String serviceName = request.getParameter("serviceName");
          String hostName = request.getParameter("name");
          String unpackWARs = request.getParameter("unpackWARs");
          String appBase = request.getParameter("appBase");
          String debugLvlText = request.getParameter("debugLvl");
          
          ObjectInstance mBeanFactory = null;
          
          // unique mBean name of the new service that is created.
          String newHost = null;
          
          // Get hold of the parent engine.
          ObjectName engine = null;
          try {
              Iterator engineItr =
              mBServer.queryMBeans(new ObjectName(
              TomcatTreeBuilder.ENGINE_TYPE + ",service=" + serviceName),
              null).iterator();
              
              ObjectInstance objInstance = (ObjectInstance)engineItr.next();
              engine = (objInstance).getObjectName();
              
          } catch (Exception e) {
              throw new ServletException("Error getting engine mBean", e);
          }
          
          // invoke createStandardHost operation on the mBean factory.
          try {
              mBeanFactory = TomcatTreeBuilder.getMBeanFactory();
              ObjectName factory = mBeanFactory.getObjectName();
              
              Object[] params = new Object[2];
              // mBean name of the parent engine
              params[0] = new String(engine.toString());
              // name of the new host to be added
              params[1] = new String(hostName);
              
              String[] types = new String[2];
              types[0]= "java.lang.String";
              types[1]= "java.lang.String";
              
              newHost = (String)
              mBServer.invoke(factory, "createStandardHost", params, types);
              
          } catch (Throwable t) {
              getServlet().log
              (resources.getMessage(locale, "users.error.invoke",
              "createStandardHost"), t);
              response.sendError
              (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              resources.getMessage(locale, "users.error.invoke","createStandardHost"));
              return (null);
          } 
          
          // add the newly created service to the server mBean.
          try {
              Object[] params = new Object[1];
              params[0] = new String(newHost);
              
              String[] type = new String[1];
              type[0]= "java.lang.String";
              
              mBServer.invoke(engine, "addHost", params, type);
              
          } catch (Exception e) {
              getServlet().log
              (resources.getMessage(locale, "users.error.invoke",
              "addHost"), e);
              response.sendError
              (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              resources.getMessage(locale, "users.error.invoke",
              "addHost"));
              return (null);
          }
          
          // set the attributes read from the form to this newly created host.
          String attribute = null;
          try{
              ObjectName hostObjName = new ObjectName(newHost);
              
              if(debugLvlText != null) {
                  Integer debugLvl = new Integer(debugLvlText);
                  mBServer.setAttribute(hostObjName,
                  new Attribute(attribute=SetUpHostAction.DEBUG_PROP_NAME,
                  debugLvl));
              }
              
              if (unpackWARs != null) {
                  mBServer.setAttribute(hostObjName,
                  new Attribute(attribute=SetUpHostAction.UNPACKWARS_PROP_NAME,
                  new Boolean(unpackWARs)));
              }
              
              if(appBase != null) {
                  mBServer.setAttribute(hostObjName,
                  new Attribute(attribute=SetUpHostAction.APPBASE_PROP_NAME,
                  appBase));
              }
              
          }catch(Exception e){
              getServlet().log
              (resources.getMessage(locale, "users.error.set.attribute",
              attribute), e);
              response.sendError
              (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              resources.getMessage(locale, "users.error.set.attribute",
              attribute));
              return (null);
          }
          
          if (servlet.getDebug() >= 1)
              servlet.log(" Forwarding to success page");
          return (mapping.findForward("Save Successful"));
      }
      
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/AddHostForm.java
  
  Index: AddHostForm.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/AddHostForm.java,v
 1.1 2002/02/15 21:04:37 manveen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/15 21:04:37 $
   *
   * ====================================================================
   *
   * 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.ServletException;
  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.util.ArrayList;
  import java.util.Iterator;
  
  import javax.management.MBeanServer;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  import javax.management.InstanceAlreadyExistsException;
  
  import org.apache.webapp.admin.ApplicationServlet;
  import org.apache.webapp.admin.TomcatTreeBuilder;
  
  import org.apache.commons.modeler.Registry;
  
  /**
   * Form bean for the add host page.
   *
   * @author Manveen Kaur
   * @version $Revision: 1.1 $ $Date: 2002/02/15 21:04:37 $
   */
  
  public final class AddHostForm extends ActionForm {
      
      /**
       * The configuration information registry for our managed beans.
       */
      private static Registry registry = null;
      
      /**
       * The <code>MBeanServer</code> for this application.
       */
      private static MBeanServer mBServer = null;
      
      // ----------------------------------------------------- Instance Variables
      /**
       * The text for the hostName.
       */
      private String name = null;
      
      /**
       * The text for the debug level.
       */
      private String debugLvl = "0";
      
      /**
       * Boolean for unpack WARs.
       */
      private String unpackWARs = "false";
      
      /**
       * The directory for the appBase.
       */
      private String appBase = null;
      
      /**
       * The text for the serviceName.
       */
      private String serviceName = null;
      
      /**
       * Set of valid values for debug level.
       */
      private ArrayList debugLvlVals = null;
      
      /*
       * Represent boolean (true, false) values for unpackWARs etc.
       */
      private ArrayList booleanVals = null;
      
      // ------------------------------------------------------------- Methods
      
      /**
       * 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 Service Name.
       */
      public String getServiceName() {
          
          return this.serviceName;
          
      }
      
      /**
       * Set the Service Name.
       */
      public void setServiceName(String serviceName) {
          
          this.serviceName = serviceName;
          
      }
      
      /**
       * 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 host name.
       */
      public String getName() {
          
          return this.name;
          
      }
      
      /**
       * Set the host name.
       */
      public void setName(String name) {
          
          this.name = name;
          
      }
      
      // --------------------------------------------------------- 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");
          
          if (submit != 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"));
              }
              
              try {
                  ApplicationServlet servlet = (ApplicationServlet)getServlet();
                  mBServer = servlet.getServer();
                  
                  // get list of already existing hosts and throw an error if
                  // the name already exits
                  Iterator HostItr =
                  (mBServer.queryMBeans(new ObjectName(TomcatTreeBuilder.HOST_TYPE +
                  TomcatTreeBuilder.WILDCARD + ",service=" + serviceName), 
null)).iterator();
                  
                  while(HostItr.hasNext()){
                      ObjectInstance hostObj = (ObjectInstance)HostItr.next();
                      
                      String hostName =
                      (String)mBServer.getAttribute(hostObj.getObjectName(),"name");
                      
                      if (name.equalsIgnoreCase(hostName)) {
                          errors.add("name", new ActionError("error.hostName.exists"));
                      }
                  }
              } catch (Exception e) {
                 getServlet().log("Error getting attribute name", e);
              }
          }
          return errors;
      }
  }
  
  
  1.1                  
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/SetUpAddHostAction.java
  
  Index: SetUpAddHostAction.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/SetUpAddHostAction.java,v
 1.1 2002/02/15 21:04:37 manveen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/15 21:04:37 $
   *
   * ====================================================================
   *
   * 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.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 org.apache.webapp.admin.LabelValueBean;
  
  /**
   * Test <code>Action</code> that handles add host events.
   *
   * @author Manveen Kaur
   * @version $Revision: 1.1 $ $Date: 2002/02/15 21:04:37 $
   */
  
  public class SetUpAddHostAction extends Action {
      
      public final static String NAME_PROP_NAME = "name";
      
      // values 0,9 for debug level
      private ArrayList debugLvlList = null;
      
      // values true,false for unpackWARs
      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();
          
          // fill in the form values for display and editing
          if (form == null) {
              getServlet().log("Creating new AddHostForm bean under key "
              + mapping.getAttribute());
              form = new AddHostForm();
              
              if ("request".equals(mapping.getScope()))
                  request.setAttribute(mapping.getAttribute(), form);
              else
                  session.setAttribute(mapping.getAttribute(), form);
          }
          
          AddHostForm hostFm = (AddHostForm) 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"));
          }
          
          // the service Name is needed to retrieve the engine mBean to
          // which the new host mBean will be added.
          String serviceName = request.getParameter("serviceName");
          //System.out.println("Service name = " + serviceName);
          
          // default values
          String name = "";
          String appBase = "";        
          String debug = "0";
          String unpackWARs = "false";
          
          hostFm.setServiceName(serviceName);
          hostFm.setAppBase(appBase);
          hostFm.setDebugLvl(debug);
          hostFm.setUnpackWARs(unpackWARs);
          hostFm.setDebugLvlVals(debugLvlList);
          hostFm.setBooleanVals(booleanList);
          
          return (mapping.findForward("Add Host"));
          
      }
  }
  
  
  
  1.3       +5 -5      
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/AddServiceAction.java
  
  Index: AddServiceAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/AddServiceAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AddServiceAction.java     15 Feb 2002 09:40:39 -0000      1.2
  +++ AddServiceAction.java     15 Feb 2002 21:04:37 -0000      1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/AddServiceAction.java,v
 1.2 2002/02/15 09:40:39 manveen Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/02/15 09:40:39 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/AddServiceAction.java,v
 1.3 2002/02/15 21:04:37 manveen Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/02/15 21:04:37 $
    *
    * ====================================================================
    *
  @@ -90,7 +90,7 @@
    * add service actions.
    *
    * @author Manveen Kaur
  - * @version $Revision: 1.2 $ $Date: 2002/02/15 09:40:39 $
  + * @version $Revision: 1.3 $ $Date: 2002/02/15 21:04:37 $
    */
   
   public final class AddServiceAction extends Action {
  @@ -233,7 +233,7 @@
               
               if(defaultHost != null) {
                   mBServer.setAttribute(serviceObjName,
  -                new Attribute(SetUpServiceAction.HOST_PROP_NAME,
  +                new Attribute(attribute=SetUpServiceAction.HOST_PROP_NAME,
                   defaultHost));
               }
           }catch(Exception e){
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/admin/host/addHost.jsp
  
  Index: addHost.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/controls.tld" prefix="controls" %>
  
  <html:html locale="true">
  
  <%@ include file="../users/header.jsp" %>
  
  <!-- Body -->
  <body bgcolor="white">
  
  <!--Form -->
  
  <html:errors/>
  
  <html:form method="POST" action="/addHost">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr class="page-title-row">
        <td width="81%"> 
          <div class="page-title-text" align="left">
             <bean:message key="actions.host.create"/>
             <html:hidden property="serviceName"/>
          </div>
        </td>
      </tr>
    </table>
  
    <%@ include file="../buttons.jsp" %>
  
   <%-- Heading --%>
   
   <table border="0" cellspacing="0" cellpadding="0" width="100%">
      <tr> <td>  <div class="table-title-text"> 
         <bean:define name="addHostForm" id="addHostForm" scope="session"/>  
         <bean:message key="host.properties"/> 
      </div> </td> </tr>
    </table>
  
    <table class="back-table" border="0" cellspacing="0" cellpadding="1" width="100%">
      <tr> 
        <td> 
          <controls:table tableStyle="front-table" lineStyle="line-row">
              <controls:row header="true" 
                  labelStyle="table-header-text" dataStyle="table-header-text">
              <controls:label><bean:message key="service.property"/></controls:label>
              <controls:data><bean:message key="service.value"/> </controls:data>
          </controls:row>
  
          <controls:row labelStyle="table-label-text" dataStyle="table-normal-text">
              <controls:label><bean:message key="host.name"/>:</controls:label>
              <controls:data>
                <html:text property="name" size="24" maxlength="24"/>
              </controls:data>
          </controls:row>
  
          <controls:row labelStyle="table-label-text" dataStyle="table-normal-text">
              <controls:label><bean:message key="host.base"/>:</controls:label>
              <controls:data>
                <html:text property="appBase" size="24" maxlength="24"/>
              </controls:data>
          </controls:row>
  
          <controls:row labelStyle="table-label-text" dataStyle="table-normal-text">
              <controls:label><bean:message key="server.debuglevel"/>:</controls:label>
              <controls:data>
                  <html:select property="debugLvl">
                       <bean:define id="debugLvlVals" name="addHostForm" 
property="debugLvlVals"/>
                       <html:options collection="debugLvlVals" property="value"
                     labelProperty="label"/>
                  </html:select>
              </controls:data>
          </controls:row>
  
         <controls:row labelStyle="table-label-text" dataStyle="table-normal-text">
              <controls:label><bean:message key="host.wars"/>:</controls:label>
              <controls:data>
                 <html:select property="unpackWARs">
                       <bean:define id="booleanVals" name="addHostForm" 
property="booleanVals"/>
                       <html:options collection="booleanVals" property="value"
                     labelProperty="label"/>
                  </html:select>
              </controls:data>
          </controls:row>
  
    </controls:table>
      </td>
      </tr>
    </table>
  
  <br>
  
    <%@ include file="../buttons.jsp" %>
    </html:form>
  </body>
  
  </html:html>
  
  
  
  1.3       +3 -1      jakarta-tomcat-4.0/webapps/admin/service/service.jsp
  
  Index: service.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/service/service.jsp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- service.jsp       14 Feb 2002 20:37:22 -0000      1.2
  +++ service.jsp       15 Feb 2002 21:04:37 -0000      1.3
  @@ -38,8 +38,10 @@
               <controls:action url="">  <bean:message 
key="actions.connector.create"/> </controls:action>
               <controls:action url="">  <bean:message 
key="actions.connector.delete"/> </controls:action>
               <controls:action> ------------------------------------- 
</controls:action>
  -            <controls:action url="">  <bean:message key="actions.host.create"/> 
</controls:action>
               --%>
  +            <controls:action url='<%= "/setUpAddHost.do?serviceName=" + serviceName 
%>'>  
  +                    <bean:message key="actions.host.create"/> 
  +            </controls:action>
               <controls:action url='<%= "/setUpDeleteHost.do?serviceName=" + 
serviceName %>'>  
                       <bean:message key="actions.host.delete"/> 
               </controls:action>
  
  
  

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

Reply via email to