1 16 17 package org.apache.webapp.admin.host; 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.Arrays ; 24 import java.util.ArrayList ; 25 import javax.servlet.ServletException ; 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 import javax.servlet.http.HttpSession ; 29 import org.apache.struts.action.Action; 30 import org.apache.struts.action.ActionErrors; 31 import org.apache.struts.action.ActionForm; 32 import org.apache.struts.action.ActionForward; 33 import org.apache.struts.action.ActionMapping; 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 import org.apache.webapp.admin.ApplicationServlet; 42 import org.apache.webapp.admin.LabelValueBean; 43 import org.apache.webapp.admin.Lists; 44 import org.apache.webapp.admin.TomcatTreeBuilder; 45 46 52 53 public class EditHostAction extends Action { 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 94 ("Cannot acquire MBeanServer reference", t); 95 } 96 97 ObjectName hname = null; 99 StringBuffer sb = null; 100 try { 101 hname = new ObjectName (request.getParameter("select")); 102 } catch (Exception e) { 103 String message = 104 resources.getMessage(locale, "error.hostName.bad", 105 request.getParameter("select")); 106 getServlet().log(message); 107 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); 108 return (null); 109 } 110 111 String adminHost = null; 112 String domain = hname.getDomain(); 113 try { 116 adminHost = Lists.getAdminAppHost( 117 mBServer, domain ,request); 118 } catch (Exception e) { 119 String message = 120 resources.getMessage(locale, "error.hostName.bad", 121 adminHost); 122 getServlet().log(message); 123 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); 124 return (null); 125 } 126 request.setAttribute("adminAppHost", adminHost); 127 128 HostForm hostFm = new HostForm(); 130 session.setAttribute("hostForm", hostFm); 131 hostFm.setAdminAction("Edit"); 132 hostFm.setObjectName(hname.toString()); 133 sb = new StringBuffer (); 134 sb.append(resources.getMessage(locale, "server.service.treeBuilder.host")); 135 sb.append(" ("); 136 sb.append(hname.getKeyProperty("host")); 137 sb.append(")"); 138 hostFm.setNodeLabel(sb.toString()); 139 hostFm.setBooleanVals(Lists.getBooleanValues()); 140 141 String attribute = null; 142 try { 143 144 attribute = "name"; 146 hostFm.setHostName 147 ((String ) mBServer.getAttribute(hname, attribute)); 148 149 attribute = "appBase"; 150 hostFm.setAppBase 151 ((String ) mBServer.getAttribute(hname, attribute)); 152 attribute = "autoDeploy"; 153 hostFm.setAutoDeploy 154 (((Boolean ) mBServer.getAttribute(hname, attribute)).toString()); 155 attribute = "deployXML"; 156 hostFm.setDeployXML 157 (((Boolean ) mBServer.getAttribute(hname, attribute)).toString()); 158 attribute = "deployOnStartup"; 159 hostFm.setDeployOnStartup 160 (((Boolean ) mBServer.getAttribute(hname, attribute)).toString()); 161 attribute = "unpackWARs"; 162 hostFm.setUnpackWARs 163 (((Boolean ) mBServer.getAttribute(hname, attribute)).toString()); 164 attribute = "xmlNamespaceAware"; 165 hostFm.setXmlNamespaceAware 166 (((Boolean ) mBServer.getAttribute(hname, attribute)).toString()); 167 attribute = "xmlValidation"; 168 hostFm.setXmlValidation 169 (((Boolean ) mBServer.getAttribute(hname, attribute)).toString()); 170 171 } catch (Throwable t) { 172 getServlet().log 173 (resources.getMessage(locale, "users.error.attribute.get", 174 attribute), t); 175 response.sendError 176 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 177 resources.getMessage(locale, "users.error.attribute.get", 178 attribute)); 179 return (null); 180 } 181 182 String operation = null; 184 try { 185 operation = "findAliases"; 186 String aliases[] = 187 (String []) mBServer.invoke(hname, operation, null, null); 188 189 hostFm.setAliasVals(new ArrayList (Arrays.asList(aliases))); 190 191 } catch (Throwable t) { 192 getServlet().log 193 (resources.getMessage(locale, "users.error.invoke", 194 operation), t); 195 response.sendError 196 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 197 resources.getMessage(locale, "users.error.invoke", 198 operation)); 199 return (null); 200 } 201 202 return (mapping.findForward("Host")); 204 205 } 206 } 207 | Popular Tags |