1 25 26 package org.objectweb.jonas.webapp.jonasadmin.logging; 27 28 import java.io.IOException ; 29 import java.util.ArrayList ; 30 import java.util.Iterator ; 31 32 import javax.management.ObjectName ; 33 import javax.servlet.ServletException ; 34 import javax.servlet.http.HttpServletRequest ; 35 import javax.servlet.http.HttpServletResponse ; 36 37 import org.apache.struts.action.ActionForm; 38 import org.apache.struts.action.ActionForward; 39 import org.apache.struts.action.ActionMapping; 40 import org.objectweb.jonas.jmx.CatalinaObjectName; 41 import org.objectweb.jonas.jmx.JonasManagementRepr; 42 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx; 43 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou; 44 import org.objectweb.jonas.webapp.jonasadmin.service.container.WebAppItem; 45 46 50 51 public class EditCatalinaAccessLoggerAction extends BaseLoggerAction { 52 53 55 public ActionForward executeAction(ActionMapping pMapping, ActionForm pForm 56 , HttpServletRequest pRequest, HttpServletResponse pResponse) 57 throws IOException , ServletException { 58 59 String sAction = pRequest.getParameter("action"); 61 if (sAction == null) { 62 sAction = "edit"; 63 } 64 String sObjectName = pRequest.getParameter("select"); 65 CatalinaAccessLogValveForm oForm = null; 67 if (("create".equals(sAction) == true) || (sObjectName != null)) { 68 oForm = new CatalinaAccessLogValveForm(); 69 m_Session.setAttribute("catalinaAccessLoggerForm", oForm); 70 oForm.reset(pMapping, pRequest); 71 oForm.setObjectName(sObjectName); 72 } else { 73 oForm = (CatalinaAccessLogValveForm) m_Session.getAttribute("catalinaAccessLoggerForm"); 74 } 75 oForm.setAction(sAction); 76 try { 78 if (oForm.getObjectName() != null) { 79 ObjectName on = new ObjectName (oForm.getObjectName()); 81 String loggerContainerType = null; String loggerContainerName = null; oForm.setObjectName(on.toString()); 85 oForm.setDirectory(getStringAttribute(on, "directory")); 86 oForm.setPattern(getStringAttribute(on, "pattern")); 87 oForm.setPrefix(getStringAttribute(on, "prefix")); 88 oForm.setResolveHosts(getBooleanAttribute(on, "resolveHosts")); 89 oForm.setRotatable(getBooleanAttribute(on, "rotatable")); 90 oForm.setSuffix(getStringAttribute(on, "suffix")); 91 ObjectName onContainer = (ObjectName ) JonasManagementRepr.getAttribute(on, "containerName"); 92 if (onContainer.getKeyProperty("j2eeType") != null) { 93 if (onContainer.getKeyProperty("j2eeType").equals("WebModule")) { 94 oForm.setContainerType(m_Resources.getMessage("label.loggers.container.context")); 96 String webContainerName = WebAppItem.extractLabelPathContext(onContainer.getKeyProperty("name")); 97 oForm.setContainerName(webContainerName); 98 oForm.setContainerObjectName(onContainer.toString()); 99 loggerContainerType = LoggerItem.LOGGER_CATALINA_ACCESS_CONTEXT; 100 loggerContainerName = on.getKeyProperty("path"); 101 } 102 } else if (onContainer.getKeyProperty("type") != null) { 103 if (onContainer.getKeyProperty("type").equals("Engine")) { 104 oForm.setContainerType(m_Resources.getMessage("label.loggers.container.engine")); 105 oForm.setContainerName(m_Resources.getMessage("label.loggers.container.engine.name")); 106 loggerContainerType = LoggerItem.LOGGER_CATALINA_ACCESS_ENGINE; 107 loggerContainerName = oForm.getContainerName(); 108 } else if (onContainer.getKeyProperty("type").equals("Host")) { 109 oForm.setContainerType(m_Resources.getMessage("label.loggers.container.host")); 110 oForm.setContainerName(onContainer.getKeyProperty("host")); 111 loggerContainerType = LoggerItem.LOGGER_CATALINA_ACCESS_HOST; 112 loggerContainerName = on.getKeyProperty("host"); 113 } 114 } 115 m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) 117 + WhereAreYou.NODE_SEPARATOR 118 + "logging" 119 + WhereAreYou.NODE_SEPARATOR 120 + loggerContainerType 121 + WhereAreYou.NODE_SEPARATOR 122 + loggerContainerName, true); 123 } else { 124 oForm.setCatalinaDomainName(m_WhereAreYou.getCurrentCatalinaDomainName()); 125 ObjectName hostsOn = CatalinaObjectName.catalinaHosts(m_WhereAreYou.getCurrentCatalinaDomainName()); 126 Iterator hosts = JonasAdminJmx.getListMbean(hostsOn).iterator(); 127 ArrayList hostNames = new ArrayList (); 128 for (; hosts.hasNext();) { 129 hostNames.add(((ObjectName ) hosts.next()).getKeyProperty("host")); 130 } 131 String [] allNames = new String [hostNames.size() + 1]; 132 allNames[0] = "no name required for Engine"; 133 for (int i=1; i < allNames.length; i++) { 134 allNames[i] = (String ) hostNames.get(i-1); 135 } 136 oForm.setContainerNames(allNames); 137 } 138 } catch (Throwable t) { 139 addGlobalError(t); 140 saveErrors(pRequest, m_Errors); 141 return (pMapping.findForward("Global Error")); 142 } 143 return (pMapping.findForward("Catalina Access Logger")); 145 } 146 147 } 148 | Popular Tags |