1 25 26 package org.objectweb.jonas.webapp.jonasadmin.service.container; 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.CatalinaObjectName; 40 import org.objectweb.jonas.jmx.JonasManagementRepr; 41 import org.objectweb.jonas.jmx.JonasObjectName; 42 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminException; 43 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou; 44 45 48 public class ApplyWebAppCatalinaAction extends BaseWebAppAction { 49 50 53 private String sa_CreateJOnASStandardContext[] = { 54 "java.lang.String", "java.lang.String", "java.lang.String" 55 }; 56 57 private static String sDefaultForward = "ActionEditWebAppCatalina"; 58 59 61 63 public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form 64 , HttpServletRequest p_Request, HttpServletResponse p_Response) 65 throws IOException , ServletException { 66 67 ActionForward oForward = null; 69 70 WebAppCatalinaForm oForm = (WebAppCatalinaForm) p_Form; 72 73 try { 75 if ("create".equals(oForm.getAction())) { 77 oForward = createWebApplication(oForm, p_Mapping, p_Request); 78 } 79 else if ("edit".equals(oForm.getAction())) { 81 oForward = populateMbean(oForm, p_Mapping.findForward(sDefaultForward), p_Mapping 82 , p_Request); 83 } 84 else if ("reload".equals(oForm.getAction())) { 86 oForward = reloadWebApplication(oForm, p_Mapping); 87 } 88 else if ("stop".equals(oForm.getAction())) { 90 oForward = stopWebApplication(oForm, p_Mapping); 91 } 92 else if ("start".equals(oForm.getAction()) == true) { 94 oForward = startWebApplication(oForm, p_Mapping); 95 } 96 } catch (JonasAdminException e) { 97 m_Errors.add("webapp", new ActionMessage(e.getId())); 99 saveErrors(p_Request, m_Errors); 100 oForward = new ActionForward(p_Mapping.getInput()); 102 } catch (Throwable t) { 103 addGlobalError(t); 104 saveErrors(p_Request, m_Errors); 105 oForward = p_Mapping.findForward("Global Error"); 106 } 107 108 return oForward; 110 } 111 112 120 protected ActionForward createWebApplication(WebAppCatalinaForm p_Form, ActionMapping p_Mapping 121 , HttpServletRequest p_Request) 122 throws Exception { 123 Object values[] = null; 124 125 ObjectName onContext = findWebAppMbean(p_Form.getPathContext()); 127 if (onContext != null) { 128 throw new JonasAdminException("error.webapp.context.exists"); 129 } 130 131 ObjectName onWebService = JonasObjectName.webContainerService(); 133 values = new Object [3]; 135 values[0] = CatalinaObjectName.catalinaHost(m_WhereAreYou.getCurrentCatalinaServiceName() 137 , m_WhereAreYou.getCurrentCatalinaDefaultHostName()).toString(); 138 values[1] = p_Form.getPathContext(); 139 values[2] = ""; 140 p_Form.setObjectName((String ) JonasManagementRepr.invoke(onWebService 141 , "createJOnASStandardContext", values, sa_CreateJOnASStandardContext)); 142 143 ActionForward oForward = populateMbean(p_Form 145 , p_Mapping.findForward("ActionListWebContainers"), p_Mapping, p_Request); 146 147 try { 149 stopWebApplication(p_Form, p_Mapping); 150 } catch (Exception e) { 151 } 153 154 refreshTree(p_Request); 156 m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR 158 + "services" + WhereAreYou.NODE_SEPARATOR + "web" + WhereAreYou.NODE_SEPARATOR 159 + p_Form.getName(), true); 160 161 return oForward; 162 } 163 164 174 protected ActionForward populateMbean(WebAppCatalinaForm p_Form, ActionForward p_Forward 175 , ActionMapping p_Mapping, HttpServletRequest p_Request) 176 throws Exception { 177 ActionForward oForward = p_Forward; 178 ObjectName on = ObjectName.getInstance(p_Form.getObjectName()); 180 setBooleanAttribute(on, "cookies", p_Form.isCookies()); 182 setBooleanAttribute(on, "crossContext", p_Form.isCrossContext()); 183 setBooleanAttribute(on, "reloadable", p_Form.isReloadable()); 184 setBooleanAttribute(on, "swallowOutput", p_Form.isSwallowOutput()); 185 setBooleanAttribute(on, "override", p_Form.isOverride()); 186 if (p_Form.isSave()) { 188 p_Form.setSave(false); 191 p_Request.setAttribute("forward", p_Forward.getName()); 192 oForward = p_Mapping.findForward("ActionEditServletServer"); 193 } 194 return oForward; 195 } 196 197 204 protected ActionForward reloadWebApplication(WebAppCatalinaForm p_Form, ActionMapping p_Mapping) 205 throws Exception { 206 try { 208 String sWebModuleObjectName = p_Form.getObjectName(); 209 ObjectName proxyObjectName = JonasObjectName.webModuleProxy(m_WhereAreYou.getCurrentCatalinaDomainName()); 210 Object [] params = { sWebModuleObjectName }; 211 String [] signs = { "java.lang.String" }; 212 JonasManagementRepr.invoke(proxyObjectName, "reload", params, signs); 213 217 } 218 catch (Throwable t) { 219 throw new JonasAdminException("error.webapp.reload"); 220 } 221 ActionForward oForward = null; 223 if (p_Form.getName().equals(m_WhereAreYou.getApplicationContextPath())) { 224 oForward = p_Mapping.findForward("Main Index"); 225 } else { 226 oForward = p_Mapping.findForward(sDefaultForward); 227 } 228 return oForward; 229 } 230 231 238 protected ActionForward startWebApplication(WebAppCatalinaForm p_Form, ActionMapping p_Mapping) 239 throws Exception { 240 try { 241 String sWebModuleObjectName = p_Form.getObjectName(); 242 ObjectName proxyObjectName = JonasObjectName.webModuleProxy(m_WhereAreYou.getCurrentCatalinaDomainName()); 243 Object [] params = {sWebModuleObjectName}; 244 String [] signs = {"java.lang.String"}; 245 JonasManagementRepr.invoke(proxyObjectName, "start", params, signs); 246 250 } catch (Throwable t) { 251 throw new JonasAdminException("error.webapp.start"); 252 } 253 return p_Mapping.findForward(sDefaultForward); 254 } 255 256 263 protected ActionForward stopWebApplication(WebAppCatalinaForm p_Form, ActionMapping p_Mapping) 264 throws Exception { 265 try { 266 String sWebModuleObjectName = p_Form.getObjectName(); 267 ObjectName proxyObjectName = JonasObjectName.webModuleProxy(m_WhereAreYou.getCurrentCatalinaDomainName()); 268 Object [] params = {sWebModuleObjectName}; 269 String [] signs = {"java.lang.String"}; 270 JonasManagementRepr.invoke(proxyObjectName, "stop", params, signs); 271 275 } catch (Throwable t) { 276 throw new JonasAdminException("error.webapp.stop"); 277 } 278 return p_Mapping.findForward(sDefaultForward); 279 } 280 } 281 | Popular Tags |