1 16 17 package org.apache.webapp.admin.context; 18 19 import java.io.IOException ; 20 import java.util.Locale ; 21 import javax.servlet.ServletException ; 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 24 import javax.servlet.http.HttpSession ; 25 import org.apache.struts.action.Action; 26 import org.apache.struts.action.ActionForm; 27 import org.apache.struts.action.ActionForward; 28 import org.apache.struts.action.ActionMapping; 29 import org.apache.struts.util.MessageResources; 30 31 import javax.management.MBeanServer ; 32 import javax.management.ObjectName ; 33 34 import org.apache.webapp.admin.ApplicationServlet; 35 import org.apache.webapp.admin.Lists; 36 37 43 44 public class EditContextAction extends Action { 45 46 47 50 private MBeanServer mBServer = null; 51 52 53 55 70 public ActionForward execute(ActionMapping mapping, 71 ActionForm form, 72 HttpServletRequest request, 73 HttpServletResponse response) 74 throws IOException , ServletException { 75 76 HttpSession session = request.getSession(); 78 Locale locale = getLocale(request); 79 MessageResources resources = getResources(request); 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 ObjectName cname = null; 92 ObjectName lname = null; 94 ObjectName mname = null; 96 97 StringBuffer sb = null; 98 try { 99 cname = new ObjectName (request.getParameter("select")); 100 } catch (Exception e) { 101 String message = 102 resources.getMessage(locale, "error.contextName.bad", 103 request.getParameter("select")); 104 getServlet().log(message); 105 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); 106 return (null); 107 } 108 String name = cname.getKeyProperty("name"); 109 name = name.substring(2); 110 int i = name.indexOf("/"); 111 String host = name.substring(0,i); 112 String path = name.substring(i); 113 try { 115 sb = new StringBuffer (cname.getDomain()); 116 sb.append(":type=Loader"); 117 sb.append(",path="+path); 118 sb.append(",host="+host); 119 lname = new ObjectName (sb.toString()); 120 } catch (Exception e) { 121 String message = 122 resources.getMessage(locale, "error.managerName.bad", 123 sb.toString()); 124 getServlet().log(message); 125 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); 126 return (null); 127 } 128 129 try { 132 sb = new StringBuffer (cname.getDomain()); 133 sb.append(":type=Manager"); 134 sb.append(",path="+path); 135 sb.append(",host="+host); 136 mname = new ObjectName (sb.toString()); 137 } catch (Exception e) { 138 String message = 139 resources.getMessage("error.managerName.bad", 140 sb.toString()); 141 getServlet().log(message); 142 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); 143 return (null); 144 } 145 146 ContextForm contextFm = new ContextForm(); 148 session.setAttribute("contextForm", contextFm); 149 contextFm.setAdminAction("Edit"); 150 contextFm.setObjectName(cname.toString()); 151 contextFm.setLoaderObjectName(lname.toString()); 152 contextFm.setManagerObjectName(mname.toString()); 153 sb = new StringBuffer (); 154 sb.append(resources.getMessage(locale, "server.service.treeBuilder.context")); 155 sb.append(" ("); 156 sb.append(path); 157 sb.append(")"); 158 contextFm.setNodeLabel(sb.toString()); 159 contextFm.setBooleanVals(Lists.getBooleanValues()); 160 161 String attribute = null; 162 try { 163 164 attribute = "path"; 166 contextFm.setPath 167 ((String ) mBServer.getAttribute(cname, attribute)); 168 attribute = "cookies"; 169 contextFm.setCookies 170 (((Boolean ) mBServer.getAttribute(cname, attribute)).toString()); 171 attribute = "crossContext"; 172 contextFm.setCrossContext 173 (((Boolean ) mBServer.getAttribute(cname, attribute)).toString()); 174 attribute = "docBase"; 175 contextFm.setDocBase 176 ((String ) mBServer.getAttribute(cname, attribute)); 177 attribute = "workDir"; 178 contextFm.setWorkDir 179 ((String ) mBServer.getAttribute(cname, attribute)); 180 attribute = "useNaming"; 181 contextFm.setUseNaming 182 (((Boolean ) mBServer.getAttribute(cname, attribute)).toString()); 183 attribute = "reloadable"; 184 contextFm.setReloadable 185 (((Boolean ) mBServer.getAttribute(cname, attribute)).toString()); 186 attribute = "swallowOutput"; 187 contextFm.setSwallowOutput 188 (((Boolean ) mBServer.getAttribute(cname, attribute)).toString()); 189 attribute = "override"; 190 contextFm.setOverride 191 (((Boolean ) mBServer.getAttribute(cname, attribute)).toString()); 192 attribute = "privileged"; 193 contextFm.setPrivileged 194 (((Boolean ) mBServer.getAttribute(cname, attribute)).toString()); 195 196 attribute = "antiJARLocking"; 197 contextFm.setAntiJarLocking 198 (((Boolean ) mBServer.getAttribute(cname, attribute)).toString()); 199 attribute = "antiResourceLocking"; 200 contextFm.setAntiResourceLocking 201 (((Boolean ) mBServer.getAttribute(cname, attribute)).toString()); 202 attribute = "reloadable"; 207 contextFm.setLdrReloadable 208 (((Boolean ) mBServer.getAttribute(lname, attribute)).toString()); 209 210 attribute = "entropy"; 212 contextFm.setMgrSessionIDInit 213 ((String ) mBServer.getAttribute(mname, attribute)); 214 attribute = "maxActiveSessions"; 215 contextFm.setMgrMaxSessions 216 (((Integer ) mBServer.getAttribute(mname, attribute)).toString()); 217 221 } catch (Throwable t) { 222 getServlet().log 223 (resources.getMessage(locale, "users.error.attribute.get", 224 attribute), t); 225 response.sendError 226 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 227 resources.getMessage(locale, "users.error.attribute.get", 228 attribute)); 229 return (null); 230 } 231 232 return (mapping.findForward("Context")); 234 235 } 236 237 238 } 239 | Popular Tags |