public static ActionForward createValve(String parent, String valveType,
HttpServletResponse response, HttpServletRequest request,
ActionMapping mapping, ApplicationServlet servlet)
throws IOException, ServletException {
MessageResources resources = servlet.getResources();
HttpSession session = request.getSession();
MBeanServer mBServer = null;
Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY);
// Acquire a reference to the MBeanServer containing our MBeans
try {
mBServer = servlet.getServer();
} catch (Throwable t) {
throw new ServletException
("Cannot acquire MBeanServer reference", t);
}
String operation = null;
String values[] = null;
try {
String objectName = DeleteLoggerAction.getObjectName(parent,
TomcatTreeBuilder.VALVE_TYPE);
String parentNodeName = parent;
ObjectName pname = new ObjectName(parent);
StringBuffer sb = new StringBuffer(pname.getDomain());
// For service, create the corresponding Engine mBean
// Parent in this case needs to be the container mBean for the service
try {
if ("Service".equalsIgnoreCase(pname.getKeyProperty("type"))) {
sb.append(":type=Engine,service=");
sb.append(pname.getKeyProperty("name"));
parent = sb.toString();
}
} catch (Exception e) {
String message =
resources.getMessage("error.engineName.bad",
sb.toString());
servlet.log(message);
response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
return (null);
}
// Ensure that the requested valve name is unique
// TBD -- do we need this check?
/*
ObjectName oname =
new ObjectName(objectName);
if (mBServer.isRegistered(oname)) {
ActionErrors errors = new ActionErrors();
errors.add("valveName",
new ActionError("error.valveName.exists"));
String message =
resources.getMessage("error.valveName.exists", sb.toString());
response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
return (new ActionForward(mapping.getInput()));
}
*/
// Look up our MBeanFactory MBean
ObjectName fname =
new ObjectName(TomcatTreeBuilder.FACTORY_TYPE);
// Create a new StandardValve object
values = new String[1];
values[0] = parent;
operation = "create" + valveType;
if ("AccessLogValve".equalsIgnoreCase(valveType))
operation = "createAccessLoggerValve";
String vObjectName = (String)
mBServer.invoke(fname, operation, values, createStandardValveTypes);
// Add the new Valve to our tree control node
TreeControl control = (TreeControl)
session.getAttribute("treeControlTest");
if (control != null) {
TreeControlNode parentNode = control.findNode(parentNodeName);
if (parentNode != null) {
String nodeLabel =
"Valve for " + parentNode.getLabel();
String encodedName =
URLEncoder.encode(vObjectName);
TreeControlNode childNode =
new TreeControlNode(vObjectName,
"Valve.gif",
nodeLabel,
"EditValve.do?select=" + encodedName +
"&nodeLabel=" + URLEncoder.encode(nodeLabel) +
"&parent=" + URLEncoder.encode(parentNodeName),
"content",
true);
parentNode.addChild(childNode);
// FIXME - force a redisplay
} else {
servlet.log
("Cannot find parent node '" + parentNodeName + "'");
}
} else {
servlet.log
("Cannot find TreeControlNode!");
}
} catch (Exception e) {
servlet.log
(resources.getMessage(locale, "users.error.invoke",
operation), e);
response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
resources.getMessage(locale, "users.error.invoke",
operation));
return (null);
}