Please commit my patch to the HEAD branch.

Thanks,
Manveen

Comments:
------------

Connector functionality that enables connectors and their attributes to
be viewed and edited through the admin tool.

New files :        Location to be added
--------------------------------------
connector.jsp : jakarta-tomcat-4.0/webapps/admin/
SetUpConnector, ConnectorForm, ConnectorAction.java :
WEB-INF/classes/org/apache/webapp/admin/

Index: WEB-INF/struts-config.xml
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-4.0/webapps/admin/WEB-INF/struts-config.xml,v
retrieving revision 1.12
diff -u -r1.12 struts-config.xml
--- WEB-INF/struts-config.xml   20 Dec 2001 09:31:51 -0000      1.12
+++ WEB-INF/struts-config.xml   5 Jan 2002 07:37:41 -0000
@@ -148,6 +148,14 @@
               input="/service.jsp">
     </action>
 
+    <!-- Process a connector change -->
+    <action    path="/connector"
+               type="org.apache.webapp.admin.ConnectorAction"
+               name="connectorForm"
+              scope="session"
+              input="/connector.jsp">
+    </action>
+
     <!-- Process a set-locale action -->
     <action    path="/setLocale"
                type="org.apache.webapp.admin.SetLocaleAction"
cvs server: Diffing WEB-INF/classes
cvs server: Diffing WEB-INF/classes/org
cvs server: Diffing WEB-INF/classes/org/apache
cvs server: Diffing WEB-INF/classes/org/apache/webapp
cvs server: Diffing WEB-INF/classes/org/apache/webapp/admin
Index: WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_en.properties
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_en.properties,v
retrieving revision 1.10
diff -u -r1.10 ApplicationResources_en.properties
--- WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_en.properties  3 Jan 
2002 23:21:53 -0000       1.10
+++ WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_en.properties  5 Jan 
+2002 07:37:42 -0000
@@ -27,11 +27,34 @@
 server.debuglevel=Debug Level
 server.shutdown=Shutdown
 server.properties=Properties
-error.portNumberText.required=<li>PortNumber cannot be empty</li>
-error.shutdownText.length=<li>Shutdown Text must be atleast 6 characters</li>
+error.portNumber.required=<li>PortNumber cannot be empty</li>
 error.portNumber.format=<li>PortNumber not a valid integer!</li>
 error.portNumber.range=<li>PortNumber seems out of range. Valid range is 1-65535. 
</li>
-error.engineName.required=<li>Engine name is required</li> 
+error.shutdownText.length=<li>Shutdown Text must be atleast 6 characters</li>
+error.engineName.required=<li>Engine name is required</li>
+error.acceptCountText.required=<li>Accept count required</li>
+error.acceptCountText.format=<li>Accept count not a valid integer!</li>
+error.acceptCountText.range=<li>Accept count seems out of range. Valid range is 
+1-218. </li>
+error.connTimeOutText.required=<li>Connection time out required</li>
+error.connTimeOutText.format=<li>Connection time out not a valid integer!</li>
+error.connTimeOutText.range=<li>Connection time out seems out of range. Valid range 
+is 0-60000. </li>
+error.bufferSizeText.required=<li>Buffer Size required</li>
+error.bufferSizeText.format=<li>Buffer Size not a valid integer!</li>
+error.bufferSizeText.range=<li>Buffer Size seems out of range. Valid range is 1-8192. 
+</li>
+error.address.invalid=<li>IP Address invalid</li>
+error.redirectPortText.required=<li>Redirect Port Number cannot be empty</li>
+error.redirectPortText.format=<li>Redirect Port Number not a valid integer!</li>
+error.redirectPortText.range=<li>Redirect Port Number seems out of range. Valid range 
+is 1-65535. </li>
+error.minProcessorsText.required=<li>Minimum Processors cannot be empty</li>
+error.minProcessorsText.format=<li>Minimum Processors not a valid integer!</li>
+error.minProcessorsText.range=<li>Minimum Processors seems out of range. Valid range 
+is 1-512. </li>
+error.maxProcessorsText.required=<li>Maximum Processors cannot be empty</li>
+error.maxProcessorsText.format=<li>Maximum Processors not a valid integer!</li>
+error.maxProcessorsText.range=<li>Maximum Processors seems out of range. Valid range 
+is 1-512. Also, maximum >= minimum. </li>
+error.proxyName.invalid=<li>Proxy name is invalid</li>
+error.proxyPortText.required=<li>Proxy Port Number cannot be empty</li>
+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>
 service.service=Service
 service.name=Name
 service.engine.props=Engine properties
