KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > logging > ApplyCatalinaAccessLoggerAction


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2003-2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: ApplyCatalinaAccessLoggerAction.java,v 1.9 2005/04/21 08:59:54 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.logging;
27
28 import java.io.IOException JavaDoc;
29
30 import javax.management.ObjectName JavaDoc;
31 import javax.servlet.ServletException JavaDoc;
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
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 /**
45  * @author Michel-Ange ANTON
46  * @author Adriana Danes
47  */

48 public class ApplyCatalinaAccessLoggerAction extends BaseLoggerAction {
49
50     /**
51      * Signature for the <code>createStandardConnector</code> operation.
52      */

53     private String JavaDoc sa_CreateAccessLogger[] = {
54         "java.lang.String"
55     };
56
57     private static String JavaDoc sDefaultForward = "ActionEditWebAppCatalina";
58
59 // --------------------------------------------------------- Protected Variables
60

61 // --------------------------------------------------------- Public Methods
62
/**
63      * Execute CatalinaAccessLogger action
64      * @param pForm The current form
65      * @param pMapping The current mapping
66      * @param pRequest The current request
67      * @param pResponse The response to the current request
68      * @return The forward to go to the next page
69      * @throws Exception
70      */

71     public ActionForward executeAction(ActionMapping pMapping, ActionForm pForm
72         , HttpServletRequest JavaDoc pRequest, HttpServletResponse JavaDoc pResponse)
73         throws IOException JavaDoc, ServletException JavaDoc {
74
75         // Default forward
76
ActionForward oForward = null;
77
78         // Form used
79
CatalinaAccessLogValveForm oForm = (CatalinaAccessLogValveForm) pForm;
80
81         // Populate
82
try {
83             if ("create".equals(oForm.getAction())) {
84                 oForward = createAccessLogger(oForm, pMapping, pRequest);
85             } else if ("edit".equals(oForm.getAction())) {
86                 // Save in memory the new datas
87
oForward = populateMbean(oForm
88                     , pMapping.findForward("ActionEditCatalinaAccessLogger"), pMapping, pRequest);
89             }
90         } catch (JonasAdminException e) {
91             // Build error
92
m_Errors.add("logger.catalina.access", new ActionMessage(e.getId()));
93             saveErrors(pRequest, m_Errors);
94             // Return to the current page
95
oForward = new ActionForward(pMapping.getInput());
96         } catch (Throwable JavaDoc t) {
97             addGlobalError(t);
98             saveErrors(pRequest, m_Errors);
99             oForward = pMapping.findForward("Global Error");
100         }
101
102         // Next Forward
103
return oForward;
104     }
105
106     /**
107      * Create a new access logger.
108      * @param pForm The current form
109      * @param pMapping The current mapping
110      * @param pRequest The current request
111      * @return The forward to go to the next page
112      * @throws Exception
113      */

114     protected ActionForward createAccessLogger(CatalinaAccessLogValveForm pForm
115         , ActionMapping pMapping, HttpServletRequest JavaDoc pRequest)
116         throws Exception JavaDoc {
117         Object JavaDoc values[] = null;
118         // Look up the Catalina MBeanFactory
119
ObjectName JavaDoc onFactory = CatalinaObjectName.catalinaFactory();
120         // Create a new Access Logger Valve object
121
values = new Object JavaDoc[1];
122         String JavaDoc domainName = m_WhereAreYou.getCurrentCatalinaDomainName();
123         // Determine container type
124
String JavaDoc containerType = pForm.getContainerType();
125         if (containerType.equals(m_Resources.getMessage("label.loggers.container.engine"))) {
126             ObjectName JavaDoc onEngine = CatalinaObjectName.catalinaEngine(domainName);
127             values[0] = (onEngine).toString();
128         } else if (containerType.equals(m_Resources.getMessage("label.loggers.container.host"))) {
129             ObjectName JavaDoc onHost = CatalinaObjectName.catalinaHost(domainName, pForm.getContainerName());
130             values[0] = (onHost).toString();
131         }
132         Object JavaDoc onValve = JonasManagementRepr.invoke(onFactory
133                 , "createAccessLoggerValve",
134                 values,
135                 sa_CreateAccessLogger);
136         pForm.setObjectName((String JavaDoc) onValve);
137         // Populate
138
ActionForward oForward = populateMbean(pForm, pMapping.findForward("ActionListLoggers")
139             , pMapping, pRequest);
140
141         // refresh tree
142
refreshTree(pRequest);
143         // Force the node selected in tree
144
m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR
145             + "logging" + WhereAreYou.NODE_SEPARATOR + LoggerItem.LOGGER_CATALINA_ACCESS_HOST, true);
146
147         // Return the next forward
148
return oForward;
149     }
150
151     /**
152      * Populate the Mbean Access Logger.
153      * @param p_Form The current form
154      * @param p_Forward The current forward
155      * @param p_Mapping The current mapping
156      * @param p_Request The current request
157      * @return If 'save' is requested then return the new forward to save
158      * else return the current forward
159      * @throws Exception Failed to populate Mbean
160      */

161     protected ActionForward populateMbean(CatalinaAccessLogValveForm p_Form
162         , ActionForward p_Forward, ActionMapping p_Mapping, HttpServletRequest JavaDoc p_Request)
163         throws Exception JavaDoc {
164         ActionForward oForward = p_Forward;
165         // Access logger
166
ObjectName JavaDoc on = new ObjectName JavaDoc(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         // Save in configuration file
174
if (p_Form.isSave()) {
175             //ObjectName onServer = CatalinaObjectName.catalinaServer();
176
//JonasManagementRepr.invoke(onServer, "store", null, null);
177
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