1 16 17 18 package org.apache.webapp.admin.context; 19 20 import java.io.IOException ; 21 import java.util.Locale ; 22 import javax.management.MBeanServer ; 23 import javax.management.ObjectName ; 24 import javax.servlet.ServletException ; 25 import javax.servlet.http.HttpSession ; 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 import org.apache.struts.action.Action; 29 import org.apache.struts.action.ActionForm; 30 import org.apache.struts.action.ActionForward; 31 import org.apache.struts.action.ActionMapping; 32 import org.apache.struts.util.MessageResources; 33 34 import org.apache.webapp.admin.ApplicationServlet; 35 import org.apache.webapp.admin.TomcatTreeBuilder; 36 import org.apache.webapp.admin.TreeControl; 37 import org.apache.webapp.admin.TreeControlNode; 38 39 40 47 48 public class DeleteContextsAction extends Action { 49 50 51 54 private String removeContextTypes[] = 55 { "java.lang.String", }; 57 58 59 62 private MBeanServer mBServer = null; 63 64 65 67 68 83 public ActionForward execute(ActionMapping mapping, 84 ActionForm form, 85 HttpServletRequest request, 86 HttpServletResponse response) 87 throws IOException , ServletException { 88 89 90 HttpSession session = request.getSession(); 92 Locale locale = getLocale(request); 93 MessageResources resources = getResources(request); 94 95 try { 97 mBServer = ((ApplicationServlet) getServlet()).getServer(); 98 } catch (Throwable t) { 99 throw new ServletException 100 ("Cannot acquire MBeanServer reference", t); 101 } 102 103 String contexts[] = ((ContextsForm) form).getContexts(); 105 String values[] = new String [1]; 106 String operation = "removeContext"; 107 108 try { 109 110 TreeControl control = (TreeControl) 112 session.getAttribute("treeControlTest"); 113 114 for (int i = 0; i < contexts.length; i++) { 116 values[0] = contexts[i]; 117 if (control != null) { 118 control.selectNode(null); 119 TreeControlNode node = control.findNode(contexts[i]); 120 String domain = node.getDomain(); 121 ObjectName fname = TomcatTreeBuilder.getMBeanFactory(); 122 mBServer.invoke(fname, operation, 123 values, removeContextTypes); 124 if (node != null) { 125 node.remove(); 126 } else { 127 getServlet().log("Missing TreeControlNode for " + 128 contexts[i]); 129 } 130 } else { 131 getServlet().log("Missing TreeControl attribute"); 132 } 133 } 134 135 } catch (Exception e) { 136 getServlet().log 137 (resources.getMessage(locale, "users.error.invoke", 138 operation), e); 139 response.sendError 140 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 141 resources.getMessage(locale, "users.error.invoke", 142 operation)); 143 return (null); 144 145 } 146 147 return (mapping.findForward("Save Successful")); 149 150 } 151 152 } 153 | Popular Tags |