1 16 17 package org.apache.webapp.admin.host; 18 19 import java.net.URLEncoder ; 20 import java.util.Iterator ; 21 import java.util.Locale ; 22 import java.util.List ; 23 import java.io.IOException ; 24 import javax.management.Attribute ; 25 import javax.management.MBeanServer ; 26 import javax.management.MBeanServerFactory ; 27 import javax.management.QueryExp ; 28 import javax.management.Query ; 29 import javax.management.ObjectInstance ; 30 import javax.management.ObjectName ; 31 import javax.management.JMException ; 32 import javax.servlet.ServletException ; 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 import javax.servlet.http.HttpSession ; 36 import org.apache.struts.action.Action; 37 import org.apache.struts.action.ActionError; 38 import org.apache.struts.action.ActionErrors; 39 import org.apache.struts.action.ActionForm; 40 import org.apache.struts.action.ActionForward; 41 import org.apache.struts.action.ActionMapping; 42 import org.apache.struts.util.MessageResources; 43 import org.apache.webapp.admin.ApplicationServlet; 44 import org.apache.webapp.admin.TomcatTreeBuilder; 45 import org.apache.webapp.admin.TreeControl; 46 import org.apache.webapp.admin.TreeControlNode; 47 48 49 50 57 58 public final class SaveAliasAction extends Action { 59 60 61 63 66 private String createStandardAliasTypes[] = 67 { "java.lang.String", }; 69 70 73 private MBeanServer mBServer = null; 74 75 76 78 79 94 public ActionForward execute(ActionMapping mapping, 95 ActionForm form, 96 HttpServletRequest request, 97 HttpServletResponse response) 98 throws IOException , ServletException { 99 100 HttpSession session = request.getSession(); 102 Locale locale = getLocale(request); 103 MessageResources resources = getResources(request); 104 105 try { 107 mBServer = ((ApplicationServlet) getServlet()).getServer(); 108 } catch (Throwable t) { 109 throw new ServletException 110 ("Cannot acquire MBeanServer reference", t); 111 } 112 113 AliasForm aform = (AliasForm) form; 115 116 String operation = "addAlias"; 118 119 Object values[] = new String [1]; 121 values[0] = aform.getAliasName(); 122 123 String hostName = aform.getHostName(); 124 125 List aliasVals = aform.getAliasVals(); 127 if (aliasVals.contains(values[0])) { 128 ActionErrors errors = new ActionErrors(); 129 errors.add("aliasName", 130 new ActionError("error.aliasName.exists")); 131 saveErrors(request, errors); 132 return (new ActionForward(mapping.getInput())); 133 } 134 135 try { 136 137 ObjectName hname = new ObjectName (hostName); 138 mBServer.invoke(hname, operation, values, createStandardAliasTypes); 139 140 } catch (Throwable t) { 141 getServlet().log 142 (resources.getMessage(locale, "users.error.invoke", 143 operation), t); 144 response.sendError 145 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 146 resources.getMessage(locale, "users.error.invoke", 147 operation)); 148 return (null); 149 } 150 151 session.removeAttribute(mapping.getAttribute()); 153 return (mapping.findForward("Save Successful")); 154 155 } 156 157 } 158 | Popular Tags |