manveen 02/02/14 12:37:22 Modified: webapps/admin server.jsp webapps/admin/WEB-INF struts-config.xml webapps/admin/WEB-INF/classes/org/apache/webapp/admin ServerAction.java SetUpServerAction.java webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host HostForm.java SetUpHostAction.java webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service DeleteServiceAction.java ServiceAction.java ServiceForm.java webapps/admin/service service.jsp Added: webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host DeleteHostAction.java DeleteHostForm.java SetUpDeleteHostAction.java webapps/admin/host deleteHost.jsp host.jsp Removed: webapps/admin host.jsp Log: * Added functionality to be able to list hosts and selectively delete Hosts from the admin tool. * Log appropriate error meeasges in case of problems getting/setting attributes on server mBean. Revision Changes Path 1.10 +2 -2 jakarta-tomcat-4.0/webapps/admin/server.jsp Index: server.jsp =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/server.jsp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- server.jsp 13 Feb 2002 00:03:32 -0000 1.9 +++ server.jsp 14 Feb 2002 20:37:21 -0000 1.10 @@ -39,7 +39,7 @@ </table> <%@ include file="buttons.jsp" %> -<br> + <br> <table class="back-table" border="0" cellspacing="0" cellpadding="1" width="100%"> <tr> @@ -64,7 +64,7 @@ <html:select property="debugLvl"> <bean:define id="debugLvlVals" name="serverForm" property="debugLvlVals"/> <html:options collection="debugLvlVals" property="value" - labelProperty="label"/> + labelProperty="label"/> </html:select> </controls:data> </controls:row> 1.31 +25 -2 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.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- struts-config.xml 13 Feb 2002 21:37:44 -0000 1.30 +++ struts-config.xml 14 Feb 2002 20:37:21 -0000 1.31 @@ -39,6 +39,10 @@ <form-bean name="hostForm" type="org.apache.webapp.admin.host.HostForm"/> + <!-- Delete Host form bean --> + <form-bean name="deleteHostForm" + type="org.apache.webapp.admin.host.DeleteHostForm"/> + <!-- Context form bean --> <form-bean name="contextForm" type="org.apache.webapp.admin.context.ContextForm"/> @@ -138,7 +142,11 @@ redirect="false"/> <forward name="Host" - path="/host.jsp" + path="/host/host.jsp" + redirect="false"/> + + <forward name="Delete Host" + path="/host/deleteHost.jsp" redirect="false"/> <forward name="Context" @@ -296,6 +304,13 @@ scope="session"> </action> + <!-- Set up delete Host datastructure --> + <action path="/setUpDeleteHost" + type="org.apache.webapp.admin.host.SetUpDeleteHostAction" + name="deleteHostForm" + scope="session"> + </action> + <!-- Set up Context datastructure --> <action path="/setUpContext" type="org.apache.webapp.admin.context.SetUpContextAction" @@ -375,7 +390,15 @@ type="org.apache.webapp.admin.host.HostAction" name="hostForm" scope="session" - input="/host.jsp"> + input="/host/host.jsp"> + </action> + + <!-- Process a delete host change --> + <action path="/deleteHost" + type="org.apache.webapp.admin.host.DeleteHostAction" + name="deleteHostForm" + scope="session" + input="/host/deleteHost.jsp"> </action> <!-- Process a context change --> 1.5 +5 -5 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ServerAction.java Index: ServerAction.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ServerAction.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ServerAction.java 13 Feb 2002 22:07:53 -0000 1.4 +++ ServerAction.java 14 Feb 2002 20:37:21 -0000 1.5 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ServerAction.java,v 1.4 2002/02/13 22:07:53 manveen Exp $ - * $Revision: 1.4 $ - * $Date: 2002/02/13 22:07:53 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ServerAction.java,v 1.5 2002/02/14 20:37:21 manveen Exp $ + * $Revision: 1.5 $ + * $Date: 2002/02/14 20:37:21 $ * * ==================================================================== * @@ -87,7 +87,7 @@ * * @author Jazmin Jonson * @author Manveen Kaur - * @version $Revision: 1.4 $ $Date: 2002/02/13 22:07:53 $ + * @version $Revision: 1.5 $ $Date: 2002/02/14 20:37:21 $ */ public final class ServerAction extends Action { @@ -156,7 +156,7 @@ } String attribute = null; - // read properties from the mBean + // write out attributes read from the form to the mBean try{ String shutdownText = request.getParameter("shutdownText"); String portNumberText = request.getParameter("portNumberText"); 1.9 +5 -4 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SetUpServerAction.java Index: SetUpServerAction.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SetUpServerAction.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- SetUpServerAction.java 13 Feb 2002 22:07:53 -0000 1.8 +++ SetUpServerAction.java 14 Feb 2002 20:37:21 -0000 1.9 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SetUpServerAction.java,v 1.8 2002/02/13 22:07:53 manveen Exp $ - * $Revision: 1.8 $ - * $Date: 2002/02/13 22:07:53 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SetUpServerAction.java,v 1.9 2002/02/14 20:37:21 manveen Exp $ + * $Revision: 1.9 $ + * $Date: 2002/02/14 20:37:21 $ * * ==================================================================== * @@ -98,7 +98,7 @@ * * @author Jazmin Jonson * @author Manveen Kaur - * @version $Revision: 1.8 $ $Date: 2002/02/13 22:07:53 $ + * @version $Revision: 1.9 $ $Date: 2002/02/14 20:37:21 $ */ public class SetUpServerAction extends Action { @@ -200,6 +200,7 @@ } String attribute = null; + // read attributes from the server mBean to display them on the form. try { portNumb = (Integer)mBServer.getAttribute(serverObjName, attribute=PORT_PROP_NAME); 1.2 +5 -5 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/HostForm.java Index: HostForm.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/HostForm.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- HostForm.java 13 Feb 2002 21:37:44 -0000 1.1 +++ HostForm.java 14 Feb 2002 20:37:21 -0000 1.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/HostForm.java,v 1.1 2002/02/13 21:37:44 manveen Exp $ - * $Revision: 1.1 $ - * $Date: 2002/02/13 21:37:44 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/HostForm.java,v 1.2 2002/02/14 20:37:21 manveen Exp $ + * $Revision: 1.2 $ + * $Date: 2002/02/14 20:37:21 $ * * ==================================================================== * @@ -67,14 +67,13 @@ import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; -import java.net.InetAddress; import java.util.ArrayList; /** * Form bean for the host page. * * @author Manveen Kaur - * @version $Revision: 1.1 $ $Date: 2002/02/13 21:37:44 $ + * @version $Revision: 1.2 $ $Date: 2002/02/14 20:37:21 $ */ public final class HostForm extends ActionForm { @@ -82,7 +81,8 @@ // ----------------------------------------------------- Instance Variables /** - * The text for the node label. + * The text for the node label. This is of the form 'Host(name)' + * and is picked up from the node of the tree that is clicked on. */ private String nodeLabel = null; 1.2 +8 -3 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/SetUpHostAction.java Index: SetUpHostAction.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/SetUpHostAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SetUpHostAction.java 13 Feb 2002 21:37:44 -0000 1.1 +++ SetUpHostAction.java 14 Feb 2002 20:37:21 -0000 1.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/SetUpHostAction.java,v 1.1 2002/02/13 21:37:44 manveen Exp $ - * $Revision: 1.1 $ - * $Date: 2002/02/13 21:37:44 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/SetUpHostAction.java,v 1.2 2002/02/14 20:37:21 manveen Exp $ + * $Revision: 1.2 $ + * $Date: 2002/02/14 20:37:21 $ * * ==================================================================== * @@ -94,7 +94,7 @@ * Test <code>Action</code> that handles events from the tree control test * page when a node linking to a host is selected. * @author Manveen Kaur - * @version $Revision: 1.1 $ $Date: 2002/02/13 21:37:44 $ + * @version $Revision: 1.2 $ $Date: 2002/02/14 20:37:21 $ */ public class SetUpHostAction extends Action { @@ -212,6 +212,11 @@ name = (String)mBServer.getAttribute(hostObjName, attribute=NAME_PROP_NAME); + + // FIX-ME + // nodelabel might be null in case of returning from delete screen + if (nodeLabel == null) + nodeLabel = "Host (" + name + ")"; appBase = (String)mBServer.getAttribute(hostObjName, attribute=APPBASE_PROP_NAME); 1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/DeleteHostAction.java Index: DeleteHostAction.java =================================================================== /* * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/DeleteHostAction.java,v 1.1 2002/02/14 20:37:21 manveen Exp $ * $Revision: 1.1 $ * $Date: 2002/02/14 20:37:21 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.webapp.admin.host; import java.io.IOException; import java.util.Iterator; import java.util.Locale; import java.util.TreeSet; import javax.management.MBeanServer; import javax.management.ObjectName; import javax.management.ObjectInstance; 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.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import javax.management.QueryExp; import org.apache.struts.util.MessageResources; import org.apache.webapp.admin.ApplicationServlet; import org.apache.webapp.admin.TomcatTreeBuilder; /** * Delete hosts that are selected to be deleted. * * @author Manveen Kaur * @version $Revision: 1.1 $ $Date: 2002/02/14 20:37:21 $ */ public class DeleteHostAction extends Action { /** * The MBeanServer we will be interacting with. */ private MBeanServer mBServer = null; /** * The MessageResources we will be retrieving messages from. */ private MessageResources resources = null; /* * Remove operation. */ private String REMOVE_OP = "removeHost"; // --------------------------------------------------------- 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); try { mBServer = ((ApplicationServlet) getServlet()).getServer(); } catch (Throwable t) { throw new ServletException ("Cannot acquire MBeanServer reference", t); } // Get the parent engine name String serviceName = request.getParameter("serviceName"); ObjectName engine = null; // retrieve the parent engine bean String enginePattern = TomcatTreeBuilder.ENGINE_TYPE + ",service=" + serviceName; try { Iterator engineItr = mBServer.queryMBeans(new ObjectName( enginePattern), null).iterator(); ObjectInstance objInstance = (ObjectInstance)engineItr.next(); engine = (objInstance).getObjectName(); } catch (Exception e) { throw new ServletException("Error getting parent engine Bean(" + enginePattern + ")", e); } // selected services to be deleted String[] selected = request.getParameterValues("checkbox"); // process delete action if (selected != null) { for (int index=0; index <selected.length; index++) { String pattern = selected[index]; Iterator names = null; try { names = mBServer.queryNames(new ObjectName(pattern), null).iterator(); } catch (Exception e) { throw new ServletException("queryNames(" + pattern + ")", e); } while (names.hasNext()) { try { ObjectName oName = (ObjectName) names.next(); // remove this host Object[] param = new Object[1]; param[0] = new String(oName.toString()); String[] type = new String[1]; type[0]= "java.lang.String"; mBServer.invoke(engine, REMOVE_OP , param, type); } catch (Exception e) { getServlet().log (resources.getMessage(locale, "users.error.invoke", REMOVE_OP), e); response.sendError (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, resources.getMessage(locale, "users.error.invoke", REMOVE_OP)); return (null); } } } } //Fix me -- need to refresh the tree? return (mapping.findForward("Save Successful")); } } 1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/DeleteHostForm.java Index: DeleteHostForm.java =================================================================== /* * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/DeleteHostForm.java,v 1.1 2002/02/14 20:37:21 manveen Exp $ * $Revision: 1.1 $ * $Date: 2002/02/14 20:37:21 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 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 javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; /** * Form bean for the "Delete Host" page. * * @author Manveen Kaur * @version $Revision: 1.1 $ $Date: 2002/02/14 20:37:21 $ */ public class DeleteHostForm extends ActionForm { // ----------------------------------------------------- Instance Variables /** * The text for the serviceName. */ private String serviceName = null; /** * Return the Service Name. */ public String getServiceName() { return this.serviceName; } /** * Set the Service Name. */ public void setServiceName(String serviceName) { this.serviceName = serviceName; } // --------------------------------------------------------- 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.serviceName = null; } } 1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/host/SetUpDeleteHostAction.java Index: SetUpDeleteHostAction.java =================================================================== /* * $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 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.webapp.admin.host; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.TreeSet; import java.util.StringTokenizer; import java.util.Set; 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.QueryExp; import javax.management.ObjectInstance; import javax.management.ObjectName; import org.apache.struts.util.MessageResources; import org.apache.webapp.admin.ApplicationServlet; import org.apache.webapp.admin.TomcatTreeBuilder; /** * Test <code>Action</code> that handles events to delete hosts. * * @author Manveen Kaur * @version $Revision: 1.1 $ $Date: 2002/02/14 20:37:21 $ */ public class SetUpDeleteHostAction 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 { HttpSession session = request.getSession(); if (form == null) { getServlet().log(" Creating new DeleteHostForm bean under key " + mapping.getAttribute()); form = new DeleteHostForm(); } if ("request".equals(mapping.getScope())) request.setAttribute(mapping.getAttribute(), form); else session.setAttribute(mapping.getAttribute(), form); // Acquire a reference to the MBeanServer containing our MBeans try { mBServer = ((ApplicationServlet) getServlet()).getServer(); } catch (Throwable t) { throw new ServletException ("Cannot acquire MBeanServer reference", t); } // get the parent engine name to get the parent Engine mBean // on which the removeHost operation will be invoked. String serviceName = request.getParameter("serviceName");; String deleteThis = request.getParameter("this"); // get the service name from the host mBean if (serviceName == null) { StringTokenizer st = new StringTokenizer(deleteThis, "="); while (st.hasMoreTokens()) { serviceName = st.nextToken().trim(); } } DeleteHostForm deleteForm = (DeleteHostForm) form; String pattern = null; if (deleteThis != null) { // this particular host is to be deleted. pattern = deleteThis ; } else { // Acquire the entire set of host MBean names to be listed pattern = TomcatTreeBuilder.HOST_TYPE + TomcatTreeBuilder.WILDCARD + ",service=" + serviceName; } Set results = null; try { results = mBServer.queryNames(new ObjectName(pattern), null); } catch (Throwable t) { throw new ServletException("queryNames(" + pattern + ")", t); } TreeSet hosts = new TreeSet(); Iterator names = results.iterator(); while (names.hasNext()) { ObjectName name = (ObjectName) names.next(); hosts.add(name); } // Forward the Set as a request attribute request.setAttribute("hosts", hosts); deleteForm.setServiceName(serviceName); return (mapping.findForward("Delete Host")); } } 1.4 +35 -9 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/DeleteServiceAction.java Index: DeleteServiceAction.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/DeleteServiceAction.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- DeleteServiceAction.java 13 Feb 2002 00:13:11 -0000 1.3 +++ DeleteServiceAction.java 14 Feb 2002 20:37:21 -0000 1.4 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/DeleteServiceAction.java,v 1.3 2002/02/13 00:13:11 manveen Exp $ - * $Revision: 1.3 $ - * $Date: 2002/02/13 00:13:11 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/DeleteServiceAction.java,v 1.4 2002/02/14 20:37:21 manveen Exp $ + * $Revision: 1.4 $ + * $Date: 2002/02/14 20:37:21 $ * * ==================================================================== * @@ -65,6 +65,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; +import java.util.Locale; import java.util.Set; import java.util.TreeSet; import javax.management.MBeanServer; @@ -72,6 +73,7 @@ import javax.management.ObjectInstance; import javax.management.modelmbean.ModelMBean; 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; @@ -79,6 +81,7 @@ import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import javax.management.QueryExp; +import org.apache.struts.util.MessageResources; import org.apache.webapp.admin.ApplicationServlet; import org.apache.webapp.admin.TomcatTreeBuilder; @@ -88,11 +91,19 @@ * Also, deregister their mBeans from the mBeanServer. * * @author Manveen Kaur - * @version $Revision: 1.3 $ $Date: 2002/02/13 00:13:11 $ + * @version $Revision: 1.4 $ $Date: 2002/02/14 20:37:21 $ */ public class DeleteServiceAction extends Action { - + /** + * The MessageResources we will be retrieving messages from. + */ + private MessageResources resources = null; + + /** + * The MBeanServer we will be interacting with. + */ + private MBeanServer mBServer = null; // --------------------------------------------------------- Public Methods @@ -119,8 +130,16 @@ throws IOException, ServletException { - // Acquire a reference to the MBeanServer containing our MBeans - MBeanServer mBServer = null; + // 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); + try { mBServer = ((ApplicationServlet) getServlet()).getServer(); } catch (Throwable t) { @@ -165,8 +184,15 @@ mBServer.invoke(server, "removeService", serviceParam, type); - } catch (Throwable t) { - throw new ServletException("Exception while removing service", t); + } catch (Exception e) { + getServlet().log + (resources.getMessage(locale, "users.error.invoke", + "removeService"), e); + response.sendError + (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, + resources.getMessage(locale, "users.error.invoke", + "removeService")); + return (null); } } } 1.2 +58 -38 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/ServiceAction.java Index: ServiceAction.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/ServiceAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ServiceAction.java 31 Jan 2002 19:35:58 -0000 1.1 +++ ServiceAction.java 14 Feb 2002 20:37:21 -0000 1.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/ServiceAction.java,v 1.1 2002/01/31 19:35:58 manveen Exp $ - * $Revision: 1.1 $ - * $Date: 2002/01/31 19:35:58 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/ServiceAction.java,v 1.2 2002/02/14 20:37:21 manveen Exp $ + * $Revision: 1.2 $ + * $Date: 2002/02/14 20:37:21 $ * * ==================================================================== * @@ -62,6 +62,7 @@ package org.apache.webapp.admin.service; import java.util.Iterator; +import java.util.Locale; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -89,13 +90,19 @@ * actions on a Service. * * @author Manveen Kaur - * @version $Revision: 1.1 $ $Date: 2002/01/31 19:35:58 $ + * @version $Revision: 1.2 $ $Date: 2002/02/14 20:37:21 $ */ public final class ServiceAction extends Action { - + /** + * The MBeanServer we will be interacting with. + */ private static MBeanServer mBServer = null; + /** + * The MessageResources we will be retrieving messages from. + */ + private MessageResources resources = null; // --------------------------------------------------------- Public Methods @@ -120,37 +127,45 @@ HttpServletResponse response) throws IOException, ServletException { - try{ - - // front end validation and checking. - // =================================================== - MessageResources messages = getResources(); - - // 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(); - } - - String serviceName = request.getParameter("serviceName"); - + if (resources == null) { + resources = getServlet().getResources(); + } + Locale locale = (Locale)request.getSession().getAttribute(Action.LOCALE_KEY); + + ActionErrors errors = new ActionErrors(); + + // Report any errors we have discovered back to the original form + if (!errors.empty()) { + saveErrors(request, errors); + return (new ActionForward(mapping.getInput())); + } + + // Acquire a reference to the MBeanServer containing our MBeans + try { + mBServer = ((ApplicationServlet) getServlet()).getServer(); + } catch (Throwable t) { + throw new ServletException + ("Cannot acquire MBeanServer reference", t); + } + + String serviceName = request.getParameter("serviceName"); + ObjectName serviceObjName = null; + try { Iterator serviceItr = mBServer.queryMBeans(new ObjectName( TomcatTreeBuilder.ENGINE_TYPE + ",service=" + serviceName), null).iterator(); - ObjectName serviceObjName = + serviceObjName = ((ObjectInstance)serviceItr.next()).getObjectName(); - + } catch (Throwable t) { + throw new ServletException + ("Cannot acquire MBean reference " + serviceName, t); + } + + String attribute = null; + try { String engineName = request.getParameter("engineName"); String debugLvlText = request.getParameter("debugLvl"); String defaultHost = request.getParameter("defaultHost"); @@ -158,14 +173,14 @@ if (engineName != null) { mBServer.setAttribute(serviceObjName, - new Attribute(SetUpServiceAction.NAME_PROP_NAME, + new Attribute(attribute=SetUpServiceAction.NAME_PROP_NAME, engineName)); } if(debugLvlText != null) { Integer debugLvl = new Integer(debugLvlText); mBServer.setAttribute(serviceObjName, - new Attribute(SetUpServiceAction.DEBUG_PROP_NAME, + new Attribute(attribute=SetUpServiceAction.DEBUG_PROP_NAME, debugLvl)); } @@ -179,14 +194,19 @@ } */ mBServer.setAttribute(serviceObjName, - new Attribute(SetUpServiceAction.HOST_PROP_NAME, - defaultHost)); - + new Attribute(attribute=SetUpServiceAction.HOST_PROP_NAME, + defaultHost)); + } - - }catch(Throwable t){ - t.printStackTrace(System.out); - //forward to error page + }catch(Exception e){ + getServlet().log + (resources.getMessage(locale, "users.error.attribute.set", + attribute), e); + response.sendError + (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, + resources.getMessage(locale, "users.error.attribute.set", + attribute)); + return (null); } if (servlet.getDebug() >= 1) 1.2 +4 -6 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/ServiceForm.java Index: ServiceForm.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/ServiceForm.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ServiceForm.java 31 Jan 2002 19:35:58 -0000 1.1 +++ ServiceForm.java 14 Feb 2002 20:37:21 -0000 1.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/ServiceForm.java,v 1.1 2002/01/31 19:35:58 manveen Exp $ - * $Revision: 1.1 $ - * $Date: 2002/01/31 19:35:58 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/service/ServiceForm.java,v 1.2 2002/02/14 20:37:21 manveen Exp $ + * $Revision: 1.2 $ + * $Date: 2002/02/14 20:37:21 $ * * ==================================================================== * @@ -73,7 +73,7 @@ * Form bean for the service page. * * @author Manveen Kaur - * @version $Revision: 1.1 $ $Date: 2002/01/31 19:35:58 $ + * @version $Revision: 1.2 $ $Date: 2002/02/14 20:37:21 $ */ public final class ServiceForm extends ActionForm { @@ -254,8 +254,6 @@ this.engineName = null; this.debugLvl = "0"; this.defaultHost = " "; - //this.debugLvlVals = null; - //this.hostNameVals = null; } /** 1.1 jakarta-tomcat-4.0/webapps/admin/host/deleteHost.jsp Index: deleteHost.jsp =================================================================== <!-- Standard Struts Entries --> <%@ page language="java" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> <%@ 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="/deleteHost"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr bgcolor="7171A5"> <td width="81%"> <div class="page-title-text" align="left"> <html:hidden property="serviceName"/> <bean:message key="actions.host.delete"/> </div> </td> <td width="19%"> <div align="right"> <controls:actions> <controls:action selected="true"> ----<bean:message key="actions.available.actions"/>---- </controls:action> <controls:action> --------------------------------- </controls:action> </controls:actions> </div> </td> </tr> </table> <%@ include file="../buttons.jsp" %> <br> <%-- Hosts List --%> <table class="back-table" border="0" cellspacing="0" cellpadding="1" width="100%"> <tr> <td> <table class="front-table" border="1" cellspacing="0" cellpadding="0" width="100%"> <tr class="header-row"> <td><div align="left" class="table-header-text"> <bean:message key="actions.delete"/> </div></td> <td><div align="left" class="table-header-text"> <bean:message key="host.name"/> </div></td> </tr> <logic:iterate name="hosts" id="host"> <tr class="line-row"> <td><div align="left" class="table-normal-text"> <input type="checkbox" name="checkbox" value='<%= host.toString() %>' > </div></td> <td><div align="left" class="table-normal-text"> <html:link page='<%= "/setUpHost.do?select=" + java.net.URLEncoder.encode(host.toString())%>'> <controls:attribute name="host" attribute="name"/> </html:link> </div></td> </tr> </logic:iterate> </table> </td> </tr> </table> <%@ include file="../buttons.jsp" %> <br> </html:form> <p> </p> </body> </html:html> 1.1 jakarta-tomcat-4.0/webapps/admin/host/host.jsp Index: host.jsp =================================================================== <!-- Standard Struts Entries --> <%@ page language="java" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> <%@ 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="/host" focus="name"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr class="page-title-row"> <td align="left" nowrap> <div class="page-title-text"> <bean:write name="hostForm" property="nodeLabel" scope="session"/> <bean:define id="hostName" name="hostForm" property="hostName"/> </div> </td> <td align="right" nowrap> <div align="right"> <controls:actions> <controls:action selected="true"> -----<bean:message key="actions.available.actions"/>----- </controls:action> <controls:action> ------------------------------------- </controls:action> <%-- <controls:action url=""> <bean:message key="actions.accesslogger.create"/> </controls:action> <controls:action url=""> <bean:message key="actions.accesslogger.delete"/> </controls:action> <controls:action> ------------------------------------- </controls:action> <controls:action url=""> <bean:message key="actions.alias.create"/> </controls:action> <controls:action url=""> <bean:message key="actions.alias.delete"/> </controls:action> <controls:action> ------------------------------------- </controls:action> <controls:action url=""> <bean:message key="actions.logger.create"/> </controls:action> <controls:action url=""> <bean:message key="actions.logger.delete"/> </controls:action> <controls:action> ------------------------------------- </controls:action> <controls:action url=""> <bean:message key="actions.requestfilter.create"/> </controls:action> <controls:action url=""> <bean:message key="actions.requestfilter.delete"/> </controls:action> <controls:action> ------------------------------------- </controls:action> <controls:action url=""> <bean:message key="actions.userrealm.create"/> </controls:action> <controls:action url=""> <bean:message key="actions.userrealm.delete"/> </controls:action> <controls:action> ------------------------------------- </controls:action> <controls:action url=""> <bean:message key="actions.valve.create"/> </controls:action> <controls:action url=""> <bean:message key="actions.valve.delete"/> </controls:action> <controls:action> ------------------------------------- </controls:action> --%> <controls:action url='<%= "/setUpDeleteHost.do?this=" + java.net.URLEncoder.encode(hostName.toString()) %>'> <bean:message key="actions.thishost.delete"/> </controls:action> </controls:actions> </div> </td> </tr> </table> <%@ include file="../buttons.jsp" %> <br> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr> <td> <div class="table-title-text"> <bean:message key="host.properties"/> <html:hidden property="hostName"/> </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="hostForm" 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="hostForm" property="booleanVals"/> <html:options collection="booleanVals" property="value" labelProperty="label"/> </html:select> </controls:data> </controls:row> </controls:table> </td> </tr> </table> <br> <br> <!-- Aliases --> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr> <td> <div class="table-title-text"> <bean:message key="host.aliases"/> </div> </td> </tr> </table> <table class="back-table" border="0" cellspacing="0" cellpadding="1" width="100%"> <tr> <td> <table class="front-table" border="1" cellspacing="0" cellpadding="0" width="100%"> <tr class="header-row"> <td width="27%"> <div class="table-header-text" align="left"><bean:message key="host.alias.name"/> </div> </td> </tr> <logic:iterate id="aliasVal" name="hostForm" property="aliasVals"> <tr> <td width="27%" valign="top" colspan=2> <div class="table-normal-text"> <%= aliasVal %> </div> </td> </tr> </logic:iterate> </table> </td> </tr> </table> <!-- Alias table end --> <%@ include file="../buttons.jsp" %> </html:form> </body> </html:html> 1.2 +6 -2 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.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- service.jsp 13 Feb 2002 00:04:29 -0000 1.1 +++ service.jsp 14 Feb 2002 20:37:22 -0000 1.2 @@ -39,8 +39,12 @@ <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=""> <bean:message key="actions.host.delete"/> </controls:action> - <controls:action> ------------------------------------- </controls:action> + --%> + <controls:action url='<%= "/setUpDeleteHost.do?serviceName=" + serviceName %>'> + <bean:message key="actions.host.delete"/> + </controls:action> + <controls:action> ------------------------------------- </controls:action> + <%-- <controls:action url=""> <bean:message key="actions.logger.create"/> </controls:action> <controls:action url=""> <bean:message key="actions.logger.delete"/> </controls:action> <controls:action> ------------------------------------- </controls:action>
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>