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 42 49 50 public class DeleteAliasesAction extends Action { 51 52 53 56 private String removeAliasTypes[] = 57 { "java.lang.String", }; 59 60 61 64 private MBeanServer mBServer = null; 65 66 67 69 70 85 public ActionForward execute(ActionMapping mapping, 86 ActionForm form, 87 HttpServletRequest request, 88 HttpServletResponse response) 89 throws IOException , ServletException { 90 91 92 HttpSession session = request.getSession(); 94 Locale locale = getLocale(request); 95 MessageResources resources = getResources(request); 96 97 try { 99 mBServer = ((ApplicationServlet) getServlet()).getServer(); 100 } catch (Throwable t) { 101 throw new ServletException 102 ("Cannot acquire MBeanServer reference", t); 103 } 104 105 AliasesForm aliasesFm = (AliasesForm) form; 106 String hostName = aliasesFm.getHostName(); 108 109 String aliases[] = aliasesFm.getAliases(); 111 String values[] = new String [1]; 112 String operation = "removeAlias"; 113 114 try { 115 116 ObjectName hname = new ObjectName (hostName); 117 118 for (int i = 0; i < aliases.length; i++) { 120 values[0] = aliases[i]; 121 mBServer.invoke(hname, operation, values, removeAliasTypes); 122 } 123 124 } catch (Exception e) { 125 getServlet().log 126 (resources.getMessage(locale, "users.error.invoke", 127 operation), e); 128 response.sendError 129 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 130 resources.getMessage(locale, "users.error.invoke", 131 operation)); 132 return (null); 133 134 } 135 136 return (mapping.findForward("Save Successful")); 138 139 } 140 141 } 142 | Popular Tags |