1 16 17 18 package org.apache.webapp.admin.host; 19 20 import java.io.IOException ; 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.Locale ; 24 import java.util.Set ; 25 import java.util.TreeSet ; 26 import javax.management.MBeanServer ; 27 import javax.management.ObjectName ; 28 import javax.management.ObjectInstance ; 29 import javax.management.modelmbean.ModelMBean ; 30 import javax.servlet.ServletException ; 31 import javax.servlet.http.HttpSession ; 32 import javax.servlet.http.HttpServletRequest ; 33 import javax.servlet.http.HttpServletResponse ; 34 import org.apache.struts.action.Action; 35 import org.apache.struts.action.ActionForm; 36 import org.apache.struts.action.ActionForward; 37 import org.apache.struts.action.ActionMapping; 38 import org.apache.struts.util.MessageResources; 39 40 import org.apache.webapp.admin.ApplicationServlet; 41 import org.apache.webapp.admin.TomcatTreeBuilder; 42 import org.apache.webapp.admin.TreeControl; 43 import org.apache.webapp.admin.TreeControlNode; 44 45 46 53 54 public class DeleteHostsAction extends Action { 55 56 57 60 private String removeHostTypes[] = 61 { "java.lang.String", }; 63 64 65 68 private MBeanServer mBServer = null; 69 70 71 73 74 89 public ActionForward execute(ActionMapping mapping, 90 ActionForm form, 91 HttpServletRequest request, 92 HttpServletResponse response) 93 throws IOException , ServletException { 94 95 96 HttpSession session = request.getSession(); 98 Locale locale = getLocale(request); 99 MessageResources resources = getResources(request); 100 101 try { 103 mBServer = ((ApplicationServlet) getServlet()).getServer(); 104 } catch (Throwable t) { 105 throw new ServletException 106 ("Cannot acquire MBeanServer reference", t); 107 } 108 109 String hosts[] = ((HostsForm) form).getHosts(); 111 String values[] = new String [1]; 112 String operation = "removeHost"; 113 114 getServlet().log("enter DeleteHosts " + hosts); 115 116 try { 117 118 TreeControl control = (TreeControl) 120 session.getAttribute("treeControlTest"); 121 122 for (int i = 0; i < hosts.length; i++) { 124 values[0] = hosts[i]; 125 getServlet().log("remove host " + hosts[i]); 126 if (control != null) { 127 control.selectNode(null); 128 TreeControlNode node = control.findNode(hosts[i]); 129 String domain = node.getDomain(); 130 ObjectName fname = TomcatTreeBuilder.getMBeanFactory(); 131 mBServer.invoke(fname, operation, 132 values, removeHostTypes); 133 if (node != null) { 134 node.remove(); 135 } else { 136 getServlet().log("Missing TreeControlNode for " + 137 hosts[i]); 138 } 139 } else { 140 getServlet().log("Missing TreeControl attribute"); 141 } 142 } 143 144 } catch (Exception e) { 145 getServlet().log 146 (resources.getMessage(locale, "users.error.invoke", 147 operation), e); 148 response.sendError 149 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 150 resources.getMessage(locale, "users.error.invoke", 151 operation)); 152 return (null); 153 154 } 155 156 return (mapping.findForward("Save Successful")); 158 159 } 160 161 } 162 | Popular Tags |