1 16 17 package org.apache.webapp.admin.connector; 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 EditConnectorAction 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 94 ("Cannot acquire MBeanServer reference", t); 95 } 96 97 ObjectName cname = null; 99 StringBuffer sb = null; 100 try { 101 cname = new ObjectName (request.getParameter("select")); 102 } catch (Exception e) { 103 String message = 104 resources.getMessage(locale, "error.connectorName.bad", 105 request.getParameter("select")); 106 getServlet().log(message); 107 response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); 108 return (null); 109 } 110 111 ConnectorForm connectorFm = new ConnectorForm(); 113 session.setAttribute("connectorForm", connectorFm); 114 connectorFm.setAdminAction("Edit"); 115 connectorFm.setObjectName(cname.toString()); 116 sb = new StringBuffer (); 117 sb.append(resources.getMessage(locale, "server.service.treeBuilder.connector")); 118 sb.append(" ("); 119 sb.append(cname.getKeyProperty("port")); 120 sb.append(")"); 121 connectorFm.setNodeLabel(sb.toString()); 122 connectorFm.setBooleanVals(Lists.getBooleanValues()); 123 connectorFm.setClientAuthVals(Lists.getClientAuthValues()); 124 125 String attribute = null; 126 try { 127 128 attribute = "scheme"; 131 String scheme = (String ) mBServer.getAttribute(cname, attribute); 132 connectorFm.setScheme(scheme); 133 134 attribute = "protocolHandlerClassName"; 135 String handlerClassName = 136 (String ) mBServer.getAttribute(cname, attribute); 137 int period = handlerClassName.lastIndexOf('.'); 138 String connType = handlerClassName.substring(period + 1); 139 String connectorType = "HTTPS"; 140 if ("JkCoyoteHandler".equalsIgnoreCase(connType)) { 141 connectorType = "AJP"; 142 } else if ("Http11Protocol".equalsIgnoreCase(connType) && 143 ("http".equalsIgnoreCase(scheme))) { 144 connectorType = "HTTP"; 145 } 146 connectorFm.setConnectorType(connectorType); 147 148 attribute = "acceptCount"; 149 connectorFm.setAcceptCountText 150 (String.valueOf(mBServer.getAttribute(cname, attribute))); 151 attribute = "compression"; 152 connectorFm.setCompression 153 ((String ) mBServer.getAttribute(cname, attribute)); 154 attribute = "connectionLinger"; 155 connectorFm.setConnLingerText 156 (String.valueOf(mBServer.getAttribute(cname, attribute))); 157 attribute = "connectionTimeout"; 158 connectorFm.setConnTimeOutText 159 (String.valueOf(mBServer.getAttribute(cname, attribute))); 160 attribute = "connectionUploadTimeout"; 161 connectorFm.setConnUploadTimeOutText 162 (String.valueOf(mBServer.getAttribute(cname, attribute))); 163 attribute = "disableUploadTimeout"; 164 connectorFm.setDisableUploadTimeout 165 (String.valueOf(mBServer.getAttribute(cname, attribute))); 166 attribute = "bufferSize"; 167 connectorFm.setBufferSizeText 168 (String.valueOf(mBServer.getAttribute(cname, attribute))); 169 attribute = "enableLookups"; 170 connectorFm.setEnableLookups 171 (String.valueOf(mBServer.getAttribute(cname, attribute))); 172 attribute = "address"; 173 connectorFm.setAddress 174 ((String ) mBServer.getAttribute(cname, attribute)); 175 attribute = "maxKeepAliveRequests"; 176 connectorFm.setMaxKeepAliveText 177 (String.valueOf(mBServer.getAttribute(cname, attribute))); 178 attribute = "maxSpareThreads"; 179 connectorFm.setMaxSpare 180 (String.valueOf(mBServer.getAttribute(cname, attribute))); 181 attribute = "maxThreads"; 182 connectorFm.setMaxThreads 183 (String.valueOf(mBServer.getAttribute(cname, attribute))); 184 attribute = "minSpareThreads"; 185 connectorFm.setMinSpare 186 (String.valueOf(mBServer.getAttribute(cname, attribute))); 187 attribute = "threadPriority"; 188 connectorFm.setThreadPriority 189 (String.valueOf(mBServer.getAttribute(cname, attribute))); 190 attribute = "secure"; 191 connectorFm.setSecure 192 (((Boolean ) mBServer.getAttribute(cname, attribute)).toString()); 193 attribute = "tcpNoDelay"; 194 connectorFm.setTcpNoDelay 195 (String.valueOf(mBServer.getAttribute(cname, attribute))); 196 attribute = "xpoweredBy"; 197 connectorFm.setXpoweredBy 198 (((Boolean ) mBServer.getAttribute(cname, attribute)).toString()); 199 attribute = "URIEncoding"; 200 connectorFm.setURIEncodingText 201 ((String ) mBServer.getAttribute(cname, attribute)); 202 attribute = "useBodyEncodingForURI"; 203 connectorFm.setUseBodyEncodingForURIText 204 (((Boolean ) mBServer.getAttribute(cname, attribute)).toString()); 205 attribute = "allowTrace"; 206 connectorFm.setAllowTraceText 207 (((Boolean ) mBServer.getAttribute(cname, attribute)).toString()); 208 209 attribute = "port"; 211 connectorFm.setPortText 212 (((Integer ) mBServer.getAttribute(cname, attribute)).toString()); 213 attribute = "redirectPort"; 214 connectorFm.setRedirectPortText 215 (((Integer ) mBServer.getAttribute(cname, attribute)).toString()); 216 217 if (!("AJP".equalsIgnoreCase(connectorType))) { 219 attribute = "proxyName"; 220 connectorFm.setProxyName 221 ((String ) mBServer.getAttribute(cname, attribute)); 222 attribute = "proxyPort"; 223 connectorFm.setProxyPortText 224 (((Integer ) mBServer.getAttribute(cname, attribute)).toString()); 225 } 226 227 if ("HTTPS".equalsIgnoreCase(connectorType)) { 228 attribute = "algorithm"; 231 connectorFm.setAlgorithm 232 ((String ) mBServer.getAttribute(cname, attribute)); 233 attribute = "clientAuth"; 234 connectorFm.setClientAuthentication 235 (((String ) mBServer.getAttribute(cname, attribute))); 236 attribute = "ciphers"; 237 connectorFm.setCiphers 238 ((String ) mBServer.getAttribute(cname, attribute)); 239 attribute = "keystoreFile"; 240 connectorFm.setKeyStoreFileName 241 ((String ) mBServer.getAttribute(cname, attribute)); 242 attribute = "keystorePass"; 243 connectorFm.setKeyStorePassword 244 ((String ) mBServer.getAttribute(cname, attribute)); 245 attribute = "keystoreType"; 246 connectorFm.setKeyStoreType 247 ((String ) mBServer.getAttribute(cname, attribute)); 248 attribute = "sslProtocol"; 249 connectorFm.setSslProtocol 250 ((String ) mBServer.getAttribute(cname, attribute)); 251 } 252 253 254 } catch (Throwable t) { 255 getServlet().log 256 (resources.getMessage(locale, "users.error.attribute.get", 257 attribute), t); 258 response.sendError 259 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 260 resources.getMessage(locale, "users.error.attribute.get", 261 attribute)); 262 return (null); 263 } 264 265 return (mapping.findForward("Connector")); 267 268 } 269 270 271 } 272 | Popular Tags |