1 16 17 18 package org.apache.webapp.admin.resources; 19 20 import java.io.IOException ; 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.Locale ; 24 import javax.servlet.ServletException ; 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.http.HttpServletResponse ; 27 import javax.servlet.http.HttpSession ; 28 import org.apache.struts.action.Action; 29 import org.apache.struts.action.ActionErrors; 30 import org.apache.struts.action.ActionForm; 31 import org.apache.struts.action.ActionForward; 32 import org.apache.struts.action.ActionMapping; 33 import javax.management.Attribute ; 34 import javax.management.MBeanServer ; 35 import javax.management.MBeanServerFactory ; 36 import javax.management.QueryExp ; 37 import javax.management.Query ; 38 import javax.management.ObjectInstance ; 39 import javax.management.ObjectName ; 40 import javax.management.JMException ; 41 import javax.management.MBeanAttributeInfo ; 42 import javax.management.MBeanOperationInfo ; 43 import javax.management.MBeanInfo ; 44 import org.apache.struts.util.MessageResources; 45 import org.apache.webapp.admin.ApplicationServlet; 46 47 48 56 57 public final class DeleteResourceLinksAction extends Action { 58 59 60 62 63 66 private MBeanServer mserver = null; 67 68 69 71 72 87 public ActionForward execute(ActionMapping mapping, 88 ActionForm form, 89 HttpServletRequest request, 90 HttpServletResponse response) 91 throws IOException , ServletException { 92 93 if (mserver == null) { 95 mserver = ((ApplicationServlet) getServlet()).getServer(); 96 } 97 MessageResources resources = getResources(request); 98 HttpSession session = request.getSession(); 99 Locale locale = getLocale(request); 100 101 if (isCancelled(request)) { 103 return (mapping.findForward("List Resource Links Setup")); 104 } 105 106 if (!isTokenValid(request)) { 108 response.sendError 109 (HttpServletResponse.SC_BAD_REQUEST, 110 resources.getMessage(locale, "users.error.token")); 111 return (null); 112 } 113 114 ResourceLinksForm resourceLinksForm = (ResourceLinksForm) form; 116 String resourceLinks[] = resourceLinksForm.getResourceLinks(); 117 if (resourceLinks == null) { 118 resourceLinks = new String [0]; 119 } 120 121 try { 123 124 String resourcetype = resourceLinksForm.getResourcetype(); 125 String path = resourceLinksForm.getPath(); 126 String host = resourceLinksForm.getHost(); 127 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 < resourceLinks.length; i++) { 135 ObjectName oname = new ObjectName (resourceLinks[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, "removeResourceLink", 141 params, signature); 142 } 143 144 } catch (Throwable t) { 145 146 getServlet().log 147 (resources.getMessage(locale, "users.error.invoke", 148 "removeResource"), t); 149 response.sendError 150 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 151 resources.getMessage(locale, "users.error.invoke", 152 "removeResource")); 153 return (null); 154 155 } 156 157 return (mapping.findForward("ResourceLinks List Setup")); 159 160 } 161 162 } 163 | Popular Tags |