0001: /*
0002: * Copyright 1999-2004 The Apache Software Foundation
0003: *
0004: * Licensed under the Apache License, Version 2.0 (the "License");
0005: * you may not use this file except in compliance with the License.
0006: * You may obtain a copy of the License at
0007: *
0008: * http://www.apache.org/licenses/LICENSE-2.0
0009: *
0010: * Unless required by applicable law or agreed to in writing, software
0011: * distributed under the License is distributed on an "AS IS" BASIS,
0012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013: * See the License for the specific language governing permissions and
0014: * limitations under the License.
0015: */
0016:
0017: package org.apache.coyote.tomcat4;
0018:
0019: import java.util.Vector;
0020: import org.apache.tomcat.util.IntrospectionUtils;
0021:
0022: import org.apache.coyote.Adapter;
0023: import org.apache.coyote.ProtocolHandler;
0024:
0025: import org.apache.catalina.Connector;
0026: import org.apache.catalina.Container;
0027: import org.apache.catalina.Lifecycle;
0028: import org.apache.catalina.LifecycleException;
0029: import org.apache.catalina.LifecycleListener;
0030: import org.apache.catalina.Logger;
0031: import org.apache.catalina.Request;
0032: import org.apache.catalina.Response;
0033: import org.apache.catalina.Service;
0034: import org.apache.catalina.net.DefaultServerSocketFactory;
0035: import org.apache.catalina.net.ServerSocketFactory;
0036: import org.apache.catalina.util.LifecycleSupport;
0037: import org.apache.catalina.util.StringManager;
0038: import org.apache.commons.modeler.Registry;
0039:
0040: import javax.management.MBeanRegistration;
0041: import javax.management.ObjectName;
0042: import javax.management.MBeanServer;
0043:
0044: /**
0045: * Implementation of a Coyote connector for Tomcat 4.x.
0046: *
0047: * @author Craig R. McClanahan
0048: * @author Remy Maucherat
0049: * @version $Revision: 1.34 $ $Date: 2004/02/24 08:54:29 $
0050: */
0051:
0052: public final class CoyoteConnector implements Connector, Lifecycle,
0053: MBeanRegistration {
0054:
0055: // ----------------------------------------------------- Instance Variables
0056:
0057: /**
0058: * The <code>Service</code> we are associated with (if any).
0059: */
0060: private Service service = null;
0061:
0062: /**
0063: * The accept count for this Connector.
0064: */
0065: private int acceptCount = 10;
0066:
0067: /**
0068: * The IP address on which to bind, if any. If <code>null</code>, all
0069: * addresses on the server will be bound.
0070: */
0071: private String address = null;
0072:
0073: /**
0074: * Do we allow TRACE ?
0075: */
0076: private boolean allowTrace = false;
0077:
0078: /**
0079: * The input buffer size we should create on input streams.
0080: */
0081: private int bufferSize = 2048;
0082:
0083: /**
0084: * The Container used for processing requests received by this Connector.
0085: */
0086: protected Container container = null;
0087:
0088: /**
0089: * The set of processors that have ever been created.
0090: */
0091: private Vector created = new Vector();
0092:
0093: /**
0094: * The current number of processors that have been created.
0095: */
0096: private int curProcessors = 0;
0097:
0098: /**
0099: * The debugging detail level for this component.
0100: */
0101: private int debug = 0;
0102:
0103: /**
0104: * The "enable DNS lookups" flag for this Connector.
0105: */
0106: private boolean enableLookups = false;
0107:
0108: /**
0109: * The server socket factory for this component.
0110: */
0111: private ServerSocketFactory factory = null;
0112:
0113: /**
0114: * Descriptive information about this Connector implementation.
0115: */
0116: private static final String info = "org.apache.coyote.tomcat4.CoyoteConnector2/1.0";
0117:
0118: /**
0119: * The lifecycle event support for this component.
0120: */
0121: protected LifecycleSupport lifecycle = new LifecycleSupport(this );
0122:
0123: /**
0124: * The minimum number of processors to start at initialization time.
0125: */
0126: protected int minProcessors = 5;
0127:
0128: /**
0129: * The maximum amount of spare processors.
0130: */
0131: protected int maxSpareProcessors = 5;
0132:
0133: /**
0134: * The maximum number of processors allowed, or <0 for unlimited.
0135: */
0136: private int maxProcessors = 20;
0137:
0138: /**
0139: * Linger value on the incoming connection.
0140: * Note : a value inferior to 0 means no linger.
0141: */
0142: private int connectionLinger = Constants.DEFAULT_CONNECTION_LINGER;
0143:
0144: /**
0145: * Timeout value on the incoming connection.
0146: * Note : a value of 0 means no timeout.
0147: */
0148: private int connectionTimeout = Constants.DEFAULT_CONNECTION_TIMEOUT;
0149:
0150: /**
0151: * Timeout value on the incoming connection during request processing.
0152: * Note : a value of 0 means no timeout.
0153: */
0154: private int connectionUploadTimeout = Constants.DEFAULT_CONNECTION_UPLOAD_TIMEOUT;
0155:
0156: /**
0157: * Timeout value on the server socket.
0158: * Note : a value of 0 means no timeout.
0159: */
0160: private int serverSocketTimeout = Constants.DEFAULT_SERVER_SOCKET_TIMEOUT;
0161:
0162: /**
0163: * The port number on which we listen for requests.
0164: */
0165: private int port = 8080;
0166:
0167: /**
0168: * The server name to which we should pretend requests to this Connector
0169: * were directed. This is useful when operating Tomcat behind a proxy
0170: * server, so that redirects get constructed accurately. If not specified,
0171: * the server name included in the <code>Host</code> header is used.
0172: */
0173: private String proxyName = null;
0174:
0175: /**
0176: * The server port to which we should pretent requests to this Connector
0177: * were directed. This is useful when operating Tomcat behind a proxy
0178: * server, so that redirects get constructed accurately. If not specified,
0179: * the port number specified by the <code>port</code> property is used.
0180: */
0181: private int proxyPort = 0;
0182:
0183: /**
0184: * The redirect port for non-SSL to SSL redirects.
0185: */
0186: private int redirectPort = 443;
0187:
0188: /**
0189: * The request scheme that will be set on all requests received
0190: * through this connector.
0191: */
0192: private String scheme = "http";
0193:
0194: /**
0195: * The secure connection flag that will be set on all requests received
0196: * through this connector.
0197: */
0198: private boolean secure = false;
0199:
0200: /** For jk, do tomcat authentication if true, trust server if false
0201: */
0202: private boolean tomcatAuthentication = true;
0203:
0204: /**
0205: * The string manager for this package.
0206: */
0207: private StringManager sm = StringManager
0208: .getManager(Constants.Package);
0209:
0210: /**
0211: * Has this component been initialized yet?
0212: */
0213: private boolean initialized = false;
0214:
0215: /**
0216: * Has this component been started yet?
0217: */
0218: private boolean started = false;
0219:
0220: /**
0221: * The shutdown signal to our background thread
0222: */
0223: private boolean stopped = false;
0224:
0225: /**
0226: * The background thread.
0227: */
0228: private Thread thread = null;
0229:
0230: /**
0231: * Use TCP no delay ?
0232: */
0233: private boolean tcpNoDelay = true;
0234:
0235: /**
0236: * Flag to disable setting a seperate time-out for uploads.
0237: * If <code>true</code>, then the <code>timeout</code> parameter is
0238: * ignored. If <code>false</code>, then the <code>timeout</code>
0239: * parameter is used to control uploads.
0240: */
0241: private boolean disableUploadTimeout = false;
0242:
0243: /**
0244: * Maximum number of Keep-Alive requests to honor per connection.
0245: */
0246: private int maxKeepAliveRequests = 100;
0247:
0248: /**
0249: * Compression value.
0250: */
0251: private String compression = "off";
0252:
0253: /**
0254: * Coyote Protocol handler class name.
0255: * Defaults to the Coyote HTTP/1.1 protocolHandler.
0256: */
0257: private String protocolHandlerClassName = "org.apache.coyote.http11.Http11Protocol";
0258:
0259: /**
0260: * Use URI validation for Tomcat 4.0.x.
0261: */
0262: private boolean useURIValidationHack = true;
0263:
0264: /**
0265: * Coyote protocol handler.
0266: */
0267: private ProtocolHandler protocolHandler = null;
0268:
0269: /**
0270: * Coyote adapter.
0271: */
0272: private Adapter adapter = null;
0273:
0274: /**
0275: * URI encoding.
0276: */
0277: private String URIEncoding = null;
0278:
0279: /**
0280: * URI encoding as body.
0281: */
0282: private boolean useBodyEncodingForURI = true;
0283:
0284: // ------------------------------------------------------------- Properties
0285:
0286: /**
0287: * Return the <code>Service</code> with which we are associated (if any).
0288: */
0289: public Service getService() {
0290:
0291: return (this .service);
0292:
0293: }
0294:
0295: /**
0296: * Set the <code>Service</code> with which we are associated (if any).
0297: *
0298: * @param service The service that owns this Engine
0299: */
0300: public void setService(Service service) {
0301:
0302: this .service = service;
0303:
0304: }
0305:
0306: /**
0307: * Return the connection linger for this Connector.
0308: */
0309: public int getConnectionLinger() {
0310:
0311: return (connectionLinger);
0312:
0313: }
0314:
0315: /**
0316: * Set the connection linger for this Connector.
0317: *
0318: * @param count The new connection linge
0319: */
0320: public void setConnectionLinger(int connectionLinger) {
0321:
0322: this .connectionLinger = connectionLinger;
0323:
0324: }
0325:
0326: /**
0327: * Return the connection timeout for this Connector.
0328: */
0329: public int getConnectionTimeout() {
0330:
0331: return (connectionTimeout);
0332:
0333: }
0334:
0335: /**
0336: * Set the connection timeout for this Connector.
0337: *
0338: * @param count The new connection timeout
0339: */
0340: public void setConnectionTimeout(int connectionTimeout) {
0341:
0342: this .connectionTimeout = connectionTimeout;
0343:
0344: }
0345:
0346: /**
0347: * Return the connection upload timeout for this Connector.
0348: */
0349: public int getConnectionUploadTimeout() {
0350:
0351: return (connectionUploadTimeout);
0352:
0353: }
0354:
0355: /**
0356: * Set the connection upload timeout for this Connector.
0357: *
0358: * @param connectionUploadTimeout The new connection upload timeout
0359: */
0360: public void setConnectionUploadTimeout(int connectionUploadTimeout) {
0361:
0362: this .connectionUploadTimeout = connectionUploadTimeout;
0363:
0364: }
0365:
0366: /**
0367: * Return the server socket timeout for this Connector.
0368: */
0369: public int getServerSocketTimeout() {
0370:
0371: return (serverSocketTimeout);
0372:
0373: }
0374:
0375: /**
0376: * Set the server socket timeout for this Connector.
0377: *
0378: * @param connectionUploadTimeout The new server socket timeout
0379: */
0380: public void setServerSocketTimeout(int serverSocketTimeout) {
0381:
0382: this .serverSocketTimeout = serverSocketTimeout;
0383:
0384: }
0385:
0386: /**
0387: * Return the accept count for this Connector.
0388: */
0389: public int getAcceptCount() {
0390:
0391: return (acceptCount);
0392:
0393: }
0394:
0395: /**
0396: * Set the accept count for this Connector.
0397: *
0398: * @param count The new accept count
0399: */
0400: public void setAcceptCount(int count) {
0401:
0402: this .acceptCount = count;
0403:
0404: }
0405:
0406: /**
0407: * Return the bind IP address for this Connector.
0408: */
0409: public String getAddress() {
0410:
0411: return (this .address);
0412:
0413: }
0414:
0415: /**
0416: * Set the bind IP address for this Connector.
0417: *
0418: * @param address The bind IP address
0419: */
0420: public void setAddress(String address) {
0421:
0422: this .address = address;
0423:
0424: }
0425:
0426: /**
0427: * True if the TRACE method is allowed. Default value is "false".
0428: */
0429: public boolean getAllowTrace() {
0430:
0431: return (this .allowTrace);
0432:
0433: }
0434:
0435: /**
0436: * Set the allowTrace flag, to disable or enable the TRACE HTTP method.
0437: *
0438: * @param allowTrace The new allowTrace flag
0439: */
0440: public void setAllowTrace(boolean allowTrace) {
0441:
0442: this .allowTrace = allowTrace;
0443:
0444: }
0445:
0446: /**
0447: * Is this connector available for processing requests?
0448: */
0449: public boolean isAvailable() {
0450:
0451: return (started);
0452:
0453: }
0454:
0455: /**
0456: * Return the input buffer size for this Connector.
0457: */
0458: public int getBufferSize() {
0459:
0460: return (this .bufferSize);
0461:
0462: }
0463:
0464: /**
0465: * Set the input buffer size for this Connector.
0466: *
0467: * @param bufferSize The new input buffer size.
0468: */
0469: public void setBufferSize(int bufferSize) {
0470:
0471: this .bufferSize = bufferSize;
0472:
0473: }
0474:
0475: /**
0476: * Return the Container used for processing requests received by this
0477: * Connector.
0478: */
0479: public Container getContainer() {
0480:
0481: return (container);
0482:
0483: }
0484:
0485: /**
0486: * Set the Container used for processing requests received by this
0487: * Connector.
0488: *
0489: * @param container The new Container to use
0490: */
0491: public void setContainer(Container container) {
0492:
0493: this .container = container;
0494:
0495: }
0496:
0497: /**
0498: * Get the value of compression.
0499: */
0500: public String getCompression() {
0501:
0502: return (compression);
0503:
0504: }
0505:
0506: /**
0507: * Set the value of compression.
0508: *
0509: * @param compression The new compression value, which can be "on", "off"
0510: * or "force"
0511: */
0512: public void setCompression(String compression) {
0513:
0514: this .compression = compression;
0515:
0516: }
0517:
0518: /**
0519: * Return the current number of processors that have been created.
0520: */
0521: public int getCurProcessors() {
0522:
0523: return (curProcessors);
0524:
0525: }
0526:
0527: /**
0528: * Return the debugging detail level for this component.
0529: */
0530: public int getDebug() {
0531:
0532: return (debug);
0533:
0534: }
0535:
0536: /**
0537: * Set the debugging detail level for this component.
0538: *
0539: * @param debug The new debugging detail level
0540: */
0541: public void setDebug(int debug) {
0542:
0543: this .debug = debug;
0544:
0545: }
0546:
0547: /**
0548: * Return the "enable DNS lookups" flag.
0549: */
0550: public boolean getEnableLookups() {
0551:
0552: return (this .enableLookups);
0553:
0554: }
0555:
0556: /**
0557: * Set the "enable DNS lookups" flag.
0558: *
0559: * @param enableLookups The new "enable DNS lookups" flag value
0560: */
0561: public void setEnableLookups(boolean enableLookups) {
0562:
0563: this .enableLookups = enableLookups;
0564:
0565: }
0566:
0567: /**
0568: * Return the server socket factory used by this Container.
0569: */
0570: public ServerSocketFactory getFactory() {
0571:
0572: if (this .factory == null) {
0573: synchronized (this ) {
0574: this .factory = new DefaultServerSocketFactory();
0575: }
0576: }
0577: return (this .factory);
0578:
0579: }
0580:
0581: /**
0582: * Set the server socket factory used by this Container.
0583: *
0584: * @param factory The new server socket factory
0585: */
0586: public void setFactory(ServerSocketFactory factory) {
0587:
0588: this .factory = factory;
0589:
0590: }
0591:
0592: /**
0593: * Return descriptive information about this Connector implementation.
0594: */
0595: public String getInfo() {
0596:
0597: return (info);
0598:
0599: }
0600:
0601: /**
0602: * Return the minimum number of processors to start at initialization.
0603: */
0604: public int getMinProcessors() {
0605:
0606: return (minProcessors);
0607:
0608: }
0609:
0610: /**
0611: * Set the minimum number of processors to start at initialization.
0612: *
0613: * @param minProcessors The new minimum processors
0614: */
0615: public void setMinProcessors(int minProcessors) {
0616:
0617: this .minProcessors = minProcessors;
0618:
0619: }
0620:
0621: /**
0622: * Return the maximum number of processors allowed, or <0 for unlimited.
0623: */
0624: public int getMaxProcessors() {
0625:
0626: return (maxProcessors);
0627:
0628: }
0629:
0630: /**
0631: * Set the maximum number of processors allowed, or <0 for unlimited.
0632: *
0633: * @param maxProcessors The new maximum processors
0634: */
0635: public void setMaxProcessors(int maxProcessors) {
0636:
0637: this .maxProcessors = maxProcessors;
0638:
0639: }
0640:
0641: /**
0642: * Return the maximum number of spare processors allowed.
0643: */
0644: public int getMaxSpareProcessors() {
0645:
0646: return (maxSpareProcessors);
0647:
0648: }
0649:
0650: /**
0651: * Set the maximum number of spare processors allowed.
0652: *
0653: * @param maxSpareProcessors The new maximum of spare processors
0654: */
0655: public void setMaxSpareProcessors(int maxSpareProcessors) {
0656:
0657: this .maxSpareProcessors = maxSpareProcessors;
0658:
0659: }
0660:
0661: /**
0662: * Return the port number on which we listen for requests.
0663: */
0664: public int getPort() {
0665:
0666: return (this .port);
0667:
0668: }
0669:
0670: /**
0671: * Set the port number on which we listen for requests.
0672: *
0673: * @param port The new port number
0674: */
0675: public void setPort(int port) {
0676:
0677: this .port = port;
0678:
0679: }
0680:
0681: /**
0682: * Return the class name of the Coyote protocol handler in use.
0683: */
0684: public String getProtocolHandlerClassName() {
0685:
0686: return (this .protocolHandlerClassName);
0687:
0688: }
0689:
0690: /**
0691: * Set the class name of the Coyote protocol handler which will be used
0692: * by the connector.
0693: *
0694: * @param protocolHandlerClassName The new class name
0695: */
0696: public void setProtocolHandlerClassName(
0697: String protocolHandlerClassName) {
0698:
0699: this .protocolHandlerClassName = protocolHandlerClassName;
0700:
0701: }
0702:
0703: /**
0704: * Return the proxy server name for this Connector.
0705: */
0706: public String getProxyName() {
0707:
0708: return (this .proxyName);
0709:
0710: }
0711:
0712: /**
0713: * Set the proxy server name for this Connector.
0714: *
0715: * @param proxyName The new proxy server name
0716: */
0717: public void setProxyName(String proxyName) {
0718:
0719: if (!"".equals(proxyName)) {
0720: this .proxyName = proxyName;
0721: } else {
0722: this .proxyName = null;
0723: }
0724:
0725: }
0726:
0727: /**
0728: * Return the proxy server port for this Connector.
0729: */
0730: public int getProxyPort() {
0731:
0732: return (this .proxyPort);
0733:
0734: }
0735:
0736: /**
0737: * Set the proxy server port for this Connector.
0738: *
0739: * @param proxyPort The new proxy server port
0740: */
0741: public void setProxyPort(int proxyPort) {
0742:
0743: this .proxyPort = proxyPort;
0744:
0745: }
0746:
0747: /**
0748: * Return the port number to which a request should be redirected if
0749: * it comes in on a non-SSL port and is subject to a security constraint
0750: * with a transport guarantee that requires SSL.
0751: */
0752: public int getRedirectPort() {
0753:
0754: return (this .redirectPort);
0755:
0756: }
0757:
0758: /**
0759: * Set the redirect port number.
0760: *
0761: * @param redirectPort The redirect port number (non-SSL to SSL)
0762: */
0763: public void setRedirectPort(int redirectPort) {
0764:
0765: this .redirectPort = redirectPort;
0766:
0767: }
0768:
0769: /**
0770: * Return the flag that specifies upload time-out behavior.
0771: */
0772: public boolean getDisableUploadTimeout() {
0773: return disableUploadTimeout;
0774: }
0775:
0776: /**
0777: * Set the flag to specify upload time-out behavior.
0778: *
0779: * @param isDisabled If <code>true</code>, then the <code>timeout</code>
0780: * parameter is ignored. If <code>false</code>, then the
0781: * <code>timeout</code> parameter is used to control uploads.
0782: */
0783: public void setDisableUploadTimeout(boolean isDisabled) {
0784: disableUploadTimeout = isDisabled;
0785: }
0786:
0787: /**
0788: * Return the maximum number of Keep-Alive requests to honor per connection.
0789: */
0790: public int getMaxKeepAliveRequests() {
0791: return maxKeepAliveRequests;
0792: }
0793:
0794: /**
0795: * Set the maximum number of Keep-Alive requests to honor per connection.
0796: */
0797: public void setMaxKeepAliveRequests(int mkar) {
0798: maxKeepAliveRequests = mkar;
0799: }
0800:
0801: /**
0802: * Return the scheme that will be assigned to requests received
0803: * through this connector. Default value is "http".
0804: */
0805: public String getScheme() {
0806:
0807: return (this .scheme);
0808:
0809: }
0810:
0811: /**
0812: * Set the scheme that will be assigned to requests received through
0813: * this connector.
0814: *
0815: * @param scheme The new scheme
0816: */
0817: public void setScheme(String scheme) {
0818:
0819: this .scheme = scheme;
0820:
0821: }
0822:
0823: /**
0824: * Return the secure connection flag that will be assigned to requests
0825: * received through this connector. Default value is "false".
0826: */
0827: public boolean getSecure() {
0828:
0829: return (this .secure);
0830:
0831: }
0832:
0833: /**
0834: * Set the secure connection flag that will be assigned to requests
0835: * received through this connector.
0836: *
0837: * @param secure The new secure connection flag
0838: */
0839: public void setSecure(boolean secure) {
0840:
0841: this .secure = secure;
0842:
0843: }
0844:
0845: public boolean getTomcatAuthentication() {
0846: return tomcatAuthentication;
0847: }
0848:
0849: public void setTomcatAuthentication(boolean tomcatAuthentication) {
0850: this .tomcatAuthentication = tomcatAuthentication;
0851: }
0852:
0853: /**
0854: * Return the TCP no delay flag value.
0855: */
0856: public boolean getTcpNoDelay() {
0857:
0858: return (this .tcpNoDelay);
0859:
0860: }
0861:
0862: /**
0863: * Set the TCP no delay flag which will be set on the socket after
0864: * accepting a connection.
0865: *
0866: * @param tcpNoDelay The new TCP no delay flag
0867: */
0868: public void setTcpNoDelay(boolean tcpNoDelay) {
0869:
0870: this .tcpNoDelay = tcpNoDelay;
0871:
0872: }
0873:
0874: /**
0875: * Return the character encoding to be used for the URI.
0876: */
0877: public String getURIEncoding() {
0878:
0879: return (this .URIEncoding);
0880:
0881: }
0882:
0883: /**
0884: * Set the URI encoding to be used for the URI.
0885: *
0886: * @param URIEncoding The new URI character encoding.
0887: */
0888: public void setURIEncoding(String URIEncoding) {
0889:
0890: this .URIEncoding = URIEncoding;
0891:
0892: }
0893:
0894: /**
0895: * Return the true if the entity body encoding should be used for the URI.
0896: */
0897: public boolean getUseBodyEncodingForURI() {
0898:
0899: return (this .useBodyEncodingForURI);
0900:
0901: }
0902:
0903: /**
0904: * Set if the entity body encoding should be used for the URI.
0905: *
0906: * @param useBodyEncodingForURI The new value for the flag.
0907: */
0908: public void setUseBodyEncodingForURI(boolean useBodyEncodingForURI) {
0909:
0910: this .useBodyEncodingForURI = useBodyEncodingForURI;
0911:
0912: }
0913:
0914: /**
0915: * Return the value of the Uri validation flag.
0916: */
0917: public boolean getUseURIValidationHack() {
0918:
0919: return (this .useURIValidationHack);
0920:
0921: }
0922:
0923: /**
0924: * Set the value of the Uri validation flag.
0925: *
0926: * @param useURIValidationHack The new flag value
0927: */
0928: public void setUseURIValidationHack(boolean useURIValidationHack) {
0929:
0930: this .useURIValidationHack = useURIValidationHack;
0931:
0932: }
0933:
0934: // --------------------------------------------------------- Public Methods
0935:
0936: /**
0937: * Create (or allocate) and return a Request object suitable for
0938: * specifying the contents of a Request to the responsible Container.
0939: */
0940: public Request createRequest() {
0941:
0942: CoyoteRequest request = new CoyoteRequest();
0943: request.setConnector(this );
0944: return (request);
0945:
0946: }
0947:
0948: /**
0949: * Create (or allocate) and return a Response object suitable for
0950: * receiving the contents of a Response from the responsible Container.
0951: */
0952: public Response createResponse() {
0953:
0954: CoyoteResponse response = new CoyoteResponse();
0955: response.setConnector(this );
0956: return (response);
0957:
0958: }
0959:
0960: // -------------------------------------------------------- Private Methods
0961:
0962: /**
0963: * Log a message on the Logger associated with our Container (if any).
0964: *
0965: * @param message Message to be logged
0966: */
0967: private void log(String message) {
0968:
0969: Logger logger = container.getLogger();
0970: String localName = "CoyoteConnector";
0971: if (logger != null)
0972: logger.log(localName + " " + message);
0973: else
0974: System.out.println(localName + " " + message);
0975:
0976: }
0977:
0978: /**
0979: * Log a message on the Logger associated with our Container (if any).
0980: *
0981: * @param message Message to be logged
0982: * @param throwable Associated exception
0983: */
0984: private void log(String message, Throwable throwable) {
0985:
0986: Logger logger = container.getLogger();
0987: String localName = "CoyoteConnector";
0988: if (logger != null)
0989: logger.log(localName + " " + message, throwable);
0990: else {
0991: System.out.println(localName + " " + message);
0992: throwable.printStackTrace(System.out);
0993: }
0994:
0995: }
0996:
0997: // ------------------------------------------------------ Lifecycle Methods
0998:
0999: /**
1000: * Add a lifecycle event listener to this component.
1001: *
1002: * @param listener The listener to add
1003: */
1004: public void addLifecycleListener(LifecycleListener listener) {
1005:
1006: lifecycle.addLifecycleListener(listener);
1007:
1008: }
1009:
1010: /**
1011: * Get the lifecycle listeners associated with this lifecycle. If this
1012: * Lifecycle has no listeners registered, a zero-length array is returned.
1013: */
1014: public LifecycleListener[] findLifecycleListeners() {
1015:
1016: return null;//lifecycle.findLifecycleListeners();
1017:
1018: }
1019:
1020: /**
1021: * Remove a lifecycle event listener from this component.
1022: *
1023: * @param listener The listener to add
1024: */
1025: public void removeLifecycleListener(LifecycleListener listener) {
1026:
1027: lifecycle.removeLifecycleListener(listener);
1028:
1029: }
1030:
1031: /**
1032: * Initialize this connector (create ServerSocket here!)
1033: */
1034: public void initialize() throws LifecycleException {
1035:
1036: if (initialized)
1037: throw new LifecycleException(sm
1038: .getString("coyoteConnector.alreadyInitialized"));
1039:
1040: this .initialized = true;
1041:
1042: // Initializa adapter
1043: adapter = new CoyoteAdapter(this );
1044:
1045: // Instantiate protocol handler
1046: try {
1047: Class clazz = Class.forName(protocolHandlerClassName);
1048: protocolHandler = (ProtocolHandler) clazz.newInstance();
1049: } catch (Exception e) {
1050: e.printStackTrace();
1051: throw new LifecycleException(
1052: sm
1053: .getString(
1054: "coyoteConnector.protocolHandlerInstantiationFailed",
1055: e));
1056: }
1057: protocolHandler.setAdapter(adapter);
1058:
1059: IntrospectionUtils.setProperty(protocolHandler, "jkHome",
1060: System.getProperty("catalina.base"));
1061:
1062: // Set attributes
1063: IntrospectionUtils.setProperty(protocolHandler, "port", ""
1064: + port);
1065: IntrospectionUtils.setProperty(protocolHandler, "maxThreads",
1066: "" + maxProcessors);
1067: IntrospectionUtils.setProperty(protocolHandler,
1068: "minSpareThreads", "" + minProcessors);
1069: IntrospectionUtils.setProperty(protocolHandler,
1070: "maxSpareThreads", "" + maxSpareProcessors);
1071: IntrospectionUtils.setProperty(protocolHandler, "backlog", ""
1072: + acceptCount);
1073: IntrospectionUtils.setProperty(protocolHandler, "tcpNoDelay",
1074: "" + tcpNoDelay);
1075: IntrospectionUtils.setProperty(protocolHandler, "soLinger", ""
1076: + connectionLinger);
1077: IntrospectionUtils.setProperty(protocolHandler, "soTimeout", ""
1078: + connectionTimeout);
1079: IntrospectionUtils.setProperty(protocolHandler, "timeout", ""
1080: + connectionUploadTimeout);
1081: IntrospectionUtils.setProperty(protocolHandler,
1082: "serverSoTimeout", "" + serverSocketTimeout);
1083: IntrospectionUtils.setProperty(protocolHandler,
1084: "disableUploadTimeout", "" + disableUploadTimeout);
1085: IntrospectionUtils.setProperty(protocolHandler,
1086: "maxKeepAliveRequests", "" + maxKeepAliveRequests);
1087: IntrospectionUtils.setProperty(protocolHandler,
1088: "tomcatAuthentication", "" + tomcatAuthentication);
1089: IntrospectionUtils.setProperty(protocolHandler, "compression",
1090: compression);
1091: if (address != null) {
1092: IntrospectionUtils.setProperty(protocolHandler, "address",
1093: address);
1094: }
1095:
1096: // Configure secure socket factory
1097: if (factory instanceof CoyoteServerSocketFactory) {
1098: IntrospectionUtils.setProperty(protocolHandler, "secure",
1099: "" + true);
1100: CoyoteServerSocketFactory ssf = (CoyoteServerSocketFactory) factory;
1101: IntrospectionUtils.setProperty(protocolHandler,
1102: "algorithm", ssf.getAlgorithm());
1103: IntrospectionUtils.setProperty(protocolHandler,
1104: "clientauth", ssf.getClientAuth());
1105: IntrospectionUtils.setProperty(protocolHandler, "keystore",
1106: ssf.getKeystoreFile());
1107: IntrospectionUtils.setProperty(protocolHandler,
1108: "randomfile", ssf.getRandomFile());
1109: IntrospectionUtils.setProperty(protocolHandler, "rootfile",
1110: ssf.getRootFile());
1111:
1112: IntrospectionUtils.setProperty(protocolHandler, "keypass",
1113: ssf.getKeystorePass());
1114: IntrospectionUtils.setProperty(protocolHandler, "keytype",
1115: ssf.getKeystoreType());
1116: IntrospectionUtils.setProperty(protocolHandler, "protocol",
1117: ssf.getProtocol());
1118: IntrospectionUtils.setProperty(protocolHandler,
1119: "sSLImplementation", ssf.getSSLImplementation());
1120: } else {
1121: IntrospectionUtils.setProperty(protocolHandler, "secure",
1122: "" + false);
1123: }
1124:
1125: try {
1126: protocolHandler.init();
1127: } catch (Exception e) {
1128: throw new LifecycleException(
1129: sm
1130: .getString(
1131: "coyoteConnector.protocolHandlerInitializationFailed",
1132: e));
1133: }
1134: }
1135:
1136: /**
1137: * Begin processing requests via this Connector.
1138: *
1139: * @exception LifecycleException if a fatal startup error occurs
1140: */
1141: public void start() throws LifecycleException {
1142:
1143: // Validate and update our current state
1144: if (started)
1145: throw new LifecycleException(sm
1146: .getString("coyoteConnector.alreadyStarted"));
1147: lifecycle.fireLifecycleEvent(START_EVENT, null);
1148: started = true;
1149:
1150: // We can't register earlier - the JMX registration of this happens
1151: // in Server.start callback
1152: if (this .oname != null) {
1153: // We are registred - register the adapter as well.
1154: try {
1155: Registry.getRegistry().registerComponent(
1156: protocolHandler,
1157: this .domain
1158: + ":type=protocolHandler,className="
1159: + protocolHandlerClassName, null);
1160: } catch (Exception ex) {
1161: ex.printStackTrace();
1162: }
1163: } else {
1164: log("Coyote can't register jmx for protocol");
1165: }
1166:
1167: try {
1168: protocolHandler.start();
1169: } catch (Exception e) {
1170: throw new LifecycleException(sm.getString(
1171: "coyoteConnector.protocolHandlerStartFailed", e));
1172: }
1173:
1174: }
1175:
1176: /**
1177: * Terminate processing requests via this Connector.
1178: *
1179: * @exception LifecycleException if a fatal shutdown error occurs
1180: */
1181: public void stop() throws LifecycleException {
1182:
1183: // Validate and update our current state
1184: if (!started)
1185: throw new LifecycleException(sm
1186: .getString("coyoteConnector.notStarted"));
1187: lifecycle.fireLifecycleEvent(STOP_EVENT, null);
1188: started = false;
1189:
1190: try {
1191: protocolHandler.destroy();
1192: } catch (Exception e) {
1193: throw new LifecycleException(sm.getString(
1194: "coyoteConnector.protocolHandlerDestroyFailed", e));
1195: }
1196:
1197: }
1198:
1199: protected String domain;
1200: protected ObjectName oname;
1201: protected MBeanServer mserver;
1202:
1203: public ObjectName getObjectName() {
1204: return oname;
1205: }
1206:
1207: public String getDomain() {
1208: return domain;
1209: }
1210:
1211: public ObjectName preRegister(MBeanServer server, ObjectName name)
1212: throws Exception {
1213: oname = name;
1214: mserver = server;
1215: domain = name.getDomain();
1216: return name;
1217: }
1218:
1219: public void postRegister(Boolean registrationDone) {
1220: }
1221:
1222: public void preDeregister() throws Exception {
1223: }
1224:
1225: public void postDeregister() {
1226: }
1227:
1228: }
|