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: ListWebContainersAction.java 9967 2007-01-29 14:57:49Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.service.container;
025:
026: import java.io.IOException;
027: import java.net.URL;
028: import java.util.ArrayList;
029: import java.util.Collections;
030: import java.util.HashMap;
031: import java.util.Iterator;
032:
033: import javax.management.ObjectName;
034: import javax.servlet.ServletException;
035: import javax.servlet.http.HttpServletRequest;
036: import javax.servlet.http.HttpServletResponse;
037:
038: import org.apache.struts.action.ActionForm;
039: import org.apache.struts.action.ActionForward;
040: import org.apache.struts.action.ActionMapping;
041: import org.objectweb.jonas.jmx.J2eeObjectName;
042: import org.objectweb.jonas.jmx.JonasManagementRepr;
043: import org.objectweb.jonas.jmx.JonasObjectName;
044: import org.objectweb.jonas.webapp.jonasadmin.JettyObjectName;
045: import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
046: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
047: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
048:
049: /**
050: * @author Michel-Ange ANTON
051: */
052:
053: public class ListWebContainersAction extends JonasBaseAction {
054:
055: // --------------------------------------------------------- Public Methods
056:
057: public ActionForward executeAction(ActionMapping p_Mapping,
058: ActionForm p_Form, HttpServletRequest p_Request,
059: HttpServletResponse p_Response) throws IOException,
060: ServletException {
061:
062: // Force the node selected in tree
063: m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER)
064: + WhereAreYou.NODE_SEPARATOR + "services"
065: + WhereAreYou.NODE_SEPARATOR + "web", true);
066: // Force the deployment type to use the refreshing method
067: m_WhereAreYou
068: .setCurrentJonasDeploymentType(WhereAreYou.DEPLOYMENT_WAR);
069: // Delete last list if used
070: m_Session.removeAttribute("itemsWebContainersForm");
071:
072: // no Form used
073: try {
074: String p_domainName = m_WhereAreYou.getCurrentDomainName();
075: String p_serverName = m_WhereAreYou
076: .getCurrentJonasServerName();
077:
078: ArrayList al = new ArrayList();
079: ObjectName on;
080: String sPathContext;
081: HashMap hWebAppItems = new HashMap();
082:
083: // Get the list of Catalina contexts
084: if (m_WhereAreYou.isCatalinaServer() == true) {
085: WebAppItem oItem;
086: //String p_serverName = m_WhereAreYou.getAdminJonasServerName();
087: ObjectName onContainers = J2eeObjectName.getWebModules(
088: p_domainName, p_serverName);
089: Iterator itOns = JonasAdminJmx.getListMbean(
090: onContainers, p_serverName).iterator();
091: while (itOns.hasNext()) {
092: ObjectName onWebModule = (ObjectName) itOns.next();
093: oItem = new WebAppItem(onWebModule, m_WhereAreYou
094: .getCurrentCatalinaDefaultHostName());
095: String webModulePath = ((URL) JonasManagementRepr
096: .getAttribute(onWebModule, "warURL",
097: p_serverName)).toString();
098: String sFile = JonasAdminJmx
099: .extractFilename(webModulePath);
100: oItem.setFile(sFile);
101: oItem.setPath(webModulePath);
102: hWebAppItems
103: .put(oItem.getLabelPathContext(), oItem);
104: }
105: } else if (m_WhereAreYou.isJettyServer()) {
106: // Get the list of Jetty contexts
107: Iterator itOnContexts = JonasAdminJmx.getListMbean(
108: JettyObjectName.jettyContexts(p_domainName),
109: p_serverName).iterator();
110: while (itOnContexts.hasNext()) {
111: on = (ObjectName) itOnContexts.next();
112: sPathContext = on.getKeyProperty("context");
113: if (sPathContext != null) {
114: if (!hWebAppItems.containsKey(sPathContext)
115: && on
116: .getKeyProperty("WebApplicationContext") != null
117: && on
118: .getKeyProperty("WebApplicationHandler") == null
119: && on.getKeyProperty("config") == null) {
120: hWebAppItems.put(sPathContext,
121: new WebAppItem(sPathContext, on
122: .toString()));
123: }
124: }
125: }
126:
127: // Get the list of JOnAS War
128: /* This code is only executed with Jetty because the transfere
129: * of management attributes from 'War' MBeans to JettyMBeans is
130: * not done yet
131: */
132: String sPath;
133: String sFile;
134: WebAppItem oWeb;
135: Iterator itOnWars = JonasAdminJmx.getListMbean(
136: JonasObjectName.allWars(), p_serverName)
137: .iterator();
138: while (itOnWars.hasNext()) {
139: on = (ObjectName) itOnWars.next();
140: sPath = on.getKeyProperty("fname");
141: sFile = JonasAdminJmx.extractFilename(sPath);
142: sPathContext = getStringAttribute(on, "ContextRoot");
143: if (sPathContext.charAt(0) != '/') {
144: sPathContext = "/" + sPathContext;
145: }
146: oWeb = (WebAppItem) hWebAppItems.get(sPathContext);
147: if (oWeb != null) {
148: oWeb.setFile(sFile);
149: oWeb.setPath(sPath);
150: }
151: }
152: }
153:
154: // Prepare to display and sort
155: al.addAll(hWebAppItems.values());
156: Collections.sort(al, new WebAppItemByPathContext());
157:
158: // Set list in the request
159: p_Request.setAttribute("listWebContainers", al);
160: } catch (Throwable t) {
161: addGlobalError(t);
162: saveErrors(p_Request, m_Errors);
163: return (p_Mapping.findForward("Global Error"));
164: }
165: // Forward to the jsp.
166: return (p_Mapping.findForward("Web Containers"));
167: }
168: }
|