1 16 17 18 package org.apache.webapp.admin.resources; 19 20 21 import java.io.IOException ; 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 import java.util.Locale ; 25 import javax.servlet.ServletException ; 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 import javax.servlet.http.HttpSession ; 29 import org.apache.struts.action.Action; 30 import org.apache.struts.action.ActionErrors; 31 import org.apache.struts.action.ActionForm; 32 import org.apache.struts.action.ActionForward; 33 import org.apache.struts.action.ActionMapping; 34 import javax.management.Attribute ; 35 import javax.management.MBeanServer ; 36 import javax.management.MBeanServerFactory ; 37 import javax.management.QueryExp ; 38 import javax.management.Query ; 39 import javax.management.ObjectInstance ; 40 import javax.management.ObjectName ; 41 import javax.management.JMException ; 42 import javax.management.MBeanAttributeInfo ; 43 import javax.management.MBeanOperationInfo ; 44 import javax.management.MBeanInfo ; 45 import org.apache.struts.util.MessageResources; 46 import org.apache.webapp.admin.ApplicationServlet; 47 48 49 57 58 public final class DeleteEnvEntriesAction extends Action { 59 60 61 63 64 67 private MBeanServer mserver = null; 68 69 70 72 73 88 public ActionForward execute(ActionMapping mapping, 89 ActionForm form, 90 HttpServletRequest request, 91 HttpServletResponse response) 92 throws IOException , ServletException { 93 94 if (mserver == null) { 96 mserver = ((ApplicationServlet) getServlet()).getServer(); 97 } 98 MessageResources resources = getResources(request); 99 HttpSession session = request.getSession(); 100 Locale locale = getLocale(request); 101 102 if (isCancelled(request)) { 104 return (mapping.findForward("List EnvEntries Setup")); 105 } 106 107 if (!isTokenValid(request)) { 109 response.sendError 110 (HttpServletResponse.SC_BAD_REQUEST, 111 resources.getMessage(locale, "users.error.token")); 112 return (null); 113 } 114 115 EnvEntriesForm envEntriesForm = (EnvEntriesForm) form; 117 String envEntries[] = envEntriesForm.getEnvEntries(); 118 String resourcetype = envEntriesForm.getResourcetype(); 119 String path = envEntriesForm.getPath(); 120 String host = envEntriesForm.getHost(); 121 122 if (envEntries == null) { 123 envEntries = new String [0]; 124 } 125 126 try { 128 ObjectName dname = null; 129 130 String signature[] = new String [1]; 131 signature[0] = "java.lang.String"; 132 Object params[] = new String [1]; 133 134 for (int i = 0; i < envEntries.length; i++) { 135 ObjectName oname = new ObjectName (envEntries[i]); 136 String domain = oname.getDomain(); 137 dname = ResourceUtils.getNamingResourceObjectName(domain, 138 resourcetype, path, host); 139 params[0] = oname.getKeyProperty("name"); 140 mserver.invoke(dname, "removeEnvironment", 141 params, signature); 142 } 143 144 } catch (Throwable t) { 145 146 getServlet().log 147 (resources.getMessage(locale, "users.error.invoke", 148 "removeEnvironment"), t); 149 response.sendError 150 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 151 resources.getMessage(locale, "users.error.invoke", 152 "removeEnvironment")); 153 return (null); 154 155 } 156 157 return (mapping.findForward("EnvEntries List Setup")); 159 160 } 161 162 } 163 | Popular Tags |