1 25 26 package org.objectweb.jonas.webapp.jonasadmin.logging; 27 28 import java.io.IOException ; 29 30 import javax.management.ObjectName ; 31 import javax.servlet.ServletException ; 32 import javax.servlet.http.HttpServletRequest ; 33 import javax.servlet.http.HttpServletResponse ; 34 35 import org.apache.struts.action.ActionMessage; 36 import org.apache.struts.action.ActionForm; 37 import org.apache.struts.action.ActionForward; 38 import org.apache.struts.action.ActionMapping; 39 import org.objectweb.jonas.jmx.JonasManagementRepr; 40 import org.objectweb.jonas.jmx.CatalinaObjectName; 41 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminException; 42 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou; 43 44 48 public class ApplyCatalinaAccessLoggerAction extends BaseLoggerAction { 49 50 53 private String sa_CreateAccessLogger[] = { 54 "java.lang.String" 55 }; 56 57 private static String sDefaultForward = "ActionEditWebAppCatalina"; 58 59 61 71 public ActionForward executeAction(ActionMapping pMapping, ActionForm pForm 72 , HttpServletRequest pRequest, HttpServletResponse pResponse) 73 throws IOException , ServletException { 74 75 ActionForward oForward = null; 77 78 CatalinaAccessLogValveForm oForm = (CatalinaAccessLogValveForm) pForm; 80 81 try { 83 if ("create".equals(oForm.getAction())) { 84 oForward = createAccessLogger(oForm, pMapping, pRequest); 85 } else if ("edit".equals(oForm.getAction())) { 86 oForward = populateMbean(oForm 88 , pMapping.findForward("ActionEditCatalinaAccessLogger"), pMapping, pRequest); 89 } 90 } catch (JonasAdminException e) { 91 m_Errors.add("logger.catalina.access", new ActionMessage(e.getId())); 93 saveErrors(pRequest, m_Errors); 94 oForward = new ActionForward(pMapping.getInput()); 96 } catch (Throwable t) { 97 addGlobalError(t); 98 saveErrors(pRequest, m_Errors); 99 oForward = pMapping.findForward("Global Error"); 100 } 101 102 return oForward; 104 } 105 106 114 protected ActionForward createAccessLogger(CatalinaAccessLogValveForm pForm 115 , ActionMapping pMapping, HttpServletRequest pRequest) 116 throws Exception { 117 Object values[] = null; 118 ObjectName onFactory = CatalinaObjectName.catalinaFactory(); 120 values = new Object [1]; 122 String domainName = m_WhereAreYou.getCurrentCatalinaDomainName(); 123 String containerType = pForm.getContainerType(); 125 if (containerType.equals(m_Resources.getMessage("label.loggers.container.engine"))) { 126 ObjectName onEngine = CatalinaObjectName.catalinaEngine(domainName); 127 values[0] = (onEngine).toString(); 128 } else if (containerType.equals(m_Resources.getMessage("label.loggers.container.host"))) { 129 ObjectName onHost = CatalinaObjectName.catalinaHost(domainName, pForm.getContainerName()); 130 values[0] = (onHost).toString(); 131 } 132 Object onValve = JonasManagementRepr.invoke(onFactory 133 , "createAccessLoggerValve", 134 values, 135 sa_CreateAccessLogger); 136 pForm.setObjectName((String ) onValve); 137 ActionForward oForward = populateMbean(pForm, pMapping.findForward("ActionListLoggers") 139 , pMapping, pRequest); 140 141 refreshTree(pRequest); 143 m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR 145 + "logging" + WhereAreYou.NODE_SEPARATOR + LoggerItem.LOGGER_CATALINA_ACCESS_HOST, true); 146 147 return oForward; 149 } 150 151 161 protected ActionForward populateMbean(CatalinaAccessLogValveForm p_Form 162 , ActionForward p_Forward, ActionMapping p_Mapping, HttpServletRequest p_Request) 163 throws Exception { 164 ActionForward oForward = p_Forward; 165 ObjectName on = new ObjectName (p_Form.getObjectName()); 167 setStringAttribute(on, "directory", p_Form.getDirectory()); 168 setStringAttribute(on, "prefix", p_Form.getPrefix()); 169 setStringAttribute(on, "suffix", p_Form.getSuffix()); 170 setBooleanAttribute(on, "resolveHosts", p_Form.isResolveHosts()); 171 setBooleanAttribute(on, "rotatable", p_Form.isRotatable()); 172 setStringAttribute(on, "pattern", p_Form.getPattern()); 173 if (p_Form.isSave()) { 175 p_Form.setSave(false); 178 p_Request.setAttribute("forward", p_Forward.getName()); 179 oForward = p_Mapping.findForward("ActionEditServletServer"); 180 } 181 return oForward; 182 } 183 184 } 185 | Popular Tags |