ApplyCatalinaAccessLoggerAction.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * --------------------------------------------------------------------------
00022  * $Id: ApplyCatalinaAccessLoggerAction.java,v 1.6 2004/10/22 13:53:33 danesa Exp $
00023  * --------------------------------------------------------------------------
00024  */
00025 
00026 package org.objectweb.jonas.webapp.jonasadmin.logging;
00027 
00028 import java.io.IOException;
00029 
00030 import javax.management.ObjectName;
00031 import javax.servlet.ServletException;
00032 import javax.servlet.http.HttpServletRequest;
00033 import javax.servlet.http.HttpServletResponse;
00034 
00035 import org.apache.struts.action.ActionError;
00036 import org.apache.struts.action.ActionForm;
00037 import org.apache.struts.action.ActionForward;
00038 import org.apache.struts.action.ActionMapping;
00039 import org.objectweb.jonas.jmx.JonasManagementRepr;
00040 import org.objectweb.jonas.jmx.CatalinaObjectName;
00041 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminException;
00042 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
00043 
00047 public class ApplyCatalinaAccessLoggerAction extends BaseLoggerAction {
00048 
00052     private String sa_CreateAccessLogger[] = {
00053         "java.lang.String"
00054     };
00055 
00056     private static String sDefaultForward = "ActionEditWebAppCatalina";
00057 
00058 // --------------------------------------------------------- Protected Variables
00059 
00060 // --------------------------------------------------------- Public Methods
00061 
00062     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
00063         , HttpServletRequest p_Request, HttpServletResponse p_Response)
00064         throws IOException, ServletException {
00065 
00066         // Default forward
00067         ActionForward oForward = null;
00068 
00069         // Form used
00070         CatalinaAccessLogValveForm oForm = (CatalinaAccessLogValveForm) p_Form;
00071 
00072         // Populate
00073         try {
00074             // Perform a "Create WebApp" transaction (if requested)
00075             if ("create".equals(oForm.getAction()) == true) {
00076                 oForward = createAccessLogger(oForm, p_Mapping, p_Request);
00077             }
00078             // Save in memory the new datas
00079             else if ("edit".equals(oForm.getAction()) == true) {
00080                 oForward = populateMbean(oForm
00081                     , p_Mapping.findForward("ActionEditCatalinaAccessLogger"), p_Mapping, p_Request);
00082             }
00083         }
00084         catch (JonasAdminException e) {
00085             // Build error
00086             m_Errors.add("logger.catalina.access", new ActionError(e.getId()));
00087             saveErrors(p_Request, m_Errors);
00088             // Return to the current page
00089             oForward = new ActionForward(p_Mapping.getInput());
00090         }
00091         catch (Throwable t) {
00092             addGlobalError(t);
00093             saveErrors(p_Request, m_Errors);
00094             oForward = p_Mapping.findForward("Global Error");
00095         }
00096 
00097         // Next Forward
00098         return oForward;
00099     }
00100 
00109     protected ActionForward createAccessLogger(CatalinaAccessLogValveForm p_Form
00110         , ActionMapping p_Mapping, HttpServletRequest p_Request)
00111         throws Exception {
00112         Object values[] = null;
00113         // Look up the Catalina MBeanFactory
00114         ObjectName onFactory = CatalinaObjectName.catalinaFactory();
00115         // Create a new Access Logger Valve object
00116         values = new Object[1];
00117         // parent
00118         values[0] = CatalinaObjectName.catalinaHost(m_WhereAreYou.getCurrentCatalinaDomainName()
00119             , m_WhereAreYou.getCurrentCatalinaDefaultHostName()).toString();
00120         p_Form.setObjectName((String) JonasManagementRepr.invoke(onFactory
00121             , "createAccessLoggerValve", values, sa_CreateAccessLogger));
00122 
00123         // Populate
00124         ActionForward oForward = populateMbean(p_Form, p_Mapping.findForward("ActionListLoggers")
00125             , p_Mapping, p_Request);
00126 
00127         // refresh tree
00128         refreshTree(p_Request);
00129         // Force the node selected in tree
00130         m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR
00131             + "logging" + WhereAreYou.NODE_SEPARATOR + LoggerItem.LOGGER_CATALINA_ACCESS, true);
00132 
00133         // Return the next forward
00134         return oForward;
00135     }
00136 
00147     protected ActionForward populateMbean(CatalinaAccessLogValveForm p_Form
00148         , ActionForward p_Forward, ActionMapping p_Mapping, HttpServletRequest p_Request)
00149         throws Exception {
00150         ActionForward oForward = p_Forward;
00151         // Access logger
00152         ObjectName on = new ObjectName(p_Form.getObjectName());
00153         setStringAttribute(on, "directory", p_Form.getDirectory());
00154         setStringAttribute(on, "prefix", p_Form.getPrefix());
00155         setStringAttribute(on, "suffix", p_Form.getSuffix());
00156         setBooleanAttribute(on, "resolveHosts", p_Form.isResolveHosts());
00157         setBooleanAttribute(on, "rotatable", p_Form.isRotatable());
00158         setStringAttribute(on, "pattern", p_Form.getPattern());
00159         // Save in configuration file
00160         if (p_Form.isSave() == true) {
00161             //ObjectName onServer = CatalinaObjectName.catalinaServer();
00162             //JonasManagementRepr.invoke(onServer, "store", null, null);
00163             p_Form.setSave(false);
00164             p_Request.setAttribute("forward", p_Forward.getName());
00165             oForward = p_Mapping.findForward("ActionEditServletServer");
00166         }
00167         return oForward;
00168     }
00169 
00170 }

Generated on Tue Feb 15 15:05:28 2005 for JOnAS by  doxygen 1.3.9.1