1 16 17 package org.apache.webapp.admin; 18 19 20 import java.io.IOException ; 21 import java.util.Iterator ; 22 import java.util.List ; 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 34 import org.apache.struts.util.MessageResources; 35 36 import javax.management.MBeanServer ; 37 import javax.management.ObjectInstance ; 38 import javax.management.ObjectName ; 39 import javax.management.JMException ; 40 41 48 49 public final class CommitChangesAction extends Action { 50 51 54 private MBeanServer mBServer = null; 55 56 57 59 60 75 public ActionForward execute(ActionMapping mapping, 76 ActionForm form, 77 HttpServletRequest request, 78 HttpServletResponse response) 79 throws IOException , ServletException { 80 81 try { 83 mBServer = ((ApplicationServlet) getServlet()).getServer(); 84 } catch (Throwable t) { 85 throw new ServletException 86 ("Cannot acquire MBeanServer reference", t); 87 } 88 89 HttpSession session = request.getSession(); 91 Locale locale = getLocale(request); 92 MessageResources resources = getResources(request); 93 94 ObjectName sname = null; 95 try { 96 sname = new ObjectName (TomcatTreeBuilder.DEFAULT_DOMAIN + 97 TomcatTreeBuilder.SERVER_TYPE); 98 } catch (Exception e) { 99 String message = "Could not get Server Object"; 100 getServlet().log(message); 101 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); 102 return (null); 103 } 104 105 String operation = "storeConfig"; 106 try { 107 mBServer.invoke(sname, operation, null, null); 108 } catch (Throwable t) { 109 getServlet().log 110 (resources.getMessage(locale, "users.error.invoke", 111 operation), t); 112 response.sendError 113 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 114 resources.getMessage(locale, "users.error.invoke", 115 operation)); 116 return (null); 117 } 118 119 120 getServlet().log("Debugging -- changes saved to conf/server.xml"); 121 return (mapping.findForward("Banner")); 123 124 } 125 126 127 } 128 | Popular Tags |