@@ -69,4 +92,3 @@
 connector.max=Maximum
 connector.proxy.name=Proxy Name
 connector.proxy.portnumber=Proxy Port Number
-error.acceptCountText.required=<li>Accept count required</li>
Index: WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_es.properties
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_es.properties,v
retrieving revision 1.12
diff -u -r1.12 ApplicationResources_es.properties
--- WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_es.properties  3 Jan 
2002 23:21:53 -0000       1.12
+++ WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_es.properties  5 Jan 
+2002 07:37:43 -0000
@@ -27,11 +27,34 @@
 server.debuglevel=Nivel de Depuracion
 server.shutdown=Detener
 server.properties=Caracteristicas
-error.portNumberText.required=<li>El numero del puerto no puede estar vacio.</li>
-error.shutdownText.length=<li>El texto de la para Detener debe ser de al menos 6 
caracteres!</li>
+error.portNumber.required=<li>El numero del puerto no puede estar vacio.</li>
 error.portNumber.format=<li>El numero de puerto es un entero no valido! </li>
 error.portNumber.range=<li>El numero de puerto esta fuera del rango. El rango valido 
es 1-65535.</li>
+error.shutdownText.length=<li>El texto de la para Detener debe ser de al menos 6 
+caracteres!</li>
 error.engineName.required=<li>Se requiere el nombre del motor</li> 
+error.acceptCountText.required=<li>Valide la cuenta requerida</li>
+error.acceptCountText.format=<li>Valide la cuenta no un numero entero valido!</li>
+error.acceptCountText.range=<li>Valide la cuenta se parece fuera de rango. El rango 
+válido es 1-218. </li>
+error.connTimeOutText.required=<li>Tiempo de conexion fuera de requerido</li>
+error.connTimeOutText.format=<li>Tiempo de conexion fuera no de un numero entero 
+valido! </li>
+error.connTimeOutText.range=<li>El tiempo de conexion hacia fuera se parece fuera de 
+rango. El rango válido es 0-60000. </li>
+error.bufferSizeText.required=<li>Talla de almacenador intermediario requerida</li>
+error.bufferSizeText.format=<li>Talla de almacenador intermediario no un numero 
+entero valido! </li>
+error.bufferSizeText.range=<li>La talla de almacenador intermediario se parece fuera 
+de rango. El rango valid es 1-8192. </li>
+error.address.invalid=<li>EL IP ADDRESS no valido</li>
+error.redirectPortText.required=<li>Vuelva a dirigir el numero de acceso no puede ser 
+vacio </li>
+error.redirectPortText.format=<li>Vuelva a dirigir el numero de acceso no un numero 
+entero valido! </li>
+error.redirectPortText.range=<li>Vuelva a dirigir el numero de acceso se parece fuera 
+de rango. El rango validoes 1-65535.</li>
+error.minProcessorsText.required=<li>Los procesadores minimos no pueden ser 
+vacios</li>
+error.minProcessorsText.format=<li>Procesadores minimos no un numero entero 
+valido!</li>
+error.minProcessorsText.range=<li>Los procesadores minimos se parecen fuera de rango. 
+El rango valido es 1-512. </li>
+error.maxProcessorsText.required=<li>Los procesadores maximos no pueden ser 
+vacios</li>
+error.maxProcessorsText.format=<li>Procesadores maximos no un numero entero 
+valido!</li>
+error.maxProcessorsText.range=<li>Los procesadores maximos se parecen fuera de rango. 
+El rango valido es 1-512. Tambien, maximo > = minimo.</li>
+error.proxyPortText.required=<li>El numero de acceso del poder no puede ser vacio</li>
+error.proxyName.invalid=<li>El nombre del poder es invalido</li>
+error.proxyPortText.format=<li>Numero de acceso del poder no un numero entero 
+valido!</li>
+error.proxyPortText.range=<li>El numero de acceso del poder se parece fuera de rango. 
+El rango valido es 1-65535.</li>
 service.service=Mantienen
 service.name=Nombre
 service.engine.props=Caracteristicas del motor
@@ -69,4 +92,3 @@
 connector.max=Maximo
 connector.proxy.name=Nombre del poder
 connector.proxy.portnumber=Numero de acceso del poder
