manveen 02/02/08 13:33:02 Added: webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm MemoryRealmAction.java MemoryRealmForm.java SetUpMemoryRealmAction.java Log: Added functionality to be able to view and edit memory realm properties from the admin tool. Revision Changes Path 1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/MemoryRealmAction.java Index: MemoryRealmAction.java =================================================================== /* * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/MemoryRealmAction.java,v 1.1 2002/02/08 21:33:02 manveen Exp $ * $Revision: 1.1 $ * $Date: 2002/02/08 21:33:02 $ * * ==================================================================== * * 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.realm; 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 org.apache.struts.util.MessageResources; import org.apache.webapp.admin.ApplicationServlet; import org.apache.webapp.admin.LabelValueBean; /** * Implementation of <strong>Action</strong> that validates * actions on a Memory Realm. * * @author Manveen Kaur * @version $Revision: 1.1 $ $Date: 2002/02/08 21:33:02 $ */ public final class MemoryRealmAction 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); System.out.println("forward is to " + mapping.getInput()); return (new ActionForward(mapping.getInput())); } if(mBServer == null) { ApplicationServlet servlet = (ApplicationServlet)getServlet(); mBServer = servlet.getServer(); } /** * Get the realm Name from the form. * This is used to lookup the MBeanServer and * retrieve this realm's MBean. */ String realmName = request.getParameter("realmName"); Iterator realmItr = mBServer.queryMBeans(new ObjectName(realmName), null).iterator(); ObjectInstance objInstance = (ObjectInstance)realmItr.next(); ObjectName realmObjName = (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(realmObjName, new Attribute(SetUpMemoryRealmAction.DEBUG_PROP_NAME, debugLvl)); } String pathName = request.getParameter("pathName"); if(pathName != null) { mBServer.setAttribute(realmObjName, new Attribute(SetUpMemoryRealmAction.PATH_NAME_PROP_NAME, pathName)); } }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")); } } 1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/MemoryRealmForm.java Index: MemoryRealmForm.java =================================================================== /* * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/MemoryRealmForm.java,v 1.1 2002/02/08 21:33:02 manveen Exp $ * $Revision: 1.1 $ * $Date: 2002/02/08 21:33:02 $ * * ==================================================================== * * 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.realm; 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; import java.util.Enumeration; import org.apache.webapp.admin.ApplicationServlet; import org.apache.webapp.admin.LabelValueBean; /** * Form bean for the memory realm page. * * @author Manveen Kaur * @version $Revision: 1.1 $ $Date: 2002/02/08 21:33:02 $ */ public final class MemoryRealmForm extends ActionForm { // ----------------------------------------------------- Instance Variables /** * The text for the debug level. */ private String debugLvl = "0"; /** * The text for the realm name, used to retrieve * the corresponding realm mBean. */ private String realmName = null; /** * The text for the realm type. * Specifies if it is a JNDI, JDBC, UserDatabase or MemoryRealm. */ private String realmType = null; /** * Set of valid values for debug level. */ private ArrayList debugLvlVals = null; /** * The text for the path Name. */ private String pathName = null; /** * The text for the node label. */ private String nodeLabel = null; // ------------------------------------------------------------- Properties /** * Return the Realm Name. */ public String getRealmName() { return this.realmName; } /** * Set the Realm Name. */ public void setRealmName(String realmName) { this.realmName = realmName; } /** * Return the Realm type. */ public String getRealmType() { return this.realmType; } /** * Set the Realm type. */ public void setRealmType(String realmType) { this.realmType = realmType; } /** * 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 path Name. */ public String getPathName() { return this.pathName; } /** * Set the path Name. */ public void setPathName(String pathName) { this.pathName = pathName; } /** * Return the label of the node that was clicked. */ public String getNodeLabel() { return this.nodeLabel; } /** * Set the node label. */ public void setNodeLabel(String nodeLabel) { this.nodeLabel = nodeLabel; } // --------------------------------------------------------- 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.debugLvl = "0"; this.pathName = 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 */ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); String submit = request.getParameter("submit"); // front end validation when save is clicked. if (submit != null) { //pathName cannot be null if ((pathName == null) || (pathName.length()<1)) { errors.add("pathName", new ActionError("error.pathName.required")); } } return errors; } } 1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/SetUpMemoryRealmAction.java Index: SetUpMemoryRealmAction.java =================================================================== /* * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/SetUpMemoryRealmAction.java,v 1.1 2002/02/08 21:33:02 manveen Exp $ * $Revision: 1.1 $ * $Date: 2002/02/08 21:33:02 $ * * ==================================================================== * * 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.realm; 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.ObjectInstance; import javax.management.ObjectName; //import javax.management.JMException; import org.apache.webapp.admin.ApplicationServlet; import org.apache.webapp.admin.LabelValueBean; import org.apache.struts.util.MessageResources; /** * Test <code>Action</code> that handles events from the tree control when * a Memory realm is chosen. * * @author Manveen Kaur * @version $Revision: 1.1 $ $Date: 2002/02/08 21:33:02 $ */ public class SetUpMemoryRealmAction extends Action { private static MBeanServer mBServer = null; public final static String DEBUG_PROP_NAME = "debug"; public final static String PATH_NAME_PROP_NAME = "pathname"; private ArrayList debugLvlList = 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 { // Acquire a reference to the MBeanServer containing our MBeans MBeanServer mBServer = null; try { mBServer = ((ApplicationServlet) getServlet()).getServer(); } catch (Throwable t) { throw new ServletException ("Cannot acquire MBeanServer reference", t); } String selectedName = request.getParameter("select"); String realmType = request.getParameter("type"); String nodeLabel = request.getParameter("nodeLabel"); MemoryRealmForm realmFm = (MemoryRealmForm) 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")); } String pathName = null; try{ Iterator realmItr = mBServer.queryMBeans(new ObjectName(selectedName), null).iterator(); ObjectInstance objInstance = (ObjectInstance)realmItr.next(); ObjectName realmObjName = (objInstance).getObjectName(); realmFm.setRealmName(selectedName); realmFm.setRealmType(realmType); realmFm.setNodeLabel(nodeLabel); realmFm.setDebugLvlVals(debugLvlList); realmFm.setDebugLvl( ((Integer) mBServer.getAttribute(realmObjName, DEBUG_PROP_NAME)).toString()); pathName = (String) mBServer.getAttribute(realmObjName, PATH_NAME_PROP_NAME); } catch(Throwable t){ throw new ServletException("Error in reading from mBean", t); } realmFm.setPathName(pathName); // Stash the form bean and forward to the display page request.setAttribute("memoryRealmForm", realmFm); // Forward back to the appropriate Realm page return (mapping.findForward("MemoryRealm")); } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>