1 16 17 18 package org.apache.webapp.admin.host; 19 20 import java.io.IOException ; 21 import java.util.Collections ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.Locale ; 25 import java.util.TreeSet ; 26 import java.util.Set ; 27 import java.util.ArrayList ; 28 import javax.servlet.ServletException ; 29 import javax.servlet.http.HttpServletRequest ; 30 import javax.servlet.http.HttpServletResponse ; 31 import javax.servlet.http.HttpSession ; 32 import org.apache.struts.action.Action; 33 import org.apache.struts.action.ActionErrors; 34 import org.apache.struts.action.ActionForm; 35 import org.apache.struts.action.ActionForward; 36 import org.apache.struts.action.ActionMapping; 37 38 import javax.management.MBeanServer ; 39 import javax.management.MBeanServerFactory ; 40 import javax.management.QueryExp ; 41 import javax.management.Query ; 42 import javax.management.ObjectInstance ; 43 import javax.management.ObjectName ; 44 import javax.management.JMException ; 45 import org.apache.struts.util.MessageResources; 46 47 import org.apache.webapp.admin.ApplicationServlet; 48 import org.apache.webapp.admin.Lists; 49 import org.apache.webapp.admin.TomcatTreeBuilder; 50 51 57 58 public class DeleteHostAction extends Action { 59 60 61 64 private MBeanServer mBServer = null; 65 66 67 69 84 public ActionForward execute(ActionMapping mapping, 85 ActionForm form, 86 HttpServletRequest request, 87 HttpServletResponse response) 88 throws IOException , ServletException { 89 90 91 HttpSession session = request.getSession(); 93 Locale locale = getLocale(request); 94 MessageResources resources = getResources(request); 95 96 try { 98 mBServer = ((ApplicationServlet) getServlet()).getServer(); 99 } catch (Throwable t) { 100 throw new ServletException 101 ("Cannot acquire MBeanServer reference", t); 102 } 103 104 HostsForm hostsForm = new HostsForm(); 107 String select = request.getParameter("select"); 108 String domain = null; 109 if (select != null) { 110 String hosts[] = new String [1]; 111 hosts[0] = select; 112 hostsForm.setHosts(hosts); 113 114 try { 115 domain = (new ObjectName (select)).getDomain(); 116 } catch (Exception e) { 117 throw new ServletException 118 ("Error extracting service name from the host to be deleted", e); 119 } 120 } 121 String adminHost = null; 122 try { 125 adminHost = Lists.getAdminAppHost( 126 mBServer, "domain" ,request); 127 } catch (Exception e) { 128 String message = 129 resources.getMessage(locale, "error.hostName.bad", 130 adminHost); 131 getServlet().log(message); 132 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); 133 return (null); 134 } 135 request.setAttribute("adminAppHost", adminHost); 136 request.setAttribute("hostsForm", hostsForm); 137 138 ArrayList list = new ArrayList (); 140 try { 141 String pattern = domain + TomcatTreeBuilder.HOST_TYPE + 142 TomcatTreeBuilder.WILDCARD; 143 Iterator items = 144 mBServer.queryNames(new ObjectName (pattern), null).iterator(); 145 while (items.hasNext()) { 146 list.add(items.next().toString()); 147 } 148 } catch (Exception e) { 149 getServlet().log 150 (resources.getMessage(locale, "users.error.select")); 151 response.sendError 152 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 153 resources.getMessage(locale, "users.error.select")); 154 return (null); 155 } 156 Collections.sort(list); 157 request.setAttribute("hostsList", list); 158 159 return (mapping.findForward("Hosts")); 161 162 } 163 164 } 165 | Popular Tags |