1 16 17 18 package org.apache.webapp.admin.connector; 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 DeleteConnectorsAction extends Action { 55 56 57 60 private String removeConnectorTypes[] = 61 { "java.lang.String", }; 63 64 65 68 private MBeanServer mBServer = null; 69 70 71 72 74 75 90 public ActionForward execute(ActionMapping mapping, 91 ActionForm form, 92 HttpServletRequest request, 93 HttpServletResponse response) 94 throws IOException , ServletException { 95 96 97 HttpSession session = request.getSession(); 99 Locale locale = getLocale(request); 100 MessageResources resources = getResources(request); 101 102 try { 104 mBServer = ((ApplicationServlet) getServlet()).getServer(); 105 } catch (Throwable t) { 106 throw new ServletException 107 ("Cannot acquire MBeanServer reference", t); 108 } 109 110 String connectors[] = ((ConnectorsForm) form).getConnectors(); 112 String values[] = new String [1]; 113 String operation = "removeConnector"; 114 try { 115 116 TreeControl control = (TreeControl) 118 session.getAttribute("treeControlTest"); 119 120 ObjectName fname = null; 122 String domain = null; 123 TreeControlNode node = null; 124 125 for (int i = 0; i < connectors.length; i++) { 127 values[0] = connectors[i]; 128 if (control != null) { 129 control.selectNode(null); 130 node = control.findNode(connectors[i]); 131 domain = node.getDomain(); 132 fname = TomcatTreeBuilder.getMBeanFactory(); 134 mBServer.invoke(fname, operation, 135 values, removeConnectorTypes); 136 if (node != null) { 137 node.remove(); 138 } else { 139 getServlet().log("Missing TreeControlNode for " + 140 connectors[i]); 141 } 142 } else { 143 getServlet().log("Missing TreeControl attribute"); 144 } 145 } 146 147 } catch (Exception e) { 148 149 getServlet().log 150 (resources.getMessage(locale, "users.error.invoke", 151 operation), e); 152 response.sendError 153 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 154 resources.getMessage(locale, "users.error.invoke", 155 operation)); 156 return (null); 157 158 } 159 160 return (mapping.findForward("Save Successful")); 162 163 } 164 165 } 166 | Popular Tags |