001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 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: ApplyWebAppJettyAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.webapp.jonasadmin.service.container;
027:
028: import java.io.IOException;
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.ActionMessage;
036: import org.apache.struts.action.ActionForm;
037: import org.apache.struts.action.ActionForward;
038: import org.apache.struts.action.ActionMapping;
039: import org.objectweb.jonas.jmx.JonasManagementRepr;
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 ApplyWebAppJettyAction extends BaseWebAppAction {
047:
048: private static String sDefaultForward = "ActionEditWebAppJetty";
049:
050: // --------------------------------------------------------- Protected Variables
051:
052: // --------------------------------------------------------- Public Methods
053:
054: public ActionForward executeAction(ActionMapping p_Mapping,
055: ActionForm p_Form, HttpServletRequest p_Request,
056: HttpServletResponse p_Response) throws IOException,
057: ServletException {
058:
059: // Current server
060: WhereAreYou oWhere = (WhereAreYou) p_Request.getSession()
061: .getAttribute(WhereAreYou.SESSION_NAME);
062: String jonasServerName = oWhere.getCurrentJonasServerName();
063:
064: // Default forward
065: ActionForward oForward = null;
066:
067: // Identify the requested action
068: WebAppJettyForm oForm = (WebAppJettyForm) p_Form;
069:
070: // Populate
071: try {
072: // Stop the web app
073: if ("stop".equals(oForm.getAction())) {
074: oForward = stopWebApplication(oForm, p_Mapping,
075: jonasServerName);
076: }
077: // Start the web app
078: else if ("start".equals(oForm.getAction())) {
079: oForward = startWebApplication(oForm, p_Mapping,
080: jonasServerName);
081: }
082: } catch (JonasAdminException e) {
083: // Build error
084: m_Errors.add("webapp", new ActionMessage(e.getId()));
085: saveErrors(p_Request, m_Errors);
086: // Return to the current page
087: oForward = new ActionForward(p_Mapping.getInput());
088: } catch (Throwable t) {
089: addGlobalError(t);
090: saveErrors(p_Request, m_Errors);
091: oForward = p_Mapping.findForward("Global Error");
092: }
093:
094: // Next Forward
095: return oForward;
096: }
097:
098: // --------------------------------------------------------- Protected Methods
099:
100: /**
101: * Start the current web application.
102: * @param p_Form The current form
103: * @param p_Mapping The current mapping
104: * @return The forward to go to the next page
105: * @throws Exception
106: */
107: protected ActionForward startWebApplication(WebAppJettyForm p_Form,
108: ActionMapping p_Mapping, String jonasServerName)
109: throws Exception {
110: try {
111: ObjectName onContext = new ObjectName(p_Form
112: .getObjectName());
113: JonasManagementRepr.invoke(onContext, "start", null, null,
114: jonasServerName);
115: } catch (Throwable t) {
116: throw new JonasAdminException("error.webapp.start");
117: }
118: return p_Mapping.findForward(sDefaultForward);
119: }
120:
121: /**
122: * Stop the current web application.
123: * @param p_Form The current form
124: * @param p_Mapping The current mapping
125: * @return The forward to go to the next page
126: * @throws Exception
127: */
128: protected ActionForward stopWebApplication(WebAppJettyForm p_Form,
129: ActionMapping p_Mapping, String jonasServerName)
130: throws Exception {
131: try {
132: ObjectName onContext = new ObjectName(p_Form
133: .getObjectName());
134: JonasManagementRepr.invoke(onContext, "stop", null, null,
135: jonasServerName);
136: } catch (Throwable t) {
137: throw new JonasAdminException("error.webapp.stop");
138: }
139: return p_Mapping.findForward(sDefaultForward);
140: }
141: }
|