1 16 17 package org.apache.webapp.admin.valve; 18 19 import java.util.Locale ; 20 import java.io.IOException ; 21 import javax.management.Attribute ; 22 import javax.management.MBeanServer ; 23 import javax.management.MBeanServerFactory ; 24 import javax.management.QueryExp ; 25 import javax.management.Query ; 26 import javax.management.ObjectName ; 27 import javax.management.JMException ; 28 import javax.servlet.ServletException ; 29 import javax.servlet.http.HttpServletRequest ; 30 import javax.servlet.http.HttpServletResponse ; 31 import javax.servlet.http.HttpSession ; 32 import org.apache.struts.action.Action; 33 import org.apache.struts.action.ActionError; 34 import org.apache.struts.action.ActionErrors; 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 import org.apache.webapp.admin.ApplicationServlet; 40 41 48 49 public final class SaveAccessLogValveAction extends Action { 50 51 52 54 57 private MBeanServer mBServer = null; 58 59 61 62 77 public ActionForward execute(ActionMapping mapping, 78 ActionForm form, 79 HttpServletRequest request, 80 HttpServletResponse response) 81 throws IOException , ServletException { 82 83 HttpSession session = request.getSession(); 85 Locale locale = getLocale(request); 86 MessageResources resources = getResources(request); 87 88 try { 90 mBServer = ((ApplicationServlet) getServlet()).getServer(); 91 } catch (Throwable t) { 92 throw new ServletException 93 ("Cannot acquire MBeanServer reference", t); 94 } 95 96 AccessLogValveForm vform = (AccessLogValveForm) form; 98 String adminAction = vform.getAdminAction(); 99 String vObjectName = vform.getObjectName(); 100 String parent = vform.getParentObjectName(); 101 String valveType = vform.getValveType(); 102 103 if ("Create".equals(adminAction)) { 105 106 vObjectName = ValveUtil.createValve(parent, valveType, 107 response, request, mapping, 108 (ApplicationServlet) getServlet()); 109 110 } 111 112 String attribute = null; 114 try { 115 116 ObjectName voname = new ObjectName (vObjectName); 117 118 attribute = "directory"; 119 mBServer.setAttribute(voname, 120 new Attribute ("directory", vform.getDirectory())); 121 attribute = "pattern"; 122 mBServer.setAttribute(voname, 123 new Attribute ("pattern", vform.getPattern())); 124 attribute = "prefix"; 125 mBServer.setAttribute(voname, 126 new Attribute ("prefix", vform.getPrefix())); 127 attribute = "suffix"; 128 mBServer.setAttribute(voname, 129 new Attribute ("suffix", vform.getSuffix())); 130 attribute = "resolveHosts"; 131 mBServer.setAttribute(voname, 132 new Attribute ("resolveHosts", new Boolean (vform.getResolveHosts()))); 133 attribute = "rotatable"; 134 mBServer.setAttribute(voname, 135 new Attribute ("rotatable", new Boolean (vform.getRotatable()))); 136 137 } catch (Exception e) { 138 139 getServlet().log 140 (resources.getMessage(locale, "users.error.attribute.set", 141 attribute), e); 142 response.sendError 143 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 144 resources.getMessage(locale, "users.error.attribute.set", 145 attribute)); 146 return (null); 147 } 148 149 session.removeAttribute(mapping.getAttribute()); 151 return (mapping.findForward("Save Successful")); 152 } 153 } 154 | Popular Tags |