-error.acceptCountText.required=Valide la cuenta requerida
Index: WEB-INF/classes/org/apache/webapp/admin/ServerForm.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ServerForm.java,v
retrieving revision 1.4
diff -u -r1.4 ServerForm.java
--- WEB-INF/classes/org/apache/webapp/admin/ServerForm.java     20 Dec 2001 09:31:52 
-0000      1.4
+++ WEB-INF/classes/org/apache/webapp/admin/ServerForm.java     5 Jan 2002 07:37:45 
+-0000
@@ -211,7 +211,7 @@
             
             if ((portNumberText == null) || (portNumberText.length() < 1)) {
                 errors.add("portNumberText",
-                new ActionError("error.portNumberText.required"));
+                new ActionError("error.portNumber.required"));
             } else {
                 try {
                     int port = Integer.parseInt(portNumberText);
Index: WEB-INF/classes/org/apache/webapp/admin/TomcatTreeBuilder.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TomcatTreeBuilder.java,v
retrieving revision 1.3
diff -u -r1.3 TomcatTreeBuilder.java
--- WEB-INF/classes/org/apache/webapp/admin/TomcatTreeBuilder.java      14 Dec 2001 
23:22:33 -0000      1.3
+++ WEB-INF/classes/org/apache/webapp/admin/TomcatTreeBuilder.java      5 Jan 2002 
+07:37:46 -0000
@@ -91,11 +91,10 @@
  *
  * @author Jazmin Jonson
  * @author Manveen Kaur
- * @version
+ * @version $Revision: $ $Date: $
  */
 
 
-
 public class TomcatTreeBuilder implements TreeBuilder{
     
     // This SERVER_LABEL needs to be localized
@@ -104,8 +103,8 @@
     public final static String SERVER_TYPE = "Catalina:type=Server";
     public final static String SERVICE_TYPE = "Catalina:type=Service";
     public final static String ENGINE_TYPE = "Catalina:type=Engine";
-    private final static String CONNECTOR_TYPE = "Catalina:type=Connector";
-    public final static String HOST_TYPE = "Catalina:type=Host";    
+    public final static String CONNECTOR_TYPE = "Catalina:type=Connector";
+    public final static String HOST_TYPE = "Catalina:type=Host";
     public final static String WILDCARD = ",*";
     
     private static MBeanServer mBServer = null;
@@ -149,8 +148,7 @@
         
         return serverNode;
         
-    }
-    
+    }    
     
     public void getServices(TreeControlNode serverNode)
     throws JMException, ServletException {
@@ -185,15 +183,14 @@
             serverNode.addChild(serviceNode);
             
             getConnectors(serviceNode, serviceName);
+
         }
     }
     
     public void getConnectors(TreeControlNode serviceNode,
     String serviceName)
-    
     throws JMException{
         
-        
         Iterator ConnectorItr =
         (mBServer.queryMBeans(new ObjectName(CONNECTOR_TYPE + WILDCARD +
         ",service=" + serviceName),
@@ -210,25 +207,22 @@
             (String)mBServer.getAttribute(connectorObj.getObjectName(),
             "scheme");
             
-            // HACK to take into account special characters like = and &
-            // in the node name, could remove this code if encode URL
-            // and later request.getParameter() could deal with = and &
-            // character in parameter values. Decoding name not needed
-            // because Tomcat does this automatically
-            
             encodedConnectorName =  
URLEncoder.encode(connectorObj.getObjectName().toString());
             
-            connectorNode =
-            new TreeControlNode(connectorObj.getObjectName().toString(),
-            "folder_16_pad.gif",
-            "Connector(" + connectorName + ")",
-            "treeControlTest.do?select=" +
-            encodedConnectorName,
-            null, true);
-            
-            serviceNode.addChild(connectorNode);
-        }
-        
+            // Do not display the connector node if it is a warp connector.
+            // This is because warp connector doesn't conform to the
+            // standard Engine/Host/Context hierarchy and we don't support it.
+            if (!"warp".equalsIgnoreCase(connectorName)) {
+                connectorNode =
+                new TreeControlNode(connectorObj.getObjectName().toString(),
+                "folder_16_pad.gif",
+                "Connector(" + connectorName + ")",
+                "setUpConnector.do?select=" +
+                encodedConnectorName,
+                "content", true);
+                
+                serviceNode.addChild(connectorNode);
+            }
+        }        
     }
