001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.tomcat;
017:
018: import java.util.ArrayList;
019: import java.util.Arrays;
020: import java.util.HashMap;
021: import java.util.Iterator;
022: import java.util.List;
023: import java.util.Map;
024: import java.util.Map.Entry;
025: import java.util.Set;
026:
027: import javax.net.ssl.KeyManagerFactory;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import org.apache.geronimo.gbean.AbstractName;
032: import org.apache.geronimo.gbean.AbstractNameQuery;
033: import org.apache.geronimo.gbean.GBeanData;
034: import org.apache.geronimo.gbean.GBeanInfo;
035: import org.apache.geronimo.gbean.GBeanInfoBuilder;
036: import org.apache.geronimo.gbean.ReferencePatterns;
037: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
038: import org.apache.geronimo.kernel.GBeanNotFoundException;
039: import org.apache.geronimo.kernel.Kernel;
040: import org.apache.geronimo.kernel.config.ConfigurationUtil;
041: import org.apache.geronimo.kernel.config.EditableConfigurationManager;
042: import org.apache.geronimo.kernel.config.InvalidConfigException;
043: import org.apache.geronimo.kernel.proxy.ProxyManager;
044: import org.apache.geronimo.management.geronimo.NetworkConnector;
045: import org.apache.geronimo.management.geronimo.WebAccessLog;
046: import org.apache.geronimo.management.geronimo.WebContainer;
047: import org.apache.geronimo.management.geronimo.WebManager;
048: import org.apache.geronimo.system.serverinfo.ServerInfo;
049: import org.apache.geronimo.tomcat.connector.AJP13ConnectorGBean;
050: import org.apache.geronimo.tomcat.connector.ConnectorGBean;
051: import org.apache.geronimo.tomcat.connector.Http11APRConnectorGBean;
052: import org.apache.geronimo.tomcat.connector.Http11ConnectorGBean;
053: import org.apache.geronimo.tomcat.connector.Http11NIOConnectorGBean;
054: import org.apache.geronimo.tomcat.connector.Https11APRConnectorGBean;
055: import org.apache.geronimo.tomcat.connector.Https11ConnectorGBean;
056: import org.apache.geronimo.tomcat.connector.Https11NIOConnectorGBean;
057: import org.apache.geronimo.tomcat.connector.TomcatWebConnector;
058: import org.apache.geronimo.crypto.KeystoreUtil;
059:
060: /**
061: * Tomcat implementation of the WebManager management API. Knows how to
062: * manipulate other Tomcat objects for management purposes.
063: *
064: * @version $Rev: 617588 $ $Date: 2008-02-01 10:20:07 -0800 (Fri, 01 Feb 2008) $
065: */
066: public class TomcatManagerImpl implements WebManager {
067: private final static Log log = LogFactory
068: .getLog(TomcatManagerImpl.class);
069: private final Kernel kernel;
070:
071: private static final ConnectorType HTTP_BIO = new ConnectorType(
072: Messages.getString("TomcatManagerImpl.0")); //$NON-NLS-1$
073: private static final ConnectorType HTTPS_BIO = new ConnectorType(
074: Messages.getString("TomcatManagerImpl.1")); //$NON-NLS-1$
075: private static final ConnectorType HTTP_NIO = new ConnectorType(
076: Messages.getString("TomcatManagerImpl.2")); //$NON-NLS-1$
077: private static final ConnectorType HTTPS_NIO = new ConnectorType(
078: Messages.getString("TomcatManagerImpl.3")); //$NON-NLS-1$
079: private static final ConnectorType HTTP_APR = new ConnectorType(
080: Messages.getString("TomcatManagerImpl.4")); //$NON-NLS-1$
081: private static final ConnectorType HTTPS_APR = new ConnectorType(
082: Messages.getString("TomcatManagerImpl.5")); //$NON-NLS-1$
083: private static final ConnectorType AJP = new ConnectorType(Messages
084: .getString("TomcatManagerImpl.6")); //$NON-NLS-1$
085: private static List<ConnectorType> CONNECTOR_TYPES = Arrays.asList(
086: HTTP_BIO, HTTPS_BIO, HTTP_NIO, HTTPS_NIO, HTTP_APR,
087: HTTPS_APR, AJP);
088:
089: private static Map<ConnectorType, List<ConnectorAttribute>> CONNECTOR_ATTRIBUTES = new HashMap<ConnectorType, List<ConnectorAttribute>>();
090:
091: static {
092: //******************* HTTP - BIO CONNECTOR
093: List<ConnectorAttribute> connectorAttributes = new ArrayList<ConnectorAttribute>();
094: addCommonConnectorAttributes(connectorAttributes);
095: addHttpConnectorAttributes(connectorAttributes);
096: CONNECTOR_ATTRIBUTES.put(HTTP_BIO, connectorAttributes);
097:
098: //******************* HTTPS - BIO CONNECTOR
099: connectorAttributes = new ArrayList<ConnectorAttribute>();
100: addCommonConnectorAttributes(connectorAttributes);
101: addHttpConnectorAttributes(connectorAttributes);
102: addSslConnectorAttributes(connectorAttributes);
103: setAttribute(connectorAttributes, "port", 8443); // SSL port
104: CONNECTOR_ATTRIBUTES.put(HTTPS_BIO, connectorAttributes);
105:
106: //******************* HTTP - NIO CONNECTOR
107: connectorAttributes = new ArrayList<ConnectorAttribute>();
108: addCommonConnectorAttributes(connectorAttributes);
109: addHttpConnectorAttributes(connectorAttributes);
110: addNioConnectorAttributes(connectorAttributes);
111: CONNECTOR_ATTRIBUTES.put(HTTP_NIO, connectorAttributes);
112:
113: //******************* HTTPS - NIO CONNECTOR
114: connectorAttributes = new ArrayList<ConnectorAttribute>();
115: addCommonConnectorAttributes(connectorAttributes);
116: addHttpConnectorAttributes(connectorAttributes);
117: addSslConnectorAttributes(connectorAttributes);
118: addNioConnectorAttributes(connectorAttributes);
119: setAttribute(connectorAttributes, "port", 8443); // SSL port
120: CONNECTOR_ATTRIBUTES.put(HTTPS_NIO, connectorAttributes);
121:
122: //******************* HTTP - APR CONNECTOR
123: connectorAttributes = new ArrayList<ConnectorAttribute>();
124: addCommonConnectorAttributes(connectorAttributes);
125: addHttpConnectorAttributes(connectorAttributes);
126: addAprConnectorAttributes(connectorAttributes);
127: CONNECTOR_ATTRIBUTES.put(HTTP_APR, connectorAttributes);
128:
129: //******************* HTTPS - APR CONNECTOR
130: connectorAttributes = new ArrayList<ConnectorAttribute>();
131: addCommonConnectorAttributes(connectorAttributes);
132: addHttpConnectorAttributes(connectorAttributes);
133: addAprConnectorAttributes(connectorAttributes);
134: //APR SSL specific values, different from BIO and NIO SSL because it uses openssl
135: connectorAttributes
136: .add(new ConnectorAttribute<String>(
137: "sslProtocol", "all", Messages.getString("TomcatManagerImpl.11"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
138: connectorAttributes
139: .add(new ConnectorAttribute<String>(
140: "sslCipherSuite", "ALL", Messages.getString("TomcatManagerImpl.14"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
141: connectorAttributes
142: .add(new ConnectorAttribute<String>(
143: "sslCertificateFile", "", Messages.getString("TomcatManagerImpl.17"), String.class, true)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
144: connectorAttributes
145: .add(new ConnectorAttribute<String>(
146: "sslCertificateKeyFile", null, Messages.getString("TomcatManagerImpl.19"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$
147: connectorAttributes
148: .add(new ConnectorAttribute<String>(
149: "sslPassword", null, Messages.getString("TomcatManagerImpl.21"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$
150: connectorAttributes
151: .add(new ConnectorAttribute<String>(
152: "sslVerifyClient", "none", Messages.getString("TomcatManagerImpl.24"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
153: connectorAttributes
154: .add(new ConnectorAttribute<Integer>(
155: "sslVerifyDepth", 10, Messages.getString("TomcatManagerImpl.26"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
156: connectorAttributes
157: .add(new ConnectorAttribute<String>(
158: "sslCACertificateFile", null, Messages.getString("TomcatManagerImpl.28"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$
159: connectorAttributes
160: .add(new ConnectorAttribute<String>(
161: "sslCACertificatePath", null, Messages.getString("TomcatManagerImpl.30"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$
162: connectorAttributes
163: .add(new ConnectorAttribute<String>(
164: "sslCertificateChainFile", null, Messages.getString("TomcatManagerImpl.32"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$
165: connectorAttributes
166: .add(new ConnectorAttribute<String>(
167: "sslCARevocationFile", null, Messages.getString("TomcatManagerImpl.34"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$
168: connectorAttributes
169: .add(new ConnectorAttribute<String>(
170: "sslCARevocationPath", null, Messages.getString("TomcatManagerImpl.36"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$
171: setAttribute(connectorAttributes, "port", 8443); // SSL port
172: CONNECTOR_ATTRIBUTES.put(HTTPS_APR, connectorAttributes);
173:
174: //******************* AJP CONNECTOR
175: connectorAttributes = new ArrayList<ConnectorAttribute>();
176: addCommonConnectorAttributes(connectorAttributes);
177: //AJP Attributes, see http://tomcat.apache.org/tomcat-6.0-doc/config/ajp.html
178: connectorAttributes
179: .add(new ConnectorAttribute<String>(
180: "host", "0.0.0.0", Messages.getString("TomcatManagerImpl.40"), String.class, true)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
181: connectorAttributes
182: .add(new ConnectorAttribute<Integer>(
183: "port", 8009, Messages.getString("TomcatManagerImpl.42"), Integer.class, true)); //$NON-NLS-1$ //$NON-NLS-2$
184: connectorAttributes
185: .add(new ConnectorAttribute<Integer>(
186: "backlog", 10, Messages.getString("TomcatManagerImpl.44"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
187: connectorAttributes
188: .add(new ConnectorAttribute<Integer>(
189: "bufferSize", -1, Messages.getString("TomcatManagerImpl.46"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
190: connectorAttributes
191: .add(new ConnectorAttribute<Integer>(
192: "connectionTimeout", org.apache.coyote.ajp.Constants.DEFAULT_CONNECTION_TIMEOUT, Messages.getString("TomcatManagerImpl.48"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
193: connectorAttributes
194: .add(new ConnectorAttribute<Integer>(
195: "keepAliveTimeout", org.apache.coyote.ajp.Constants.DEFAULT_CONNECTION_TIMEOUT, Messages.getString("TomcatManagerImpl.50"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
196: connectorAttributes
197: .add(new ConnectorAttribute<Integer>(
198: "maxThreads", 40, Messages.getString("TomcatManagerImpl.52"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
199: connectorAttributes
200: .add(new ConnectorAttribute<Integer>(
201: "minSpareThreads", 10, Messages.getString("TomcatManagerImpl.54"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
202: connectorAttributes
203: .add(new ConnectorAttribute<Integer>(
204: "maxSpareThreads", 100, Messages.getString("TomcatManagerImpl.56"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
205: connectorAttributes
206: .add(new ConnectorAttribute<Boolean>(
207: "tcpNoDelay", true, Messages.getString("TomcatManagerImpl.58"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
208: connectorAttributes
209: .add(new ConnectorAttribute<Boolean>(
210: "tomcatAuthentication", true, Messages.getString("TomcatManagerImpl.60"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
211: CONNECTOR_ATTRIBUTES.put(AJP, connectorAttributes);
212: }
213:
214: private static Map<ConnectorType, GBeanInfo> CONNECTOR_GBEAN_INFOS = new HashMap<ConnectorType, GBeanInfo>();
215:
216: static {
217: CONNECTOR_GBEAN_INFOS.put(HTTP_BIO,
218: Http11ConnectorGBean.GBEAN_INFO);
219: CONNECTOR_GBEAN_INFOS.put(HTTPS_BIO,
220: Https11ConnectorGBean.GBEAN_INFO);
221: CONNECTOR_GBEAN_INFOS.put(HTTP_NIO,
222: Http11NIOConnectorGBean.GBEAN_INFO);
223: CONNECTOR_GBEAN_INFOS.put(HTTPS_NIO,
224: Https11NIOConnectorGBean.GBEAN_INFO);
225: CONNECTOR_GBEAN_INFOS.put(HTTP_APR,
226: Http11APRConnectorGBean.GBEAN_INFO);
227: CONNECTOR_GBEAN_INFOS.put(HTTPS_APR,
228: Https11APRConnectorGBean.GBEAN_INFO);
229: CONNECTOR_GBEAN_INFOS.put(AJP, AJP13ConnectorGBean.GBEAN_INFO);
230: }
231:
232: public TomcatManagerImpl(Kernel kernel) {
233: this .kernel = kernel;
234: }
235:
236: public String getProductName() {
237: return "Tomcat";
238: }
239:
240: /**
241: * Gets the network containers.
242: */
243: public Object[] getContainers() {
244: ProxyManager proxyManager = kernel.getProxyManager();
245: AbstractNameQuery query = new AbstractNameQuery(
246: TomcatWebContainer.class.getName());
247: Set names = kernel.listGBeans(query);
248: TomcatWebContainer[] results = new TomcatWebContainer[names
249: .size()];
250: int i = 0;
251: for (Iterator it = names.iterator(); it.hasNext(); i++) {
252: AbstractName name = (AbstractName) it.next();
253: results[i] = (TomcatWebContainer) proxyManager.createProxy(
254: name, TomcatWebContainer.class.getClassLoader());
255: }
256: return results;
257: }
258:
259: /**
260: * Gets the protocols which this container can configure connectors for.
261: */
262: public String[] getSupportedProtocols() {
263: return new String[] { PROTOCOL_HTTP, PROTOCOL_HTTPS,
264: PROTOCOL_AJP };
265: }
266:
267: /**
268: * Removes a connector. This shuts it down if necessary, and removes it from the server environment. It must be a
269: * connector that uses this network technology.
270: * @param connectorName
271: */
272: public void removeConnector(AbstractName connectorName) {
273: try {
274: GBeanInfo info = kernel.getGBeanInfo(connectorName);
275: boolean found = false;
276: Set intfs = info.getInterfaces();
277: for (Iterator it = intfs.iterator(); it.hasNext();) {
278: String intf = (String) it.next();
279: if (intf.equals(TomcatWebConnector.class.getName())) {
280: found = true;
281: }
282: }
283: if (!found) {
284: throw new GBeanNotFoundException(connectorName);
285: }
286: EditableConfigurationManager mgr = ConfigurationUtil
287: .getEditableConfigurationManager(kernel);
288: if (mgr != null) {
289: try {
290: mgr.removeGBeanFromConfiguration(connectorName
291: .getArtifact(), connectorName);
292: } catch (InvalidConfigException e) {
293: log.error("Unable to add GBean", e);
294: } finally {
295: ConfigurationUtil.releaseConfigurationManager(
296: kernel, mgr);
297: }
298: } else {
299: log
300: .warn("The ConfigurationManager in the kernel does not allow editing");
301: }
302: } catch (GBeanNotFoundException e) {
303: log.warn("No such GBean '" + connectorName + "'"); //todo: what if we want to remove a failed GBean?
304: } catch (Exception e) {
305: log.error(e);
306: }
307: }
308:
309: /**
310: * Gets the ObjectNames of any existing connectors for this network technology for the specified protocol.
311: *
312: * @param protocol A protocol as returned by getSupportedProtocols
313: */
314: public NetworkConnector[] getConnectors(String protocol) {
315: if (protocol == null) {
316: return getConnectors();
317: }
318: List result = new ArrayList();
319: ProxyManager proxyManager = kernel.getProxyManager();
320: AbstractNameQuery query = new AbstractNameQuery(
321: TomcatWebConnector.class.getName());
322: Set names = kernel.listGBeans(query);
323: for (Iterator it = names.iterator(); it.hasNext();) {
324: AbstractName name = (AbstractName) it.next();
325: try {
326: if (kernel.getAttribute(name, "protocol").equals(
327: protocol)) {
328: result.add(proxyManager.createProxy(name,
329: TomcatWebConnector.class.getClassLoader()));
330: }
331: } catch (Exception e) {
332: log.error(
333: "Unable to check the protocol for a connector",
334: e);
335: }
336: }
337: return (TomcatWebConnector[]) result
338: .toArray(new TomcatWebConnector[names.size()]);
339: }
340:
341: public WebAccessLog getAccessLog(WebContainer container) {
342: AbstractNameQuery query = new AbstractNameQuery(
343: TomcatLogManager.class.getName());
344: Set names = kernel.listGBeans(query);
345: if (names.size() == 0) {
346: return null;
347: } else if (names.size() > 1) {
348: throw new IllegalStateException(
349: "Should not be more than one Tomcat access log manager");
350: }
351: return (WebAccessLog) kernel.getProxyManager().createProxy(
352: (AbstractName) names.iterator().next(),
353: TomcatLogManager.class.getClassLoader());
354: }
355:
356: public List<ConnectorType> getConnectorTypes() {
357: return CONNECTOR_TYPES;
358: }
359:
360: public List<ConnectorAttribute> getConnectorAttributes(
361: ConnectorType connectorType) {
362: return ConnectorAttribute.copy(CONNECTOR_ATTRIBUTES
363: .get(connectorType));
364: }
365:
366: public AbstractName getConnectorConfiguration(
367: ConnectorType connectorType,
368: List<ConnectorAttribute> connectorAttributes,
369: WebContainer container, String uniqueName) {
370: GBeanInfo gbeanInfo = CONNECTOR_GBEAN_INFOS.get(connectorType);
371: AbstractName containerName = kernel
372: .getAbstractNameFor(container);
373: AbstractName name = kernel.getNaming()
374: .createSiblingName(containerName, uniqueName,
375: NameFactory.GERONIMO_SERVICE);
376: GBeanData gbeanData = new GBeanData(name, gbeanInfo);
377: gbeanData.setAttribute("name", uniqueName);
378: gbeanData.setReferencePattern(
379: ConnectorGBean.CONNECTOR_CONTAINER_REFERENCE,
380: containerName);
381: for (ConnectorAttribute connectorAttribute : connectorAttributes) {
382: gbeanData.setAttribute(connectorAttribute
383: .getAttributeName(), connectorAttribute.getValue());
384: }
385: AbstractNameQuery query = new AbstractNameQuery(
386: ServerInfo.class.getName());
387: Set set = kernel.listGBeans(query);
388: AbstractName serverInfo = (AbstractName) set.iterator().next();
389: gbeanData.setReferencePattern("ServerInfo", serverInfo);
390:
391: EditableConfigurationManager mgr = ConfigurationUtil
392: .getEditableConfigurationManager(kernel);
393: if (mgr != null) {
394: try {
395: mgr.addGBeanToConfiguration(
396: containerName.getArtifact(), gbeanData, false);
397: } catch (InvalidConfigException e) {
398: log.error("Unable to add GBean", e);
399: return null;
400: } finally {
401: ConfigurationUtil.releaseConfigurationManager(kernel,
402: mgr);
403: }
404: } else {
405: log
406: .warn("The ConfigurationManager in the kernel does not allow editing");
407: return null;
408: }
409: return name;
410: }
411:
412: /**
413: * Gets the ObjectNames of any existing connectors associated with this network technology.
414: */
415: public NetworkConnector[] getConnectors() {
416: ProxyManager proxyManager = kernel.getProxyManager();
417: AbstractNameQuery query = new AbstractNameQuery(
418: TomcatWebConnector.class.getName());
419: Set names = kernel.listGBeans(query);
420: TomcatWebConnector[] results = new TomcatWebConnector[names
421: .size()];
422: int i = 0;
423: for (Iterator it = names.iterator(); it.hasNext(); i++) {
424: AbstractName name = (AbstractName) it.next();
425: results[i] = (TomcatWebConnector) proxyManager.createProxy(
426: name, TomcatWebConnector.class.getClassLoader());
427: }
428: return results;
429: }
430:
431: /**
432: * Gets the ObjectNames of any existing connectors for the specified container for the specified protocol.
433: *
434: * @param protocol A protocol as returned by getSupportedProtocols
435: */
436: public NetworkConnector[] getConnectorsForContainer(
437: Object container, String protocol) {
438: if (protocol == null) {
439: return getConnectorsForContainer(container);
440: }
441: AbstractName containerName = kernel
442: .getAbstractNameFor(container);
443: ProxyManager mgr = kernel.getProxyManager();
444: try {
445: List results = new ArrayList();
446: AbstractNameQuery query = new AbstractNameQuery(
447: TomcatWebConnector.class.getName());
448: Set set = kernel.listGBeans(query); // all Tomcat connectors
449: for (Iterator it = set.iterator(); it.hasNext();) {
450: AbstractName name = (AbstractName) it.next(); // a single Tomcat connector
451: GBeanData data = kernel.getGBeanData(name);
452: ReferencePatterns refs = data
453: .getReferencePatterns(ConnectorGBean.CONNECTOR_CONTAINER_REFERENCE);
454: if (containerName.equals(refs.getAbstractName())) {
455: try {
456: String testProtocol = (String) kernel
457: .getAttribute(name, "protocol");
458: if (testProtocol != null
459: && testProtocol.equals(protocol)) {
460: results.add(mgr.createProxy(name,
461: TomcatWebConnector.class
462: .getClassLoader()));
463: }
464: } catch (Exception e) {
465: log.error(
466: "Unable to look up protocol for connector '"
467: + name + "'", e);
468: }
469: break;
470: }
471: }
472: return (TomcatWebConnector[]) results
473: .toArray(new TomcatWebConnector[results.size()]);
474: } catch (Exception e) {
475: throw (IllegalArgumentException) new IllegalArgumentException(
476: "Unable to look up connectors for Tomcat container '"
477: + containerName + "': ").initCause(e);
478: }
479: }
480:
481: /**
482: * Gets the ObjectNames of any existing connectors for the specified container.
483: */
484: public NetworkConnector[] getConnectorsForContainer(Object container) {
485: AbstractName containerName = kernel
486: .getAbstractNameFor(container);
487: ProxyManager mgr = kernel.getProxyManager();
488: try {
489: List results = new ArrayList();
490: AbstractNameQuery query = new AbstractNameQuery(
491: TomcatWebConnector.class.getName());
492: Set set = kernel.listGBeans(query); // all Tomcat connectors
493: for (Iterator it = set.iterator(); it.hasNext();) {
494: AbstractName name = (AbstractName) it.next(); // a single Tomcat connector
495: GBeanData data = kernel.getGBeanData(name);
496: ReferencePatterns refs = data
497: .getReferencePatterns(ConnectorGBean.CONNECTOR_CONTAINER_REFERENCE);
498: if (containerName.equals(refs.getAbstractName())) {
499: results.add(mgr.createProxy(name,
500: TomcatWebConnector.class.getClassLoader()));
501: }
502: }
503: return (TomcatWebConnector[]) results
504: .toArray(new TomcatWebConnector[results.size()]);
505: } catch (Exception e) {
506: throw (IllegalArgumentException) new IllegalArgumentException(
507: "Unable to look up connectors for Tomcat container '"
508: + containerName).initCause(e);
509: }
510: }
511:
512: // see http://tomcat.apache.org/tomcat-6.0-doc/config/http.html
513: private static void addCommonConnectorAttributes(
514: List<ConnectorAttribute> connectorAttributes) {
515: connectorAttributes
516: .add(new ConnectorAttribute<Boolean>(
517: "allowTrace", false, Messages.getString("TomcatManagerImpl.80"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
518: connectorAttributes
519: .add(new ConnectorAttribute<Boolean>(
520: "emptySessionPath", false, Messages.getString("TomcatManagerImpl.82"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
521: connectorAttributes
522: .add(new ConnectorAttribute<Boolean>(
523: "enableLookups", true, Messages.getString("TomcatManagerImpl.84"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
524: connectorAttributes
525: .add(new ConnectorAttribute<Integer>(
526: "maxPostSize", 2097152, Messages.getString("TomcatManagerImpl.86"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
527: connectorAttributes
528: .add(new ConnectorAttribute<Integer>(
529: "maxSavePostSize", 4096, Messages.getString("TomcatManagerImpl.88"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
530: connectorAttributes
531: .add(new ConnectorAttribute<String>(
532: "proxyName", null, Messages.getString("TomcatManagerImpl.90"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$
533: connectorAttributes
534: .add(new ConnectorAttribute<Integer>(
535: "proxyPort", 0, Messages.getString("TomcatManagerImpl.92"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
536: connectorAttributes
537: .add(new ConnectorAttribute<Integer>(
538: "redirectPort", 8443, Messages.getString("TomcatManagerImpl.94"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
539: connectorAttributes
540: .add(new ConnectorAttribute<String>(
541: "uriEncoding", "ISO-8859-1", Messages.getString("TomcatManagerImpl.97"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
542: connectorAttributes
543: .add(new ConnectorAttribute<Boolean>(
544: "useBodyEncodingForURI", false, Messages.getString("TomcatManagerImpl.99"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
545: connectorAttributes
546: .add(new ConnectorAttribute<Boolean>(
547: "useIPVHosts", false, Messages.getString("TomcatManagerImpl.101"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
548: connectorAttributes
549: .add(new ConnectorAttribute<Boolean>(
550: "xpoweredBy", false, Messages.getString("TomcatManagerImpl.103"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
551: }
552:
553: // see http://tomcat.apache.org/tomcat-6.0-doc/config/http.html
554: private static void addHttpConnectorAttributes(
555: List<ConnectorAttribute> connectorAttributes) {
556: connectorAttributes
557: .add(new ConnectorAttribute<Integer>(
558: "acceptCount", 10, Messages.getString("TomcatManagerImpl.105"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
559: connectorAttributes
560: .add(new ConnectorAttribute<String>(
561: "address", "0.0.0.0", Messages.getString("TomcatManagerImpl.108"), String.class, true)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
562: connectorAttributes
563: .add(new ConnectorAttribute<Integer>(
564: "bufferSize", 2048, Messages.getString("TomcatManagerImpl.110"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
565: connectorAttributes
566: .add(new ConnectorAttribute<String>(
567: "compressableMimeType", "text/html,text/xml,text/plain", Messages.getString("TomcatManagerImpl.113"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
568: connectorAttributes
569: .add(new ConnectorAttribute<String>(
570: "compression", "off", Messages.getString("TomcatManagerImpl.116"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
571: connectorAttributes
572: .add(new ConnectorAttribute<Integer>(
573: "connectionLinger", -1, Messages.getString("TomcatManagerImpl.118"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
574: connectorAttributes
575: .add(new ConnectorAttribute<Integer>(
576: "connectionTimeout", 60000, Messages.getString("TomcatManagerImpl.120"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
577: connectorAttributes
578: .add(new ConnectorAttribute<String>(
579: "executor", null, Messages.getString("TomcatManagerImpl.122"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$
580: connectorAttributes
581: .add(new ConnectorAttribute<Integer>(
582: "keepAliveTimeout", 60000, Messages.getString("TomcatManagerImpl.124"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
583: connectorAttributes
584: .add(new ConnectorAttribute<Boolean>(
585: "disableUploadTimeout", true, Messages.getString("TomcatManagerImpl.126"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
586: connectorAttributes
587: .add(new ConnectorAttribute<Integer>(
588: "maxHttpHeaderSize", 4096, Messages.getString("TomcatManagerImpl.128"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
589: connectorAttributes
590: .add(new ConnectorAttribute<Integer>(
591: "maxKeepAliveRequests", 100, Messages.getString("TomcatManagerImpl.130"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
592: connectorAttributes
593: .add(new ConnectorAttribute<Integer>(
594: "maxThreads", 40, Messages.getString("TomcatManagerImpl.132"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
595: connectorAttributes
596: .add(new ConnectorAttribute<Integer>(
597: "minSpareThreads", 10, Messages.getString("TomcatManagerImpl.134"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
598: connectorAttributes
599: .add(new ConnectorAttribute<Integer>(
600: "maxSpareThreads", 100, Messages.getString("TomcatManagerImpl.136"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
601: connectorAttributes
602: .add(new ConnectorAttribute<String>(
603: "noCompressionUserAgents", "", Messages.getString("TomcatManagerImpl.139"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
604: connectorAttributes
605: .add(new ConnectorAttribute<Integer>(
606: "port", 8080, Messages.getString("TomcatManagerImpl.141"), Integer.class, true)); //$NON-NLS-1$ //$NON-NLS-2$
607: connectorAttributes
608: .add(new ConnectorAttribute<String>(
609: "restrictedUserAgents", "", Messages.getString("TomcatManagerImpl.144"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
610: connectorAttributes
611: .add(new ConnectorAttribute<String>(
612: "server", "", Messages.getString("TomcatManagerImpl.147"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
613: connectorAttributes
614: .add(new ConnectorAttribute<Integer>(
615: "socketBuffer", 9000, Messages.getString("TomcatManagerImpl.149"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
616: connectorAttributes
617: .add(new ConnectorAttribute<Boolean>(
618: "tcpNoDelay", true, Messages.getString("TomcatManagerImpl.151"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
619: connectorAttributes
620: .add(new ConnectorAttribute<Integer>(
621: "threadPriority", Thread.NORM_PRIORITY, Messages.getString("TomcatManagerImpl.153"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
622: }
623:
624: // see http://tomcat.apache.org/tomcat-6.0-doc/config/http.html
625: private static void addSslConnectorAttributes(
626: List<ConnectorAttribute> connectorAttributes) {
627: connectorAttributes
628: .add(new ConnectorAttribute<String>(
629: "algorithm", KeyManagerFactory.getDefaultAlgorithm(), Messages.getString("TomcatManagerImpl.155"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$
630: connectorAttributes
631: .add(new ConnectorAttribute<Boolean>(
632: "clientAuth", false, Messages.getString("TomcatManagerImpl.157"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
633: connectorAttributes
634: .add(new ConnectorAttribute<String>(
635: "keystoreFile", "", Messages.getString("TomcatManagerImpl.160"), String.class, true)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
636: connectorAttributes
637: .add(new ConnectorAttribute<String>(
638: "keystorePass", null, Messages.getString("TomcatManagerImpl.162"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$
639: connectorAttributes
640: .add(new ConnectorAttribute<String>(
641: "keystoreType", KeystoreUtil.defaultType, Messages.getString("TomcatManagerImpl.165"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
642: connectorAttributes
643: .add(new ConnectorAttribute<String>(
644: "sslProtocol", "TLS", Messages.getString("TomcatManagerImpl.168"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
645: connectorAttributes
646: .add(new ConnectorAttribute<String>(
647: "ciphers", "", Messages.getString("TomcatManagerImpl.171"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
648: connectorAttributes
649: .add(new ConnectorAttribute<String>(
650: "keyAlias", null, Messages.getString("TomcatManagerImpl.173"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$
651: connectorAttributes
652: .add(new ConnectorAttribute<String>(
653: "truststoreFile", null, Messages.getString("TomcatManagerImpl.175"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$
654: connectorAttributes
655: .add(new ConnectorAttribute<String>(
656: "truststorePass", null, Messages.getString("TomcatManagerImpl.177"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$
657: connectorAttributes
658: .add(new ConnectorAttribute<String>(
659: "truststoreType", KeystoreUtil.defaultType, Messages.getString("TomcatManagerImpl.179"), String.class)); //$NON-NLS-1$ //$NON-NLS-2$
660: }
661:
662: // see http://tomcat.apache.org/tomcat-6.0-doc/config/http.html
663: private static void addNioConnectorAttributes(
664: List<ConnectorAttribute> connectorAttributes) {
665: connectorAttributes
666: .add(new ConnectorAttribute<Boolean>(
667: "useSendfile", true, Messages.getString("TomcatManagerImpl.181"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
668: connectorAttributes
669: .add(new ConnectorAttribute<Boolean>(
670: "useExecutor", true, Messages.getString("TomcatManagerImpl.183"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
671: connectorAttributes
672: .add(new ConnectorAttribute<Integer>(
673: "acceptorThreadCount", 1, Messages.getString("TomcatManagerImpl.185"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
674: connectorAttributes
675: .add(new ConnectorAttribute<Integer>(
676: "pollerThreadCount", 1, Messages.getString("TomcatManagerImpl.187"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
677: connectorAttributes
678: .add(new ConnectorAttribute<Integer>(
679: "pollerThreadPriority", Thread.NORM_PRIORITY, Messages.getString("TomcatManagerImpl.189"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
680: connectorAttributes
681: .add(new ConnectorAttribute<Integer>(
682: "acceptorThreadPriority", Thread.NORM_PRIORITY, Messages.getString("TomcatManagerImpl.191"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
683: connectorAttributes
684: .add(new ConnectorAttribute<Integer>(
685: "selectorTimeout", 1000, Messages.getString("TomcatManagerImpl.193"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
686: connectorAttributes
687: .add(new ConnectorAttribute<Boolean>(
688: "useComet", true, Messages.getString("TomcatManagerImpl.195"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
689: connectorAttributes
690: .add(new ConnectorAttribute<Integer>(
691: "processCache", 200, Messages.getString("TomcatManagerImpl.197"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
692: connectorAttributes
693: .add(new ConnectorAttribute<Boolean>(
694: "socket_directBuffer", false, Messages.getString("TomcatManagerImpl.199"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
695: connectorAttributes
696: .add(new ConnectorAttribute<Integer>(
697: "socket_rxBufSize", 25188, Messages.getString("TomcatManagerImpl.201"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
698: connectorAttributes
699: .add(new ConnectorAttribute<Integer>(
700: "socket_txBufSize", 43800, Messages.getString("TomcatManagerImpl.203"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
701: connectorAttributes
702: .add(new ConnectorAttribute<Integer>(
703: "socket_appReadBufSize", 8192, Messages.getString("TomcatManagerImpl.205"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
704: connectorAttributes
705: .add(new ConnectorAttribute<Integer>(
706: "socket_appWriteBufSize", 8192, Messages.getString("TomcatManagerImpl.207"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
707: connectorAttributes
708: .add(new ConnectorAttribute<Integer>(
709: "socket_bufferPool", 500, Messages.getString("TomcatManagerImpl.209"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
710: connectorAttributes
711: .add(new ConnectorAttribute<Integer>(
712: "socket_bufferPoolSize", 104857600, Messages.getString("TomcatManagerImpl.211"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
713: connectorAttributes
714: .add(new ConnectorAttribute<Integer>(
715: "socket_processorCache", 500, Messages.getString("TomcatManagerImpl.213"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
716: connectorAttributes
717: .add(new ConnectorAttribute<Integer>(
718: "socket_keyCache", 500, Messages.getString("TomcatManagerImpl.215"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
719: connectorAttributes
720: .add(new ConnectorAttribute<Integer>(
721: "socket_eventCache", 500, Messages.getString("TomcatManagerImpl.217"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
722: connectorAttributes
723: .add(new ConnectorAttribute<Boolean>(
724: "socket_tcpNoDelay", false, Messages.getString("TomcatManagerImpl.219"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
725: connectorAttributes
726: .add(new ConnectorAttribute<Boolean>(
727: "socket_soKeepAlive", false, Messages.getString("TomcatManagerImpl.221"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
728: connectorAttributes
729: .add(new ConnectorAttribute<Boolean>(
730: "socket_ooBInline", true, Messages.getString("TomcatManagerImpl.223"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
731: connectorAttributes
732: .add(new ConnectorAttribute<Boolean>(
733: "socket_soReuseAddress", true, Messages.getString("TomcatManagerImpl.225"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
734: connectorAttributes
735: .add(new ConnectorAttribute<Boolean>(
736: "socket_soLingerOn", true, Messages.getString("TomcatManagerImpl.227"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
737: connectorAttributes
738: .add(new ConnectorAttribute<Integer>(
739: "socket_soLingerTime", 25, Messages.getString("TomcatManagerImpl.229"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
740: connectorAttributes
741: .add(new ConnectorAttribute<Integer>(
742: "socket_soTimeout", 5000, Messages.getString("TomcatManagerImpl.231"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
743: connectorAttributes
744: .add(new ConnectorAttribute<Integer>(
745: "socket_soTrafficClass", (0x04 | 0x08 | 0x010), Messages.getString("TomcatManagerImpl.233"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
746: connectorAttributes
747: .add(new ConnectorAttribute<Integer>(
748: "socket_performanceConnectionTime", 1, Messages.getString("TomcatManagerImpl.235"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
749: connectorAttributes
750: .add(new ConnectorAttribute<Integer>(
751: "socket_performanceLatency", 0, Messages.getString("TomcatManagerImpl.237"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
752: connectorAttributes
753: .add(new ConnectorAttribute<Integer>(
754: "socket_performanceBandwidth", 1, Messages.getString("TomcatManagerImpl.239"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
755: connectorAttributes
756: .add(new ConnectorAttribute<Integer>(
757: "selectorPool_maxSelectors", 200, Messages.getString("TomcatManagerImpl.241"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
758: connectorAttributes
759: .add(new ConnectorAttribute<Integer>(
760: "selectorPool_maxSpareSelectors", -1, Messages.getString("TomcatManagerImpl.243"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
761: connectorAttributes
762: .add(new ConnectorAttribute<Boolean>(
763: "command_line_options", true, Messages.getString("TomcatManagerImpl.245"), Boolean.class)); //$NON-NLS-1$ //$NON-NLS-2$
764: connectorAttributes
765: .add(new ConnectorAttribute<Integer>(
766: "oomParachute", 1048576, Messages.getString("TomcatManagerImpl.247"), Integer.class)); //$NON-NLS-1$ //$NON-NLS-2$
767: }
768:
769: // http://tomcat.apache.org/tomcat-6.0-doc/apr.html
770: private static void addAprConnectorAttributes(
771: List<ConnectorAttribute> connectorAttributes) {
772: connectorAttributes
773: .add(new ConnectorAttribute<Integer>(
774: "pollTime", 2000, Messages.getString("TomcatManagerImpl.249"), Integer.class, true)); //$NON-NLS-1$ //$NON-NLS-2$
775: connectorAttributes
776: .add(new ConnectorAttribute<Integer>(
777: "pollerSize", 8192, Messages.getString("TomcatManagerImpl.251"), Integer.class, true)); //$NON-NLS-1$ //$NON-NLS-2$
778: connectorAttributes
779: .add(new ConnectorAttribute<Boolean>(
780: "useSendfile", true, Messages.getString("TomcatManagerImpl.253"), Boolean.class, true)); //$NON-NLS-1$ //$NON-NLS-2$
781: connectorAttributes
782: .add(new ConnectorAttribute<Integer>(
783: "sendfileSize", 1024, Messages.getString("TomcatManagerImpl.255"), Integer.class, true)); //$NON-NLS-1$ //$NON-NLS-2$
784: }
785:
786: private static <T> void setAttribute(
787: List<ConnectorAttribute> connectorAttributes,
788: String attributeName, T value) {
789: for (ConnectorAttribute connectorAttribute : connectorAttributes) {
790: if (connectorAttribute.getAttributeName().equals(
791: attributeName)) {
792: connectorAttribute.setValue(value);
793: return;
794: }
795: }
796: }
797:
798: public ConnectorType getConnectorType(AbstractName connectorName) {
799: ConnectorType connectorType = null;
800: try {
801: GBeanInfo info = kernel.getGBeanInfo(connectorName);
802: boolean found = false;
803: Set intfs = info.getInterfaces();
804: for (Iterator it = intfs.iterator(); it.hasNext() && !found;) {
805: String intf = (String) it.next();
806: if (intf.equals(TomcatWebConnector.class.getName())) {
807: found = true;
808: }
809: }
810: if (!found) {
811: throw new GBeanNotFoundException(connectorName);
812: }
813: String searchingFor = info.getName();
814: for (Entry<ConnectorType, GBeanInfo> entry : CONNECTOR_GBEAN_INFOS
815: .entrySet()) {
816: String candidate = entry.getValue().getName();
817: if (candidate.equals(searchingFor)) {
818: return entry.getKey();
819: }
820: }
821: } catch (GBeanNotFoundException e) {
822: log.warn("No such GBean '" + connectorName + "'");
823: } catch (Exception e) {
824: log.error(e);
825: }
826:
827: return connectorType;
828: }
829:
830: public static final GBeanInfo GBEAN_INFO;
831:
832: static {
833: GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
834: "Tomcat Web Manager", TomcatManagerImpl.class);
835: infoFactory.addAttribute("kernel", Kernel.class, false);
836: infoFactory.addInterface(WebManager.class);
837: infoFactory.setConstructor(new String[] { "kernel" });
838: GBEAN_INFO = infoFactory.getBeanInfo();
839: }
840:
841: public static GBeanInfo getGBeanInfo() {
842: return GBEAN_INFO;
843: }
844:
845: }
|