001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2003-2004 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: ApplyWebAppCatalinaAction.java 9864 2006-11-24 10:14:22Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.service.container;
025:
026: import java.io.IOException;
027:
028: import javax.management.ObjectName;
029: import javax.servlet.ServletException;
030: import javax.servlet.http.HttpServletRequest;
031: import javax.servlet.http.HttpServletResponse;
032:
033: import org.apache.struts.action.ActionMessage;
034: import org.apache.struts.action.ActionForm;
035: import org.apache.struts.action.ActionForward;
036: import org.apache.struts.action.ActionMapping;
037: import org.objectweb.jonas.jmx.CatalinaObjectName;
038: import org.objectweb.jonas.jmx.JonasManagementRepr;
039: import org.objectweb.jonas.jmx.JonasObjectName;
040: import org.objectweb.jonas.webapp.jonasadmin.JonasAdminException;
041: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
042:
043: /**
044: * @author Michel-Ange ANTON
045: */
046: public class ApplyWebAppCatalinaAction extends BaseWebAppAction {
047:
048: /**
049: * Signature for the <code>createStandardConnector</code> operation.
050: */
051: private String sa_CreateJOnASStandardContext[] = {
052: "java.lang.String", "java.lang.String", "java.lang.String" };
053:
054: private static String sDefaultForward = "ActionEditWebAppCatalina";
055:
056: // --------------------------------------------------------- Protected Variables
057:
058: // --------------------------------------------------------- Public Methods
059:
060: public ActionForward executeAction(ActionMapping p_Mapping,
061: ActionForm p_Form, HttpServletRequest p_Request,
062: HttpServletResponse p_Response) throws IOException,
063: ServletException {
064:
065: // Current server
066: WhereAreYou oWhere = (WhereAreYou) p_Request.getSession()
067: .getAttribute(WhereAreYou.SESSION_NAME);
068: String sServerName = oWhere.getCurrentJonasServerName();
069:
070: // Default forward
071: ActionForward oForward = null;
072:
073: // Identify the requested action
074: WebAppCatalinaForm oForm = (WebAppCatalinaForm) p_Form;
075:
076: // Populate
077: try {
078: // Save in memory the new datas
079: if ("edit".equals(oForm.getAction())) {
080: oForward = populateMbean(oForm, p_Mapping
081: .findForward(sDefaultForward), p_Mapping,
082: p_Request);
083: }
084: // Reload the web app
085: else if ("reload".equals(oForm.getAction())) {
086: oForward = reloadWebApplication(oForm, p_Mapping,
087: sServerName);
088: }
089: // Stop the web app
090: else if ("stop".equals(oForm.getAction())) {
091: oForward = stopWebApplication(oForm, p_Mapping,
092: sServerName);
093: }
094: // Start the web app
095: else if ("start".equals(oForm.getAction()) == true) {
096: oForward = startWebApplication(oForm, p_Mapping,
097: sServerName);
098: }
099: } catch (JonasAdminException e) {
100: // Build error
101: m_Errors.add("webapp", new ActionMessage(e.getId()));
102: saveErrors(p_Request, m_Errors);
103: // Return to the current page
104: oForward = new ActionForward(p_Mapping.getInput());
105: } catch (Throwable t) {
106: addGlobalError(t);
107: saveErrors(p_Request, m_Errors);
108: oForward = p_Mapping.findForward("Global Error");
109: }
110:
111: // Next Forward
112: return oForward;
113: }
114:
115: /**
116: * Populate the Mbean web application (Context, Manager, Loader).
117: * @param p_Form The current form
118: * @param p_Forward The current forward
119: * @param p_Mapping The current mapping
120: * @param p_Request The current request
121: * @return If 'save' is requested then return the new forward to save
122: * else return the current forward
123: * @throws Exception
124: */
125: protected ActionForward populateMbean(WebAppCatalinaForm p_Form,
126: ActionForward p_Forward, ActionMapping p_Mapping,
127: HttpServletRequest p_Request) throws Exception {
128: ActionForward oForward = p_Forward;
129: // Context
130: ObjectName on = ObjectName.getInstance(p_Form.getObjectName());
131: //setBooleanAttribute(on, "available", p_Form.isAvailable());
132: setBooleanAttribute(on, "cookies", p_Form.isCookies());
133: setBooleanAttribute(on, "crossContext", p_Form.isCrossContext());
134: setBooleanAttribute(on, "reloadable", p_Form.isReloadable());
135: setBooleanAttribute(on, "swallowOutput", p_Form
136: .isSwallowOutput());
137: setBooleanAttribute(on, "override", p_Form.isOverride());
138: // Save in configuration file
139: if (p_Form.isSave()) {
140: //ObjectName onServer = CatalinaObjectName.catalinaServer();
141: //JonasManagementRepr.invoke(onServer, "store", null, null);
142: p_Form.setSave(false);
143: p_Request.setAttribute("forward", p_Forward.getName());
144: oForward = p_Mapping.findForward("ActionEditServletServer");
145: }
146: return oForward;
147: }
148:
149: /**
150: * Reload the current web application.
151: * @param p_Form The current form
152: * @param p_Mapping The current mapping
153: * @return The forward to go to the next page
154: * @throws Exception
155: */
156: protected ActionForward reloadWebApplication(
157: WebAppCatalinaForm p_Form, ActionMapping p_Mapping,
158: String jonasServerName) throws Exception {
159: // Reload
160: try {
161: String sWebModuleObjectName = p_Form.getObjectName();
162: ObjectName proxyObjectName = JonasObjectName
163: .webModuleProxy(m_WhereAreYou
164: .getCurrentCatalinaDomainName());
165: Object[] params = { sWebModuleObjectName };
166: String[] signs = { "java.lang.String" };
167: JonasManagementRepr.invoke(proxyObjectName, "reload",
168: params, signs, jonasServerName);
169: /*
170: ObjectName onContext = new ObjectName(p_Form.getObjectName());
171: JonasManagementRepr.invoke(onContext, "reload", null, null);
172: */
173: } catch (Throwable t) {
174: throw new JonasAdminException("error.webapp.reload");
175: }
176: // Forward
177: ActionForward oForward = null;
178: if (p_Form.getName().equals(
179: m_WhereAreYou.getApplicationContextPath())) {
180: oForward = p_Mapping.findForward("Main Index");
181: } else {
182: oForward = p_Mapping.findForward(sDefaultForward);
183: }
184: return oForward;
185: }
186:
187: /**
188: * Start the current web application.
189: * @param p_Form The current form
190: * @param p_Mapping The current mapping
191: * @return The forward to go to the next page
192: * @throws Exception
193: */
194: protected ActionForward startWebApplication(
195: WebAppCatalinaForm p_Form, ActionMapping p_Mapping,
196: String jonasServerName) throws Exception {
197: try {
198: String sWebModuleObjectName = p_Form.getObjectName();
199: ObjectName proxyObjectName = JonasObjectName
200: .webModuleProxy(m_WhereAreYou
201: .getCurrentCatalinaDomainName());
202: Object[] params = { sWebModuleObjectName };
203: String[] signs = { "java.lang.String" };
204: JonasManagementRepr.invoke(proxyObjectName, "start",
205: params, signs, jonasServerName);
206: /*
207: ObjectName onContext = new ObjectName(p_Form.getObjectName());
208: JonasManagementRepr.invoke(onContext, "start", null, null);
209: */
210: } catch (Throwable t) {
211: throw new JonasAdminException("error.webapp.start");
212: }
213: return p_Mapping.findForward(sDefaultForward);
214: }
215:
216: /**
217: * Stop the current web application.
218: * @param p_Form The current form
219: * @param p_Mapping The current mapping
220: * @return The forward to go to the next page
221: * @throws Exception
222: */
223: protected ActionForward stopWebApplication(
224: WebAppCatalinaForm p_Form, ActionMapping p_Mapping,
225: String jonasServerName) throws Exception {
226: try {
227: String sWebModuleObjectName = p_Form.getObjectName();
228: ObjectName proxyObjectName = JonasObjectName
229: .webModuleProxy(m_WhereAreYou
230: .getCurrentCatalinaDomainName());
231: Object[] params = { sWebModuleObjectName };
232: String[] signs = { "java.lang.String" };
233: JonasManagementRepr.invoke(proxyObjectName, "stop", params,
234: signs, jonasServerName);
235: /*
236: ObjectName onContext = new ObjectName(p_Form.getObjectName());
237: JonasManagementRepr.invoke(onContext, "stop", null, null);
238: */
239: } catch (Throwable t) {
240: throw new JonasAdminException("error.webapp.stop");
241: }
242: return p_Mapping.findForward(sDefaultForward);
243: }
244: }
|