-    
 }

Attachment: connector.jsp
Description: application/unknown-content-type-jspfile

/*
 * $Header: Exp $
 * $Revision: $
 * $Date: $
 *
 * ====================================================================
 *
 * 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;

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 javax.management.JMException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanInfo;
import org.apache.struts.util.MessageResources;

/**
 * Implementation of <strong>Action</strong> that validates
 * actions on a Connector.
 *
 * @author Manveen Kaur
 * @version $Revision: 1.1 $ $Date: 2001/12/14 23:22:33 $
 */

public final class ConnectorAction extends Action {
    
    private static MBeanServer mBServer = 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 {
        
        try{
            
            // front end validation and checking.
            // ===================================================
            MessageResources messages = 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()));
            }
            
            if(mBServer == null) {
                ApplicationServlet servlet = (ApplicationServlet)getServlet();
                mBServer = servlet.getServer();
            }
            
            /**
             * Get the connector Name from the form.
             * This is used to lookup the MBeanServer and
             * retrieve this connector's MBean.
             */
            String connectorName = request.getParameter("connectorName");
            
            Iterator connectorItr =
            mBServer.queryMBeans(new
            ObjectName(connectorName), null).iterator();
            
            ObjectInstance objInstance = (ObjectInstance)connectorItr.next();
            ObjectName connectorObjName = (objInstance).getObjectName();
            
            /**
             * Extracting the values from the form and
             * updating the MBean with the new values.
             */
            
            String debugLvlText = request.getParameter("debugLvl");
            if(debugLvlText != null) {
                Integer debugLvl = new Integer(debugLvlText);
                mBServer.setAttribute(connectorObjName,
                new Attribute(SetUpConnectorAction.DEBUG_PROP_NAME,
                debugLvl));
            }
            
            String acceptCountText = request.getParameter("acceptCountText");
            if(acceptCountText != null) {
                Integer acceptCount = new Integer(acceptCountText);
                mBServer.setAttribute(connectorObjName,
                new Attribute(SetUpConnectorAction.ACCEPT_COUNT_PROP_NAME,
                acceptCount));
            }
            
            String connTimeOutText = request.getParameter("connTimeOutText");
            if(connTimeOutText != null) {
                Integer connTimeOut = new Integer(connTimeOutText);
                mBServer.setAttribute(connectorObjName,
                new Attribute(SetUpConnectorAction.CONN_TO_PROP_NAME,
                connTimeOut));
                
            }
            
            String bufferSizeText = request.getParameter("bufferSizeText");
            if(bufferSizeText != null) {
                Integer bufferSize = new Integer(bufferSizeText);
                mBServer.setAttribute(connectorObjName,
                new Attribute(SetUpConnectorAction.BUFF_SIZE_PROP_NAME,
                bufferSize));
            }
            
            String enableLookups = request.getParameter("enableLookups");
            if(enableLookups != null) {
                Boolean enable = Boolean.valueOf(enableLookups);
                mBServer.setAttribute(connectorObjName,
                new Attribute(SetUpConnectorAction.ENABLE_LOOKUPS_PROP_NAME,
                enable));
            }
            
            String address = request.getParameter("address");
            if(address != null) {
                mBServer.setAttribute(connectorObjName,
                new Attribute(SetUpConnectorAction.ADDRESS_PROP_NAME,
                address));
            }
                        
            String minProcessorsText = request.getParameter("minProcessorsText");
            if (minProcessorsText != null) {
                Integer minProcessors = new Integer(minProcessorsText);
                mBServer.setAttribute(connectorObjName,
                new Attribute(SetUpConnectorAction.PROC_MIN_PROP_NAME,
                minProcessors));
            }
            
            
            String maxProcessorsText = request.getParameter("maxProcessorsText");
            if(maxProcessorsText != null) {
                Integer maxProcessors = new Integer(maxProcessorsText);
                mBServer.setAttribute(connectorObjName,
                new Attribute(SetUpConnectorAction.PROC_MAX_PROP_NAME,
                maxProcessors));
            }
            
            String portText = request.getParameter("portText");
            if (portText != null) {
                Integer port = new Integer(portText);
                mBServer.setAttribute(connectorObjName,
                new Attribute(SetUpConnectorAction.PORT_PROP_NAME,
                port));
            }
                        
            String redirectPortText = request.getParameter("redirectPortText");
            if(redirectPortText != null) {
                Integer redirectPort = new Integer(redirectPortText);
                mBServer.setAttribute(connectorObjName,
                new Attribute(SetUpConnectorAction.REDIRECT_PORT_PROP_NAME,
                redirectPort));
            }
            
            String proxyName = request.getParameter("proxyName");
            if (proxyName != null) {
                mBServer.setAttribute(connectorObjName,
                new Attribute(SetUpConnectorAction.PROXY_NAME_PROP_NAME,
                proxyName));
            }
                        
            String proxyPortText = request.getParameter("proxyPortText");
            if(proxyPortText != null) {
                Integer proxyPort = new Integer(proxyPortText);
                mBServer.setAttribute(connectorObjName,
                new Attribute(SetUpConnectorAction.PROXY_PORT_PROP_NAME,
                proxyPort));
            }
            
        }catch(Throwable t){
            t.printStackTrace(System.out);
            //forward to error page
        }
        if (servlet.getDebug() >= 1)
            servlet.log(" Forwarding to success page");
        // Forward back to the test page
        return (mapping.findForward("Save Successful"));
        
    }
    
}
/*
 * $Header: 
/home/cvspublic/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ConnectorForm.java,v
 1.1 2001/12/14 23:22:33 patrickl Exp $
 * $Revision: 1.1 $
 * $Date: 2001/12/14 23:22:33 $
 *
 * ====================================================================
 *
 * 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;

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 connector page.
 *
 * @author Manveen Kaur
 * @version $Revision:  $ $Date:  $
 */

