1 16 17 package org.apache.webapp.admin.service; 18 19 import java.io.IOException ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 import java.util.Locale ; 23 import java.util.ArrayList ; 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 import org.apache.struts.util.MessageResources; 34 35 import javax.management.MBeanServer ; 36 import javax.management.ObjectInstance ; 37 import javax.management.ObjectName ; 38 import javax.management.JMException ; 39 40 import org.apache.webapp.admin.ApplicationServlet; 41 import org.apache.webapp.admin.LabelValueBean; 42 import org.apache.webapp.admin.Lists; 43 import org.apache.webapp.admin.TomcatTreeBuilder; 44 45 51 52 public class EditServiceAction extends Action { 53 54 55 58 private MBeanServer mBServer = null; 59 60 61 63 78 public ActionForward execute(ActionMapping mapping, 79 ActionForm form, 80 HttpServletRequest request, 81 HttpServletResponse response) 82 throws IOException , ServletException { 83 84 HttpSession session = request.getSession(); 86 Locale locale = getLocale(request); 87 MessageResources resources = getResources(request); 88 89 try { 91 mBServer = ((ApplicationServlet) getServlet()).getServer(); 92 } catch (Throwable t) { 93 throw new ServletException ![JavaDoc](../../../../../../cmn/javadoc.gif) 94 ("Cannot acquire MBeanServer reference", t); 95 } 96 97 ObjectName sname = null; 99 ObjectName ename = null; 100 StringBuffer sb = null; 101 try { 102 sname = new ObjectName (request.getParameter("select")); 103 } catch (Exception e) { 104 String message = 105 resources.getMessage(locale, "error.serviceName.bad", 106 request.getParameter("select")); 107 getServlet().log(message); 108 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); 109 return (null); 110 } 111 try { 112 sb = new StringBuffer (sname.getDomain()); 113 sb.append(":type=Engine"); 114 ename = new ObjectName (sb.toString()); 115 } catch (Exception e) { 116 String message = 117 resources.getMessage(locale, "error.engineName.bad", 118 sb.toString()); 119 getServlet().log(message); 120 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); 121 return (null); 122 } 123 124 String adminService = null; 125 try { 128 adminService = Lists.getAdminAppService( 129 mBServer, sname.getDomain(),request); 130 } catch (Exception e) { 131 String message = 132 resources.getMessage(locale, "error.serviceName.bad", 133 adminService); 134 getServlet().log(message); 135 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); 136 return (null); 137 } 138 139 140 ServiceForm serviceFm = new ServiceForm(); 142 session.setAttribute("serviceForm", serviceFm); 143 serviceFm.setAdminAction("Edit"); 144 serviceFm.setObjectName(sname.toString()); 145 serviceFm.setEngineObjectName(ename.toString()); 146 sb = new StringBuffer (); 147 sb.append(resources.getMessage(locale, "server.service.treeBuilder.subtreeNode")); 148 sb.append(" ("); 149 sb.append(sname.getKeyProperty("serviceName")); 150 sb.append(")"); 151 serviceFm.setNodeLabel(sb.toString()); 152 serviceFm.setAdminServiceName(adminService); 153 String attribute = null; 154 try { 155 156 attribute = "name"; 158 serviceFm.setServiceName 159 ((String ) mBServer.getAttribute(sname, attribute)); 160 attribute = "name"; 161 serviceFm.setEngineName 162 ((String ) mBServer.getAttribute(ename, attribute)); 163 attribute = "defaultHost"; 164 serviceFm.setDefaultHost 165 ((String ) mBServer.getAttribute(ename, attribute)); 166 167 attribute = "hosts"; 169 ArrayList hosts = new ArrayList (); 170 hosts.add(new LabelValueBean 171 (resources.getMessage(locale, "list.none"), "")); 172 Iterator items = Lists.getHosts(mBServer, sname).iterator(); 173 while (items.hasNext()) { 174 ObjectName hname = new ObjectName ((String ) items.next()); 175 String name = hname.getKeyProperty("host"); 176 if (name!=null) { 177 hosts.add(new LabelValueBean(name, name)); 178 } 179 } 180 serviceFm.setHostNameVals(hosts); 181 182 } catch (Throwable t) { 183 getServlet().log 184 (resources.getMessage(locale, "users.error.attribute.get", 185 attribute), t); 186 response.sendError 187 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 188 resources.getMessage(locale, "users.error.attribute.get", 189 attribute)); 190 return (null); 191 } 192 193 return (mapping.findForward("Service")); 195 196 } 197 198 199 } 200 | Popular Tags |