1 25 26 package org.objectweb.jonas.webapp.jonasadmin.service.container; 27 28 import java.net.URL ; 29 import java.util.Iterator ; 30 31 import javax.management.ObjectName ; 32 import javax.servlet.http.HttpServletRequest ; 33 34 import org.apache.struts.action.ActionMapping; 35 import org.objectweb.jonas.jmx.J2eeObjectName; 36 import org.objectweb.jonas.jmx.JonasManagementRepr; 37 import org.objectweb.jonas.jmx.JonasObjectName; 38 import org.objectweb.jonas.webapp.jonasadmin.JettyObjectName; 39 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx; 40 import org.objectweb.jonas.webapp.jonasadmin.deploy.BaseDeployAction; 41 42 45 46 abstract public class BaseWebAppAction extends BaseDeployAction { 47 48 50 protected WebAppForm mWebAppForm; 51 protected WarForm mWarForm; 52 53 55 57 63 protected boolean initialize(ActionMapping p_Mapping, HttpServletRequest p_Request) { 64 65 boolean bPopulate = false; 66 67 mWebAppForm = null; 69 mWarForm = null; 70 71 String sParamAction = p_Request.getParameter("action"); 73 String sParamWebAppObjectName = p_Request.getParameter("on"); 75 String sParamPathWar = p_Request.getParameter("war"); 77 78 if (sParamAction != null && "create".equals(sParamAction)) { 80 mWebAppForm = createWebAppForm(p_Mapping, p_Request); 82 mWebAppForm.setAction("create"); 83 m_Session.removeAttribute("warForm"); 85 } else if (sParamWebAppObjectName != null) { 86 mWebAppForm = createWebAppForm(p_Mapping, p_Request); 88 mWebAppForm.setObjectName(sParamWebAppObjectName); 89 bPopulate = true; 90 m_Session.removeAttribute("warForm"); 92 } else if (sParamPathWar != null) { 93 mWarForm = createWarForm(p_Mapping, p_Request); 95 mWarForm.setPath(sParamPathWar); 96 mWarForm.setFilename(JonasAdminJmx.extractFilename(sParamPathWar)); 97 bPopulate = true; 98 } else { 99 mWebAppForm = (WebAppForm) m_Session.getAttribute("webAppForm"); 101 if (mWebAppForm != null) { 102 mWebAppForm.setAction("edit"); 103 } 104 mWarForm = (WarForm) m_Session.getAttribute("warForm"); 105 if (("reload".equals(sParamAction) == true) || ("start".equals(sParamAction) == true) 107 || ("stop".equals(sParamAction) == true)) { 108 bPopulate = true; 109 } 110 } 111 return bPopulate; 112 } 113 114 120 protected WebAppForm createWebAppForm(ActionMapping p_Mapping, HttpServletRequest p_Request) { 121 WebAppForm oForm = null; 122 if (m_WhereAreYou.isCatalinaServer() == true) { 123 oForm = new WebAppCatalinaForm(); 124 oForm.reset(p_Mapping, p_Request); 125 m_Session.setAttribute("webAppForm", oForm); 126 m_Session.setAttribute("webAppCatalinaForm", oForm); 127 } 128 else if (m_WhereAreYou.isJettyServer() == true) { 129 oForm = new WebAppJettyForm(); 130 oForm.reset(p_Mapping, p_Request); 131 m_Session.setAttribute("webAppForm", oForm); 132 m_Session.setAttribute("webAppJettyForm", oForm); 133 } 134 return oForm; 135 } 136 137 143 protected WarForm createWarForm(ActionMapping p_Mapping, HttpServletRequest p_Request) { 144 WarForm oForm = new WarForm(); 145 oForm.reset(p_Mapping, p_Request); 146 m_Session.setAttribute("warForm", oForm); 147 return oForm; 148 } 149 150 156 protected void populateWebApp(String p_ObjectName, WebAppForm p_Form) 157 throws Exception { 158 if (m_WhereAreYou.isCatalinaServer() == true) { 159 populateWebAppCatalina(p_ObjectName, (WebAppCatalinaForm) p_Form); 160 } 161 else if (m_WhereAreYou.isJettyServer() == true) { 162 populateWebAppJetty(p_ObjectName, (WebAppJettyForm) p_Form); 163 } 164 } 165 166 173 protected void populateWebAppCatalina(String p_ObjectName, WebAppCatalinaForm p_Form) 174 throws Exception { 175 ObjectName on = new ObjectName (p_ObjectName); 177 p_Form.setObjectName(on.toString()); 178 p_Form.setName(on.getKeyProperty("name")); 179 p_Form.setJ2eeApplication(on.getKeyProperty("J2EEApplication")); 180 p_Form.setJ2eeServer(on.getKeyProperty("J2EEServer")); 181 p_Form.setPathContext(WebAppItem.extractPathContext(p_Form.getName())); 182 p_Form.setHost(getStringAttribute(on, "hostname")); 183 p_Form.setCookies(getBooleanAttribute(on, "cookies")); 184 p_Form.setReloadable(getBooleanAttribute(on, "reloadable")); 185 p_Form.setSwallowOutput(getBooleanAttribute(on, "swallowOutput")); 186 p_Form.setCrossContext(getBooleanAttribute(on, "crossContext")); 187 p_Form.setOverride(getBooleanAttribute(on, "override")); 188 p_Form.setState(getIntegerAttribute(on, "state")); 189 } 190 191 197 protected void populateWebAppJetty(String p_ObjectName, WebAppJettyForm p_Form) 198 throws Exception { 199 ObjectName on = new ObjectName (p_ObjectName); 200 p_Form.setStarted(getBooleanAttribute(on, "started")); 202 p_Form.setResourceBase(getStringAttribute(on, "resourceBase")); 203 p_Form.setDisplayName(getStringAttribute(on, "displayName")); 204 p_Form.setPathContext(getStringAttribute(on, "contextPath")); 205 } 206 207 213 protected ObjectName findJonasMbeanWar(String p_PathContext) 214 throws Exception { 215 ObjectName onRet = null; 216 ObjectName on; 217 String sPathContext; 218 StringBuffer sb; 219 220 Iterator itOnWars = JonasAdminJmx.getListMbean(JonasObjectName.allWars()).iterator(); 221 while (itOnWars.hasNext()) { 222 on = (ObjectName ) itOnWars.next(); 223 sPathContext = getStringAttribute(on, "ContextRoot"); 224 if (sPathContext.charAt(0) != '/') { 225 sb = new StringBuffer ("/"); 226 sb.append(sPathContext); 227 sPathContext = sb.toString(); 228 } 229 if (p_PathContext.equals(sPathContext) == true) { 231 onRet = on; 232 break; 233 } 234 } 235 return onRet; 236 } 237 238 244 protected ObjectName findWebAppMbean(String p_PathContext) 245 throws Exception { 246 ObjectName onRet = null; 247 if (m_WhereAreYou.isCatalinaServer() == true) { 248 onRet = findJ2eeWebModuleMbean(p_PathContext); 249 } 250 else if (m_WhereAreYou.isJettyServer() == true) { 251 252 } 253 return onRet; 254 } 255 256 262 protected ObjectName findJ2eeWebModuleMbean(String p_PathContext) 263 throws Exception { 264 ObjectName onRet = null; 265 ObjectName on; 266 String sPathContext; 267 String sSearchPathContext = p_PathContext; 268 if (sSearchPathContext.charAt(0) != '/') { 269 sSearchPathContext = "/" + p_PathContext; 270 } 271 272 Iterator itOns = JonasAdminJmx.getListMbean(J2eeObjectName.getWebModules(m_WhereAreYou. 273 getCurrentCatalinaDomainName())).iterator(); 274 while (itOns.hasNext()) { 275 on = (ObjectName ) itOns.next(); 276 sPathContext = on.getKeyProperty("name"); 278 if (sSearchPathContext.equals(sPathContext) == true) { 280 onRet = on; 281 break; 282 } 283 } 284 return onRet; 285 } 286 287 293 protected void populateWar(ObjectName p_ObjectName, WarForm p_Form) 294 throws Exception { 295 if (p_ObjectName != null) { 296 String webModulePath = ((URL ) JonasManagementRepr.getAttribute(p_ObjectName, "warURL")).toString(); 298 p_Form.setPath(webModulePath); 299 p_Form.setFilename(JonasAdminJmx.extractFilename(p_Form.getPath())); 300 p_Form.setHostName(getStringAttribute(p_ObjectName, "hostname")); 303 p_Form.setInEarCase(getBooleanAttribute(p_ObjectName, "inEarCase")); 304 p_Form.setContextRoot(getStringAttribute(p_ObjectName, "path")); 306 p_Form.setJava2DelegationModel(getBooleanAttribute(p_ObjectName, "java2DelegationModel")); 307 p_Form.setXmlContent(getStringAttribute(p_ObjectName, "deploymentDescriptor")); 308 p_Form.setJonasXmlContent(getStringAttribute(p_ObjectName, "jonasDeploymentDescriptor")); 309 p_Form.setServletsName((String []) JonasManagementRepr.getAttribute(p_ObjectName 310 , "servlets")); 311 p_Form.setWarPath((URL ) JonasManagementRepr.getAttribute(p_ObjectName, "warURL")); 312 p_Form.setEarPath((URL ) JonasManagementRepr.getAttribute(p_ObjectName, "earURL")); 313 } 314 } 315 321 protected void populateJettyWar(ObjectName p_ObjectName, WarForm p_Form) 322 throws Exception { 323 if (p_ObjectName != null) { 324 p_Form.setPath(p_ObjectName.getKeyProperty("fname")); 325 p_Form.setFilename(JonasAdminJmx.extractFilename(p_Form.getPath())); 326 327 p_Form.setHostName(getStringAttribute(p_ObjectName, "HostName")); 328 p_Form.setInEarCase(getBooleanAttribute(p_ObjectName, "InEarCase")); 329 p_Form.setContextRoot(getStringAttribute(p_ObjectName, "ContextRoot")); 330 p_Form.setJava2DelegationModel(getBooleanAttribute(p_ObjectName, "Java2DelegationModel")); 331 p_Form.setXmlContent(getStringAttribute(p_ObjectName, "XmlContent")); 332 p_Form.setJonasXmlContent(getStringAttribute(p_ObjectName, "JOnASXmlContent")); 333 p_Form.setServletsName((String []) JonasManagementRepr.getAttribute(p_ObjectName 334 , "ServletsName")); 335 p_Form.setWarPath((URL ) JonasManagementRepr.getAttribute(p_ObjectName, "WarURL")); 336 p_Form.setEarPath((URL ) JonasManagementRepr.getAttribute(p_ObjectName, "EarURL")); 337 } 338 } 339 340 346 protected void populateWar(String p_Path, WarForm p_Form) 347 throws Exception { 348 populateWar(JonasObjectName.war(p_Path), p_Form); 349 } 350 } 351 | Popular Tags |