public final class ConnectorForm extends ActionForm {
    
    // ----------------------------------------------------- Instance Variables
    
    /**
     * The text for the scheme.
     */
    private String scheme = null;
    
    /**
     * The text for the accept Count.
     */
    private String acceptCountText = null;
    
    /**
     * The text for the Connection Time Out.
     */
    private String connTimeOutText = null;
    
    
    /**
     * The text for the debug level.
     */
    private String debugLvl = "0";
    
    /**
     * The text for the buffer size.
     */
    private String bufferSizeText = null;
    
    /**
     * The value of eanble Lookups.
     */
    private String enableLookups = "false";
    
    /**
     * The text for the address.
     */
    private String address = null;
    
    /**
     * The text for the minProcessors.
     */
    private String minProcessorsText = null;
    
    /**
     * The text for the max Processors.
     */
    private String maxProcessorsText = null;
    
    
    /**
     * The text for the port.
     */
    private String portText = null;
    
    /**
     * The text for the redirect port.
     */
    private String redirectPortText = null;
    
    /**
     * The text for the proxyName.
     */
    private String proxyName = null;
    
    /**
     * The text for the proxy Port Number.
     */
    private String proxyPortText = null;
    
    
    /**
     * The text for the connectorName.
     */
    private String connectorName = null;
    
    /**
     * Set of valid values for debug level.
     */
    private ArrayList debugLvlVals = null;
    
    /*
     * Represent boolean (true, false) values for enableLookups etc.
     */
    
    private ArrayList booleanVals = null;
    
    // ------------------------------------------------------------- Properties
    
    /**
     * Return the Class Name.
     */
    public String getScheme() {
        
        return this.scheme;
        
    }
    
    /**
     * Set the Scheme.
     */
    public void setScheme(String scheme) {
        
        this.scheme = scheme;
        
    }
    
    /**
     * Return the acceptCountText.
     */
    public String getAcceptCountText() {
        
        return this.acceptCountText;
        
    }
    
    
    /**
     * Set the acceptCountText.
     */
    
    public void setAcceptCountText(String acceptCountText) {
        
        this.acceptCountText = acceptCountText;
        
    }
    
    /**
     * Return the connTimeOutText.
     */
    public String getConnTimeOutText() {
        
        return this.connTimeOutText;
        
    }
    
    /**
     * Set the connTimeOutText.
     */
    
    public void setConnTimeOutText(String connTimeOutText) {
        
        this.connTimeOutText = connTimeOutText;
        
    }
    
    
    
    
    /**
     * Return the bufferSizeText.
     */
    public String getBufferSizeText() {
        
        return this.bufferSizeText;
        
    }
    
    /**
     * Set the bufferSizeText.
     */
    
    public void setBufferSizeText(String bufferSizeText) {
        
        this.bufferSizeText = bufferSizeText;
        
    }
    
    /**
     * Return the address.
     */
    public String getAddress() {
        
        return this.address;
        
    }
    
