00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 package org.objectweb.jonas.webapp.jonasadmin.service.container;
00027
00028 import java.io.IOException;
00029 import java.net.URL;
00030 import java.util.ArrayList;
00031 import java.util.Collections;
00032 import java.util.HashMap;
00033 import java.util.Iterator;
00034
00035 import javax.management.ObjectName;
00036 import javax.servlet.ServletException;
00037 import javax.servlet.http.HttpServletRequest;
00038 import javax.servlet.http.HttpServletResponse;
00039
00040 import org.apache.struts.action.ActionForm;
00041 import org.apache.struts.action.ActionForward;
00042 import org.apache.struts.action.ActionMapping;
00043 import org.objectweb.jonas.jmx.J2eeObjectName;
00044 import org.objectweb.jonas.jmx.JonasManagementRepr;
00045 import org.objectweb.jonas.jmx.JonasObjectName;
00046 import org.objectweb.jonas.webapp.jonasadmin.JettyObjectName;
00047 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
00048 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
00049 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
00050
00055 public class ListWebContainersAction extends JonasBaseAction {
00056
00057
00058
00059 public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
00060 , HttpServletRequest p_Request, HttpServletResponse p_Response)
00061 throws IOException, ServletException {
00062
00063
00064 m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR
00065 + "services" + WhereAreYou.NODE_SEPARATOR + "web", true);
00066
00067 m_WhereAreYou.setCurrentJonasDeploymentType(WhereAreYou.DEPLOYMENT_WAR);
00068
00069 m_Session.removeAttribute("itemsWebContainersForm");
00070
00071
00072 try {
00073 ArrayList al = new ArrayList();
00074 ObjectName on;
00075 String sPathContext;
00076 HashMap hWebAppItems = new HashMap();
00077
00078
00079 if (m_WhereAreYou.isCatalinaServer() == true) {
00080 WebAppItem oItem;
00081 String p_domainName = m_WhereAreYou.getCurrentDomainName();
00082 String p_serverName = m_WhereAreYou.getApplicationJonasServerName();
00083 ObjectName onContainers = J2eeObjectName.getWebModules(p_domainName, p_serverName);
00084 Iterator itOns = JonasAdminJmx.getListMbean(onContainers).iterator();
00085 while (itOns.hasNext()) {
00086 ObjectName onWebModule = (ObjectName) itOns.next();
00087 oItem = new WebAppItem(onWebModule);
00088 String webModulePath = ((URL) JonasManagementRepr.getAttribute(onWebModule, "warURL")).toString();
00089 String sFile = JonasAdminJmx.extractFilename(webModulePath);
00090 oItem.setFile(sFile);
00091 oItem.setPath(webModulePath);
00092 hWebAppItems.put(oItem.getPathContext(), oItem);
00093 }
00094 }
00095
00096 else if (m_WhereAreYou.isJettyServer() == true) {
00097 Iterator itOnContexts = JonasAdminJmx.getListMbean(JettyObjectName.jettyContexts()).
00098 iterator();
00099 while (itOnContexts.hasNext()) {
00100 on = (ObjectName) itOnContexts.next();
00101 sPathContext = on.getKeyProperty("context");
00102 if (sPathContext != null) {
00103 if (hWebAppItems.containsKey(sPathContext) == false) {
00104 hWebAppItems.put(sPathContext, new WebAppItem(sPathContext, on.toString()));
00105 }
00106 }
00107 }
00108
00109
00110
00111
00112
00113
00114 String sPath;
00115 String sFile;
00116 WebAppItem oWeb;
00117 Iterator itOnWars = JonasAdminJmx.getListMbean(JonasObjectName.allWars()).iterator();
00118 while (itOnWars.hasNext()) {
00119 on = (ObjectName) itOnWars.next();
00120 sPath = on.getKeyProperty("fname");
00121 sFile = JonasAdminJmx.extractFilename(sPath);
00122 sPathContext = getStringAttribute(on, "ContextRoot");
00123 if (sPathContext.charAt(0) != '/') {
00124 sPathContext = "/" + sPathContext;
00125 }
00126 oWeb = (WebAppItem) hWebAppItems.get(sPathContext);
00127 if (oWeb != null) {
00128 oWeb.setFile(sFile);
00129 oWeb.setPath(sPath);
00130 }
00131 }
00132 }
00133
00134
00135 al.addAll(hWebAppItems.values());
00136 Collections.sort(al, new WebAppItemByPathContext());
00137
00138
00139 p_Request.setAttribute("listWebContainers", al);
00140 }
00141 catch (Throwable t) {
00142 addGlobalError(t);
00143 saveErrors(p_Request, m_Errors);
00144 return (p_Mapping.findForward("Global Error"));
00145 }
00146
00147 return (p_Mapping.findForward("Web Containers"));
00148 }
00149 }