001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2003-2005 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: EditCatalinaAccessLoggerAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.logging;
025:
026: import java.io.IOException;
027: import java.util.ArrayList;
028: import java.util.Iterator;
029:
030: import javax.management.ObjectName;
031: import javax.servlet.ServletException;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import org.apache.struts.action.ActionForm;
036: import org.apache.struts.action.ActionForward;
037: import org.apache.struts.action.ActionMapping;
038: import org.objectweb.jonas.jmx.CatalinaObjectName;
039: import org.objectweb.jonas.jmx.JonasManagementRepr;
040: import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
041: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
042: import org.objectweb.jonas.webapp.jonasadmin.service.container.WebAppItem;
043:
044: /**
045: * @author Michel-Ange ANTON
046: * @author Adriana Danes
047: */
048:
049: public class EditCatalinaAccessLoggerAction extends BaseLoggerAction {
050:
051: // --------------------------------------------------------- Public Methods
052:
053: public ActionForward executeAction(ActionMapping pMapping,
054: ActionForm pForm, HttpServletRequest pRequest,
055: HttpServletResponse pResponse) throws IOException,
056: ServletException {
057:
058: // Parameters
059: String sAction = pRequest.getParameter("action");
060: if (sAction == null) {
061: sAction = "edit";
062: }
063: String sObjectName = pRequest.getParameter("select");
064: // Form used
065: CatalinaAccessLogValveForm oForm = null;
066: if (("create".equals(sAction) == true) || (sObjectName != null)) {
067: oForm = new CatalinaAccessLogValveForm();
068: m_Session.setAttribute("catalinaAccessLoggerForm", oForm);
069: oForm.reset(pMapping, pRequest);
070: oForm.setObjectName(sObjectName);
071: } else {
072: oForm = (CatalinaAccessLogValveForm) m_Session
073: .getAttribute("catalinaAccessLoggerForm");
074: }
075: oForm.setAction(sAction);
076:
077: // Current JOnAS server
078: String serverName = m_WhereAreYou.getCurrentJonasServerName();
079:
080: // Polulate
081: try {
082: if (oForm.getObjectName() != null) {
083: // Get the access logger
084: ObjectName on = new ObjectName(oForm.getObjectName());
085: String loggerContainerType = null; // needed for mgmt tree node name
086: String loggerContainerName = null; // needed for mgmt tree node name
087: // Populate
088: oForm.setObjectName(on.toString());
089: oForm.setDirectory(getStringAttribute(on, "directory"));
090: oForm.setPattern(getStringAttribute(on, "pattern"));
091: oForm.setPrefix(getStringAttribute(on, "prefix"));
092: oForm.setResolveHosts(getBooleanAttribute(on,
093: "resolveHosts"));
094: oForm
095: .setRotatable(getBooleanAttribute(on,
096: "rotatable"));
097: oForm.setSuffix(getStringAttribute(on, "suffix"));
098: ObjectName onContainer = (ObjectName) JonasManagementRepr
099: .getAttribute(on, "containerName", serverName);
100: if (onContainer.getKeyProperty("j2eeType") != null) {
101: if (onContainer.getKeyProperty("j2eeType").equals(
102: "WebModule")) {
103: // The container is a Web application (Context element in Tomcat)
104: oForm
105: .setContainerType(m_Resources
106: .getMessage("label.loggers.container.context"));
107: String webContainerName = WebAppItem
108: .extractLabelPathContext(
109: onContainer
110: .getKeyProperty("name"),
111: m_WhereAreYou
112: .getCurrentCatalinaDefaultHostName());
113: oForm.setContainerName(webContainerName);
114: oForm.setContainerObjectName(onContainer
115: .toString());
116: loggerContainerType = LoggerItem.LOGGER_CATALINA_ACCESS_CONTEXT;
117: loggerContainerName = on.getKeyProperty("path");
118: }
119: } else if (onContainer.getKeyProperty("type") != null) {
120: if (onContainer.getKeyProperty("type").equals(
121: "Engine")) {
122: oForm
123: .setContainerType(m_Resources
124: .getMessage("label.loggers.container.engine"));
125: oForm
126: .setContainerName(m_Resources
127: .getMessage("label.loggers.container.engine.name"));
128: loggerContainerType = LoggerItem.LOGGER_CATALINA_ACCESS_ENGINE;
129: loggerContainerName = oForm.getContainerName();
130: } else if (onContainer.getKeyProperty("type")
131: .equals("Host")) {
132: oForm
133: .setContainerType(m_Resources
134: .getMessage("label.loggers.container.host"));
135: oForm.setContainerName(onContainer
136: .getKeyProperty("host"));
137: loggerContainerType = LoggerItem.LOGGER_CATALINA_ACCESS_HOST;
138: loggerContainerName = on.getKeyProperty("host");
139: }
140: }
141: // Force the node selected in tree
142: m_WhereAreYou.selectNameNode(
143: getTreeBranchName(DEPTH_SERVER)
144: + WhereAreYou.NODE_SEPARATOR
145: + "logging"
146: + WhereAreYou.NODE_SEPARATOR
147: + loggerContainerType
148: + WhereAreYou.NODE_SEPARATOR
149: + loggerContainerName, true);
150: } else {
151: oForm.setCatalinaDomainName(m_WhereAreYou
152: .getCurrentCatalinaDomainName());
153: ObjectName hostsOn = CatalinaObjectName
154: .catalinaHosts(m_WhereAreYou
155: .getCurrentCatalinaDomainName());
156: Iterator hosts = JonasAdminJmx.getListMbean(hostsOn,
157: serverName).iterator();
158: ArrayList hostNames = new ArrayList();
159: for (; hosts.hasNext();) {
160: hostNames.add(((ObjectName) hosts.next())
161: .getKeyProperty("host"));
162: }
163: String[] allNames = new String[hostNames.size() + 1];
164: allNames[0] = "no name required for Engine";
165: for (int i = 1; i < allNames.length; i++) {
166: allNames[i] = (String) hostNames.get(i - 1);
167: }
168: oForm.setContainerNames(allNames);
169: }
170: } catch (Throwable t) {
171: addGlobalError(t);
172: saveErrors(pRequest, m_Errors);
173: return (pMapping.findForward("Global Error"));
174: }
175: // Forward to the jsp.
176: return (pMapping.findForward("Catalina Access Logger"));
177: }
178:
179: }
|