    /**
     * Set the connTimeOutText.
     */
    
    public void setAddress(String address) {
        
        this.address = address;
        
    }
    
    
    /**
     * Return the proxy Name.
     */
    public String getProxyName() {
        
        return this.proxyName;
        
    }
    
    /**
     * Set the proxy Name.
     */
    
    public void setProxyName(String proxyName) {
        
        this.proxyName = proxyName;
        
    }
    
    /**
     * Return the proxy Port NumberText.
     */
    public String getProxyPortText() {
        
        return this.proxyPortText;
        
    }
    
    /**
     * Set the proxy Port NumberText.
     */
    
    public void setProxyPortText(String proxyPortText) {
        
        this.proxyPortText = proxyPortText;
        
    }
    
    /**
     * 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 Enable lookup Text.
     */
    
    public String getEnableLookups() {
        
        return this.enableLookups;
        
    }
    
    /**
     * Set the Enable Lookup Text.
     */
    public void setEnableLookups(String enableLookups) {
        
        this.enableLookups = enableLookups;
        
    }
    
    /**
     * Return the booleanVals.
     */
    public ArrayList getBooleanVals() {
        
        return this.booleanVals;
        
    }
    
    /**
     * Set the debugVals.
     */
    public void setBooleanVals(ArrayList booleanVals) {
        
        this.booleanVals = booleanVals;
        
    }
    
    /**
     * Return the min Processors Text.
     */
    public String getMinProcessorsText() {
        
        return this.minProcessorsText;
        
    }
    
    /**
     * Set the minProcessors Text.
     */
    public void setMinProcessorsText(String minProcessorsText) {
        
        this.minProcessorsText = minProcessorsText;
        
    }
    
    /**
     * Return the max processors Text.
     */
    public String getMaxProcessorsText() {
        
        return this.maxProcessorsText;
        
    }
    
    /**
     * Set the Max Processors Text.
     */
    public void setMaxProcessorsText(String maxProcessorsText) {
        
        this.maxProcessorsText = maxProcessorsText;
        
    }
    
    /**
     * Return the port text.
     */
    public String getPortText() {
        
        return this.portText;
        
    }
    
    /**
     * Set the port Text.
     */
    public void setPortText(String portText) {
        
        this.portText = portText;
        
    }
    
    
    /**
     * Return the port.
     */
    public String getRedirectPortText() {
        
        return this.redirectPortText;
        
    }
    
    /**
     * Set the Redirect Port Text.
     */
    public void setRedirectPortText(String redirectPortText) {
        
        this.redirectPortText = redirectPortText;
        
    }
    
    /**
     * Return the Service Name.
     */
    public String getConnectorName() {
        
        return this.connectorName;
        
    }
    
    /**
     * Set the Service Name.
     */
    public void setConnectorName(String connectorName) {
        
        this.connectorName = connectorName;
        
    }
    
    // --------------------------------------------------------- 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.portText = null;
        this.acceptCountText = null;
        this.connTimeOutText = null;
        this.bufferSizeText = null;
        this.address = null;
        this.enableLookups = "false";
        this.minProcessorsText = null;
        this.maxProcessorsText = null;
        this.portText = null;
        this.redirectPortText = null;
        this.proxyName = null;
        this.proxyPortText = null;
        
    }
    
    /**
     * 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
     */
    
    private ActionErrors errors;
    
    public ActionErrors validate(ActionMapping mapping,
    HttpServletRequest request) {
        
        errors = new ActionErrors();
        
        String submit = request.getParameter("submit");
        
        // front end validation when save is clicked.
        if (submit != null) {
            
            /* general */
            numberCheck("acceptCountText", acceptCountText, true, 1, 128);
            numberCheck("connTimeOutText", connTimeOutText, true, 0, 60000);
            numberCheck("bufferSizeText", bufferSizeText, true, 1, 8192);
            
            /* The IP address can also be null -- which means open the
             server socket on *all* IP addresses for this host */
            if (address.length() > 0) {
                try {
                    InetAddress.getByName(address);
                } catch (Exception e) {
                    errors.add("address", new ActionError("error.address.invalid"));
                }
            }
            
            /* ports */
            numberCheck("portNumber",  portText, true, 1, 65535);
            numberCheck("redirectPortText",  redirectPortText, true, 0, 65535);
            
            /* processors*/
            numberCheck("minProcessorsText",  minProcessorsText, true, 1, 512);
            try {
                // if min is a valid integer, then check that max >= min
                int min = Integer.parseInt(minProcessorsText);
                numberCheck("maxProcessorsText",  maxProcessorsText, true, min-1, 512);
            } catch (Exception e) {
                // check for the complete range
                numberCheck("maxProcessorsText",  maxProcessorsText, true, 1, 512);
            }
            
            /* proxy*/                  
            if ((proxyName!= null) && (proxyName.length() > 0)) {
                try {
                    InetAddress.getByName(proxyName);
                } catch (Exception e) {
                    errors.add("proxyName", new 
ActionError("error.proxyName.invalid"));
                }
            }      
            numberCheck("proxyPortText",  proxyPortText, true, 0, 65535);      
        }
        
        return errors;
    }
    
    /*
     * Helper method to check that it is a reuired number and
     * is a valid integer within the given range. (min, max).
     *
     * @param  field  The field name in the form for which this error occured.
     * @param  numText  The string representation of the number.
     * @param rangeCheck  Boolean value set to true of reange check should be 
performed.
     *
     * @param  min  The lower limit of the range
     * @param  max  The upper limit of the range
     *
     */
    
    private void numberCheck(String field, String numText, boolean rangeCheck,
    int min, int max) {
        
        /* Check for 'is required' */
        if ((numText == null) || (numText.length() < 1)) {
            errors.add(field, new ActionError("error."+field+".required"));
        } else {
            
        /*check for 'must be a number' in the 'valid range'*/
            try {
                int num = Integer.parseInt(numText);
                // perform range check only if required
                if (rangeCheck) {
                    if ((num < min) || (num > max ))
                        errors.add( field,
                        new ActionError("error."+ field +".range"));
                }
            } catch (NumberFormatException e) {
                errors.add(field,
                new ActionError("error."+ field + ".format"));
            }
        }
    }
    
}
/*
 * $Header:  Exp $
 * $Revision:  $
 * $Date: $
 *
 * ====================================================================
 *
 * 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 connectorS; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 *
 */


package org.apache.webapp.admin;


import java.io.IOException;
import java.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 javax.management.JMException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanInfo;

import javax.management.modelmbean.ModelMBean;
import javax.management.modelmbean.ModelMBeanInfo;

import org.apache.struts.util.MessageResources;

/**
 * Test <code>Action</code> that handles events from the tree control when
 * a connector is chosen.
 *
 * @author Manveen Kaur
 * @version $Revision: $ $Date: $
 */

public class SetUpConnectorAction extends Action {
    
    private static MBeanServer mBServer = null;
    
    public final static String SCHEME_PROP_NAME = "scheme";
    
    public final static String ACCEPT_COUNT_PROP_NAME = "acceptCount";
    public final static String CONN_TO_PROP_NAME = "connectionTimeout";
    public final static String DEBUG_PROP_NAME = "debug";
    public final static String BUFF_SIZE_PROP_NAME = "bufferSize";
    public final static String ENABLE_LOOKUPS_PROP_NAME = "enableLookups";
    public final static String ADDRESS_PROP_NAME = "address";
    
    public final static String PORT_PROP_NAME = "port";
    public final static String REDIRECT_PORT_PROP_NAME = "redirectPort";
    
    public final static String PROC_MIN_PROP_NAME = "minProcessors";
    public final static String PROC_MAX_PROP_NAME = "maxProcessors";
    
    public final static String PROXY_NAME_PROP_NAME = "proxyName";
    public final static String PROXY_PORT_PROP_NAME = "proxyPort";
    
    private ArrayList debugLvlList = 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();
        
        if (form == null) {
            getServlet().log(" Creating new ConnectorForm bean under key "
            + mapping.getAttribute());
            form = new ConnectorForm();
            
            if ("request".equals(mapping.getScope()))
                request.setAttribute(mapping.getAttribute(), form);
            else
                session.setAttribute(mapping.getAttribute(), form);
            
        }
        
        String selectedName = request.getParameter("select");
        
        ConnectorForm connectorFm = (ConnectorForm) 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 enableLookups */
        if(booleanList == null) {
            booleanList = new ArrayList();
            booleanList.add(new LabelValueBean("True", "true"));
            booleanList.add(new LabelValueBean("False", "false"));
        }
        
        String connectorName = null;
        String scheme = null;
        Integer debug = null;
        String acceptCountText = null;
        Integer connTimeOut = null;
        Integer bufferSize = null;
        String address = null;
        Boolean enableLookups = null;
        
        String portText = null;
        String redirectPortText = null;
        
        Integer maxProcessors = null;
        Integer minProcessors = null;
        
        String proxyName = null;
        String proxyPortText = null;
        
        try{
            
            if(mBServer == null) {
                ApplicationServlet servlet = (ApplicationServlet)getServlet();
                mBServer = servlet.getServer();
            }
            
            Iterator connectorItr =
            mBServer.queryMBeans(new
            ObjectName(selectedName), null).iterator();
            
            ObjectInstance objInstance = (ObjectInstance)connectorItr.next();
            ObjectName connectorObjName = (objInstance).getObjectName();
            
            /*
            ModelMBeanInfo info = (ModelMBeanInfo) 
mBServer.getMBeanInfo(connectorObjName);
            MBeanAttributeInfo attrs[] = info.getAttributes();
            for (int i = 0; i < attrs.length; i++)
                System.out.println("  AttributeInfo=" + attrs[i]);
            
            MBeanOperationInfo opers[] = info.getOperations();
            for (int i = 0; i < opers.length; i++)
                System.out.println("  Operation=" + opers[i]);
            */
            
            // Extracting the attribute values for the Connector from the MBean
            scheme = (String) mBServer.getAttribute(connectorObjName,
            SCHEME_PROP_NAME);
            
            Integer acceptCount = (Integer) mBServer.getAttribute(connectorObjName,
            ACCEPT_COUNT_PROP_NAME);
            acceptCountText = acceptCount.toString();
            
            connTimeOut = (Integer) mBServer.getAttribute(connectorObjName,
            CONN_TO_PROP_NAME);

            debug = (Integer) mBServer.getAttribute(connectorObjName,
            DEBUG_PROP_NAME);
            
            bufferSize = (Integer) mBServer.getAttribute(connectorObjName,
            BUFF_SIZE_PROP_NAME);
            
            address = (String) mBServer.getAttribute(connectorObjName,
            ADDRESS_PROP_NAME);
            
            enableLookups = (Boolean) mBServer.getAttribute(connectorObjName,
            ENABLE_LOOKUPS_PROP_NAME);
            
            Integer port = (Integer) mBServer.getAttribute(connectorObjName,
            PORT_PROP_NAME);
            if (port != null) portText = port.toString();
            
            Integer redirectPort = (Integer) mBServer.getAttribute(connectorObjName,
            REDIRECT_PORT_PROP_NAME);
            redirectPortText = redirectPort.toString();
  
            minProcessors = (Integer) mBServer.getAttribute(connectorObjName,
            PROC_MIN_PROP_NAME);
            
            maxProcessors = (Integer) mBServer.getAttribute(connectorObjName,
            PROC_MAX_PROP_NAME);
            
            proxyName = (String) mBServer.getAttribute(connectorObjName,
            PROXY_NAME_PROP_NAME);
            
            Integer proxyPort = (Integer) mBServer.getAttribute(connectorObjName,
            PROXY_PORT_PROP_NAME);
            proxyPortText = proxyPort.toString();
            
        } catch(Throwable t){
            t.printStackTrace(System.out);
            //forward to error page
        }
        
        //setting values obtained from the mBean to be displayed in the form.
        connectorFm.setScheme(scheme);
        connectorFm.setAcceptCountText(acceptCountText);
        connectorFm.setConnTimeOutText(connTimeOut.toString());
        
        connectorFm.setDebugLvl(debug.toString());
        connectorFm.setDebugLvlVals(debugLvlList);
        
        connectorFm.setEnableLookups(enableLookups.toString());
        connectorFm.setBooleanVals(booleanList);
        
        connectorFm.setBufferSizeText(bufferSize.toString());
        connectorFm.setAddress(address);
        
        connectorFm.setMinProcessorsText(minProcessors.toString());
        connectorFm.setMaxProcessorsText(maxProcessors.toString());
        
        connectorFm.setPortText(portText);
        connectorFm.setRedirectPortText(redirectPortText);
        
        connectorFm.setProxyName(proxyName);
        connectorFm.setProxyPortText(proxyPortText);
        
        connectorFm.setConnectorName(selectedName);
        
        // Forward back to the test page
        return (mapping.findForward("Connector"));
    }
}

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

Reply via email to