1 /*
2 * Copyright 1999-2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.apache.coyote.tomcat4;
18
19
20 import org.apache.tomcat.util.IntrospectionUtils;
21
22 import org.apache.coyote.Adapter;
23 import org.apache.coyote.ProtocolHandler;
24
25 import org.apache.catalina.Connector;
26 import org.apache.catalina.Container;
27 import org.apache.catalina.Lifecycle;
28 import org.apache.catalina.LifecycleException;
29 import org.apache.catalina.LifecycleListener;
30 import org.apache.catalina.Logger;
31 import org.apache.catalina.Request;
32 import org.apache.catalina.Response;
33 import org.apache.catalina.Service;
34 import org.apache.catalina.net.DefaultServerSocketFactory;
35 import org.apache.catalina.net.ServerSocketFactory;
36 import org.apache.catalina.util.LifecycleSupport;
37 import org.apache.catalina.util.StringManager;
38 import org.apache.commons.modeler.Registry;
39
40 import javax.management.MBeanRegistration;
41 import javax.management.ObjectName;
42 import javax.management.MBeanServer;
43
44
45 /**
46 * Implementation of a Coyote connector for Tomcat 4.x.
47 *
48 * @author Craig R. McClanahan
49 * @author Remy Maucherat
50 * @version $Revision: 301061 $ $Date: 2005-09-20 18:18:40 -0400 (Tue, 20 Sep 2005) $
51 */
52
53 public final class CoyoteConnector
54 implements Connector, Lifecycle, MBeanRegistration {
55
56
57 // ----------------------------------------------------- Instance Variables
58
59
60 /**
61 * The <code>Service</code> we are associated with (if any).
62 */
63 private Service service = null;
64
65
66 /**
67 * The accept count for this Connector.
68 */
69 private int acceptCount = 10;
70
71
72 /**
73 * The IP address on which to bind, if any. If <code>null</code>, all
74 * addresses on the server will be bound.
75 */
76 private String address = null;
77
78
79 /**
80 * Do we allow TRACE ?
81 */
82 private boolean allowTrace = false;
83
84
85 /**
86 * The input buffer size we should create on input streams.
87 */
88 private int bufferSize = 2048;
89
90
91 /**
92 * The Container used for processing requests received by this Connector.
93 */
94 protected Container container = null;
95
96
97 /**
98 * The current number of processors that have been created.
99 */
100 private int curProcessors = 0;
101
102
103 /**
104 * The debugging detail level for this component.
105 */
106 private int debug = 0;
107
108
109 /**
110 * The "enable DNS lookups" flag for this Connector.
111 */
112 private boolean enableLookups = false;
113
114
115 /**
116 * The server socket factory for this component.
117 */
118 private ServerSocketFactory factory = null;
119
120
121 /**
122 * Descriptive information about this Connector implementation.
123 */
124 private static final String info =
125 "org.apache.coyote.tomcat4.CoyoteConnector2/1.0";
126
127
128 /**
129 * The lifecycle event support for this component.
130 */
131 protected LifecycleSupport lifecycle = new LifecycleSupport(this);
132
133
134 /**
135 * The minimum number of processors to start at initialization time.
136 */
137 protected int minProcessors = 5;
138
139
140 /**
141 * The maximum amount of spare processors.
142 */
143 protected int maxSpareProcessors = 5;
144
145
146 /**
147 * The maximum number of processors allowed, or <0 for unlimited.
148 */
149 private int maxProcessors = 20;
150
151 /**
152 * The maximum permitted size of the request and response HTTP headers.
153 */
154 private int maxHttpHeaderSize = 4 * 1024;
155
156 /**
157 * Linger value on the incoming connection.
158 * Note : a value inferior to 0 means no linger.
159 */
160 private int connectionLinger = Constants.DEFAULT_CONNECTION_LINGER;
161
162
163 /**
164 * Timeout value on the incoming connection.
165 * Note : a value of 0 means no timeout.
166 */
167 private int connectionTimeout = Constants.DEFAULT_CONNECTION_TIMEOUT;
168
169
170 /**
171 * Timeout value on the incoming connection during request processing.
172 * Note : a value of 0 means no timeout.
173 */
174 private int connectionUploadTimeout =
175 Constants.DEFAULT_CONNECTION_UPLOAD_TIMEOUT;
176
177
178 /**
179 * Timeout value on the server socket.
180 * Note : a value of 0 means no timeout.
181 */
182 private int serverSocketTimeout = Constants.DEFAULT_SERVER_SOCKET_TIMEOUT;
183
184
185 /**
186 * The port number on which we listen for requests.
187 */
188 private int port = 8080;
189
190
191 /**
192 * The server name to which we should pretend requests to this Connector
193 * were directed. This is useful when operating Tomcat behind a proxy
194 * server, so that redirects get constructed accurately. If not specified,
195 * the server name included in the <code>Host</code> header is used.
196 */
197 private String proxyName = null;
198
199
200 /**
201 * The server port to which we should pretent requests to this Connector
202 * were directed. This is useful when operating Tomcat behind a proxy
203 * server, so that redirects get constructed accurately. If not specified,
204 * the port number specified by the <code>port</code> property is used.
205 */
206 private int proxyPort = 0;
207
208
209 /**
210 * The redirect port for non-SSL to SSL redirects.
211 */
212 private int redirectPort = 443;
213
214
215 /**
216 * The request scheme that will be set on all requests received
217 * through this connector.
218 */
219 private String scheme = "http";
220
221
222 /**
223 * The secure connection flag that will be set on all requests received
224 * through this connector.
225 */
226 private boolean secure = false;
227
228 /** For jk, do tomcat authentication if true, trust server if false
229 */
230 private boolean tomcatAuthentication = true;
231
232 /**
233 * The string manager for this package.
234 */
235 private StringManager sm =
236 StringManager.getManager(Constants.Package);
237
238
239 /**
240 * Has this component been initialized yet?
241 */
242 private boolean initialized = false;
243
244
245 /**
246 * Has this component been started yet?
247 */
248 private boolean started = false;
249
250
251 /**
252 * Use TCP no delay ?
253 */
254 private boolean tcpNoDelay = true;
255
256
257 /**
258 * Flag to disable setting a seperate time-out for uploads.
259 * If <code>true</code>, then the <code>timeout</code> parameter is
260 * ignored. If <code>false</code>, then the <code>timeout</code>
261 * parameter is used to control uploads.
262 */
263 private boolean disableUploadTimeout = false;
264
265 /**
266 * Maximum number of Keep-Alive requests to honor per connection.
267 */
268 private int maxKeepAliveRequests = 100;
269
270
271 /**
272 * Compression value.
273 */
274 private String compressableMimeTypes = "text/html,text/xml,text/plain";
275 private String compression = "off";
276
277
278 /**
279 * Coyote Protocol handler class name.
280 * Defaults to the Coyote HTTP/1.1 protocolHandler.
281 */
282 private String protocolHandlerClassName =
283 "org.apache.coyote.http11.Http11Protocol";
284
285
286 /**
287 * Use URI validation for Tomcat 4.0.x.
288 */
289 private boolean useURIValidationHack = true;
290
291
292 /**
293 * Coyote protocol handler.
294 */
295 private ProtocolHandler protocolHandler = null;
296
297
298 /**
299 * Coyote adapter.
300 */
301 private Adapter adapter = null;
302
303
304 /**
305 * URI encoding.
306 */
307 private String URIEncoding = null;
308
309
310 /**
311 * URI encoding as body.
312 */
313 private boolean useBodyEncodingForURI = true;
314
315
316 // ------------------------------------------------------------- Properties
317
318
319 /**
320 * Return the <code>Service</code> with which we are associated (if any).
321 */
322 public Service getService() {
323
324 return (this.service);
325
326 }
327
328
329 /**
330 * Set the <code>Service</code> with which we are associated (if any).
331 *
332 * @param service The service that owns this Engine
333 */
334 public void setService(Service service) {
335
336 this.service = service;
337
338 }
339
340
341 /**
342 * Return the connection linger for this Connector.
343 */
344 public int getConnectionLinger() {
345
346 return (connectionLinger);
347
348 }
349
350
351 /**
352 * Set the connection linger for this Connector.
353 *
354 * @param connectionLinger The new connection linger
355 */
356 public void setConnectionLinger(int connectionLinger) {
357
358 this.connectionLinger = connectionLinger;
359
360 }
361
362
363 /**
364 * Return the connection timeout for this Connector.
365 */
366 public int getConnectionTimeout() {
367
368 return (connectionTimeout);
369
370 }
371
372
373 /**
374 * Set the connection timeout for this Connector.
375 *
376 * @param connectionTimeout The new connection timeout
377 */
378 public void setConnectionTimeout(int connectionTimeout) {
379
380 this.connectionTimeout = connectionTimeout;
381
382 }
383
384
385 /**
386 * Return the connection upload timeout for this Connector.
387 */
388 public int getConnectionUploadTimeout() {
389
390 return (connectionUploadTimeout);
391
392 }
393
394
395 /**
396 * Set the connection upload timeout for this Connector.
397 *
398 * @param connectionUploadTimeout The new connection upload timeout
399 */
400 public void setConnectionUploadTimeout(int connectionUploadTimeout) {
401
402 this.connectionUploadTimeout = connectionUploadTimeout;
403
404 }
405
406
407 /**
408 * Return the server socket timeout for this Connector.
409 */
410 public int getServerSocketTimeout() {
411
412 return (serverSocketTimeout);
413
414 }
415
416
417 /**
418 * Set the server socket timeout for this Connector.
419 *
420 * @param serverSocketTimeout The new server socket timeout
421 */
422 public void setServerSocketTimeout(int serverSocketTimeout) {
423
424 this.serverSocketTimeout = serverSocketTimeout;
425
426 }
427
428
429 /**
430 * Return the accept count for this Connector.
431 */
432 public int getAcceptCount() {
433
434 return (acceptCount);
435
436 }
437
438
439 /**
440 * Set the accept count for this Connector.
441 *
442 * @param count The new accept count
443 */
444 public void setAcceptCount(int count) {
445
446 this.acceptCount = count;
447
448 }
449
450
451 /**
452 * Return the bind IP address for this Connector.
453 */
454 public String getAddress() {
455
456 return (this.address);
457
458 }
459
460
461 /**
462 * Set the bind IP address for this Connector.
463 *
464 * @param address The bind IP address
465 */
466 public void setAddress(String address) {
467
468 this.address = address;
469
470 }
471
472
473 /**
474 * True if the TRACE method is allowed. Default value is "false".
475 */
476 public boolean getAllowTrace() {
477
478 return (this.allowTrace);
479
480 }
481
482
483 /**
484 * Set the allowTrace flag, to disable or enable the TRACE HTTP method.
485 *
486 * @param allowTrace The new allowTrace flag
487 */
488 public void setAllowTrace(boolean allowTrace) {
489
490 this.allowTrace = allowTrace;
491
492 }
493
494 /**
495 * Is this connector available for processing requests?
496 */
497 public boolean isAvailable() {
498
499 return (started);
500
501 }
502
503
504 /**
505 * Return the input buffer size for this Connector.
506 */
507 public int getBufferSize() {
508
509 return (this.bufferSize);
510
511 }
512
513
514 /**
515 * Set the input buffer size for this Connector.
516 *
517 * @param bufferSize The new input buffer size.
518 */
519 public void setBufferSize(int bufferSize) {
520
521 this.bufferSize = bufferSize;
522
523 }
524
525
526 /**
527 * Return the Container used for processing requests received by this
528 * Connector.
529 */
530 public Container getContainer() {
531
532 return (container);
533
534 }
535
536
537 /**
538 * Set the Container used for processing requests received by this
539 * Connector.
540 *
541 * @param container The new Container to use
542 */
543 public void setContainer(Container container) {
544
545 this.container = container;
546
547 }
548
549 /**
550 * Get the list of compressable MIME types.
551 */
552 public String getCompressableMimeType() {
553 return compressableMimeTypes;
554 }
555
556 /**
557 * Set the list of compressable MIME types.
558 *
559 * @param compressableMimeTypes The new list of MIME types to enable for
560 * compression.
561 */
562 public void setCompressableMimeType(String compressableMimeTypes) {
563 this.compressableMimeTypes = compressableMimeTypes;
564 }
565
566 /**
567 * Get the value of compression.
568 */
569 public String getCompression() {
570
571 return (compression);
572
573 }
574
575
576 /**
577 * Set the value of compression.
578 *
579 * @param compression The new compression value, which can be "on", "off"
580 * or "force"
581 */
582 public void setCompression(String compression) {
583
584 this.compression = compression;
585
586 }
587
588
589 /**
590 * Return the current number of processors that have been created.
591 */
592 public int getCurProcessors() {
593
594 return (curProcessors);
595
596 }
597
598
599 /**
600 * Return the debugging detail level for this component.
601 */
602 public int getDebug() {
603
604 return (debug);
605
606 }
607
608
609 /**
610 * Set the debugging detail level for this component.
611 *
612 * @param debug The new debugging detail level
613 */
614 public void setDebug(int debug) {
615
616 this.debug = debug;
617
618 }
619
620
621 /**
622 * Return the "enable DNS lookups" flag.
623 */
624 public boolean getEnableLookups() {
625
626 return (this.enableLookups);
627
628 }
629
630
631 /**
632 * Set the "enable DNS lookups" flag.
633 *
634 * @param enableLookups The new "enable DNS lookups" flag value
635 */
636 public void setEnableLookups(boolean enableLookups) {
637
638 this.enableLookups = enableLookups;
639
640 }
641
642
643 /**
644 * Return the server socket factory used by this Container.
645 */
646 public ServerSocketFactory getFactory() {
647
648 if (this.factory == null) {
649 synchronized (this) {
650 this.factory = new DefaultServerSocketFactory();
651 }
652 }
653 return (this.factory);
654
655 }
656
657
658 /**
659 * Set the server socket factory used by this Container.
660 *
661 * @param factory The new server socket factory
662 */
663 public void setFactory(ServerSocketFactory factory) {
664
665 this.factory = factory;
666
667 }
668
669
670 /**
671 * Return descriptive information about this Connector implementation.
672 */
673 public String getInfo() {
674
675 return (info);
676
677 }
678
679
680 /**
681 * Return the minimum number of processors to start at initialization.
682 */
683 public int getMinProcessors() {
684
685 return (minProcessors);
686
687 }
688
689
690 /**
691 * Set the minimum number of processors to start at initialization.
692 *
693 * @param minProcessors The new minimum processors
694 */
695 public void setMinProcessors(int minProcessors) {
696
697 this.minProcessors = minProcessors;
698
699 }
700
701
702 /**
703 * Return the maximum number of processors allowed, or <0 for unlimited.
704 */
705 public int getMaxProcessors() {
706
707 return (maxProcessors);
708
709 }
710
711
712 /**
713 * Set the maximum number of processors allowed, or <0 for unlimited.
714 *
715 * @param maxProcessors The new maximum processors
716 */
717 public void setMaxProcessors(int maxProcessors) {
718
719 this.maxProcessors = maxProcessors;
720
721 }
722
723
724 /**
725 * Return the maximum number of spare processors allowed.
726 */
727 public int getMaxSpareProcessors() {
728
729 return (maxSpareProcessors);
730
731 }
732
733
734 /**
735 * Set the maximum number of spare processors allowed.
736 *
737 * @param maxSpareProcessors The new maximum of spare processors
738 */
739 public void setMaxSpareProcessors(int maxSpareProcessors) {
740
741 this.maxSpareProcessors = maxSpareProcessors;
742
743 }
744
745 /**
746 * Return the maximum permitted size of the HTTP request and response
747 * headers.
748 */
749 public int getMaxHttpHeaderSize() {
750 return maxHttpHeaderSize;
751 }
752
753 /**
754 * Set the maximum permitted size of the HTTP request and response
755 * headers.
756 *
757 * @param maxHttpHeaderSize The new maximum header size in bytes.
758 */
759 public void setMaxHttpHeaderSize(int maxHttpHeaderSize) {
760 this.maxHttpHeaderSize = maxHttpHeaderSize;
761 }
762
763 /**
764 * Return the port number on which we listen for requests.
765 */
766 public int getPort() {
767
768 return (this.port);
769
770 }
771
772
773 /**
774 * Set the port number on which we listen for requests.
775 *
776 * @param port The new port number
777 */
778 public void setPort(int port) {
779
780 this.port = port;
781
782 }
783
784
785 /**
786 * Return the class name of the Coyote protocol handler in use.
787 */
788 public String getProtocolHandlerClassName() {
789
790 return (this.protocolHandlerClassName);
791
792 }
793
794
795 /**
796 * Set the class name of the Coyote protocol handler which will be used
797 * by the connector.
798 *
799 * @param protocolHandlerClassName The new class name
800 */
801 public void setProtocolHandlerClassName(String protocolHandlerClassName) {
802
803 this.protocolHandlerClassName = protocolHandlerClassName;
804
805 }
806
807
808 /**
809 * Return the proxy server name for this Connector.
810 */
811 public String getProxyName() {
812
813 return (this.proxyName);
814
815 }
816
817
818 /**
819 * Set the proxy server name for this Connector.
820 *
821 * @param proxyName The new proxy server name
822 */
823 public void setProxyName(String proxyName) {
824
825 if(! "".equals(proxyName) ) {
826 this.proxyName = proxyName;
827 } else {
828 this.proxyName = null;
829 }
830
831 }
832
833
834 /**
835 * Return the proxy server port for this Connector.
836 */
837 public int getProxyPort() {
838
839 return (this.proxyPort);
840
841 }
842
843
844 /**
845 * Set the proxy server port for this Connector.
846 *
847 * @param proxyPort The new proxy server port
848 */
849 public void setProxyPort(int proxyPort) {
850
851 this.proxyPort = proxyPort;
852
853 }
854
855
856 /**
857 * Return the port number to which a request should be redirected if
858 * it comes in on a non-SSL port and is subject to a security constraint
859 * with a transport guarantee that requires SSL.
860 */
861 public int getRedirectPort() {
862
863 return (this.redirectPort);
864
865 }
866
867
868 /**
869 * Set the redirect port number.
870 *
871 * @param redirectPort The redirect port number (non-SSL to SSL)
872 */
873 public void setRedirectPort(int redirectPort) {
874
875 this.redirectPort = redirectPort;
876
877 }
878
879 /**
880 * Return the flag that specifies upload time-out behavior.
881 */
882 public boolean getDisableUploadTimeout() {
883 return disableUploadTimeout;
884 }
885
886 /**
887 * Set the flag to specify upload time-out behavior.
888 *
889 * @param isDisabled If <code>true</code>, then the <code>timeout</code>
890 * parameter is ignored. If <code>false</code>, then the
891 * <code>timeout</code> parameter is used to control uploads.
892 */
893 public void setDisableUploadTimeout( boolean isDisabled ) {
894 disableUploadTimeout = isDisabled;
895 }
896
897 /**
898 * Return the maximum number of Keep-Alive requests to honor per connection.
899 */
900 public int getMaxKeepAliveRequests() {
901 return maxKeepAliveRequests;
902 }
903
904 /**
905 * Set the maximum number of Keep-Alive requests to honor per connection.
906 */
907 public void setMaxKeepAliveRequests(int mkar) {
908 maxKeepAliveRequests = mkar;
909 }
910
911 /**
912 * Return the scheme that will be assigned to requests received
913 * through this connector. Default value is "http".
914 */
915 public String getScheme() {
916
917 return (this.scheme);
918
919 }
920
921
922 /**
923 * Set the scheme that will be assigned to requests received through
924 * this connector.
925 *
926 * @param scheme The new scheme
927 */
928 public void setScheme(String scheme) {
929
930 this.scheme = scheme;
931
932 }
933
934
935 /**
936 * Return the secure connection flag that will be assigned to requests
937 * received through this connector. Default value is "false".
938 */
939 public boolean getSecure() {
940
941 return (this.secure);
942
943 }
944
945
946 /**
947 * Set the secure connection flag that will be assigned to requests
948 * received through this connector.
949 *
950 * @param secure The new secure connection flag
951 */
952 public void setSecure(boolean secure) {
953
954 this.secure = secure;
955
956 }
957
958 public boolean getTomcatAuthentication() {
959 return tomcatAuthentication;
960 }
961
962 public void setTomcatAuthentication(boolean tomcatAuthentication) {
963 this.tomcatAuthentication = tomcatAuthentication;
964 }
965
966 /**
967 * Return the TCP no delay flag value.
968 */
969 public boolean getTcpNoDelay() {
970
971 return (this.tcpNoDelay);
972
973 }
974
975
976 /**
977 * Set the TCP no delay flag which will be set on the socket after
978 * accepting a connection.
979 *
980 * @param tcpNoDelay The new TCP no delay flag
981 */
982 public void setTcpNoDelay(boolean tcpNoDelay) {
983
984 this.tcpNoDelay = tcpNoDelay;
985
986 }
987
988
989 /**
990 * Return the character encoding to be used for the URI.
991 */
992 public String getURIEncoding() {
993
994 return (this.URIEncoding);
995
996 }
997
998
999 /**
1000 * Set the URI encoding to be used for the URI.
1001 *
1002 * @param URIEncoding The new URI character encoding.
1003 */
1004 public void setURIEncoding(String URIEncoding) {
1005
1006 this.URIEncoding = URIEncoding;
1007
1008 }
1009
1010
1011 /**
1012 * Return the true if the entity body encoding should be used for the URI.
1013 */
1014 public boolean getUseBodyEncodingForURI() {
1015
1016 return (this.useBodyEncodingForURI);
1017
1018 }
1019
1020
1021 /**
1022 * Set if the entity body encoding should be used for the URI.
1023 *
1024 * @param useBodyEncodingForURI The new value for the flag.
1025 */
1026 public void setUseBodyEncodingForURI(boolean useBodyEncodingForURI) {
1027
1028 this.useBodyEncodingForURI = useBodyEncodingForURI;
1029
1030 }
1031
1032
1033 /**
1034 * Return the value of the Uri validation flag.
1035 */
1036 public boolean getUseURIValidationHack() {
1037
1038 return (this.useURIValidationHack);
1039
1040 }
1041
1042
1043 /**
1044 * Set the value of the Uri validation flag.
1045 *
1046 * @param useURIValidationHack The new flag value
1047 */
1048 public void setUseURIValidationHack(boolean useURIValidationHack) {
1049
1050 this.useURIValidationHack = useURIValidationHack;
1051
1052 }
1053
1054
1055 // --------------------------------------------------------- Public Methods
1056
1057
1058 /**
1059 * Create (or allocate) and return a Request object suitable for
1060 * specifying the contents of a Request to the responsible Container.
1061 */
1062 public Request createRequest() {
1063
1064 CoyoteRequest request = new CoyoteRequest();
1065 request.setConnector(this);
1066 return (request);
1067
1068 }
1069
1070
1071 /**
1072 * Create (or allocate) and return a Response object suitable for
1073 * receiving the contents of a Response from the responsible Container.
1074 */
1075 public Response createResponse() {
1076
1077 CoyoteResponse response = new CoyoteResponse();
1078 response.setConnector(this);
1079 return (response);
1080
1081 }
1082
1083
1084 // -------------------------------------------------------- Private Methods
1085
1086
1087 /**
1088 * Log a message on the Logger associated with our Container (if any).
1089 *
1090 * @param message Message to be logged
1091 */
1092 private void log(String message) {
1093
1094 Logger logger = container.getLogger();
1095 String localName = "CoyoteConnector";
1096 if (logger != null)
1097 logger.log(localName + " " + message);
1098 else
1099 System.out.println(localName + " " + message);
1100
1101 }
1102
1103
1104 // ------------------------------------------------------ Lifecycle Methods
1105
1106
1107 /**
1108 * Add a lifecycle event listener to this component.
1109 *
1110 * @param listener The listener to add
1111 */
1112 public void addLifecycleListener(LifecycleListener listener) {
1113
1114 lifecycle.addLifecycleListener(listener);
1115
1116 }
1117
1118
1119 /**
1120 * Get the lifecycle listeners associated with this lifecycle. If this
1121 * Lifecycle has no listeners registered, a zero-length array is returned.
1122 */
1123 public LifecycleListener[] findLifecycleListeners() {
1124
1125 return null;//lifecycle.findLifecycleListeners();
1126
1127 }
1128
1129
1130 /**
1131 * Remove a lifecycle event listener from this component.
1132 *
1133 * @param listener The listener to add
1134 */
1135 public void removeLifecycleListener(LifecycleListener listener) {
1136
1137 lifecycle.removeLifecycleListener(listener);
1138
1139 }
1140
1141
1142 /**
1143 * Initialize this connector (create ServerSocket here!)
1144 */
1145 public void initialize()
1146 throws LifecycleException {
1147
1148 if (initialized)
1149 throw new LifecycleException
1150 (sm.getString("coyoteConnector.alreadyInitialized"));
1151
1152 this.initialized = true;
1153
1154 // Initializa adapter
1155 adapter = new CoyoteAdapter(this);
1156
1157 // Instantiate protocol handler
1158 try {
1159 Class clazz = Class.forName(protocolHandlerClassName);
1160 protocolHandler = (ProtocolHandler) clazz.newInstance();
1161 } catch (Exception e) {
1162 e.printStackTrace();
1163 throw new LifecycleException
1164 (sm.getString
1165 ("coyoteConnector.protocolHandlerInstantiationFailed", e));
1166 }
1167 protocolHandler.setAdapter(adapter);
1168
1169 IntrospectionUtils.setProperty(protocolHandler, "jkHome",
1170 System.getProperty("catalina.base"));
1171
1172 // Set attributes
1173 IntrospectionUtils.setProperty(protocolHandler, "port", "" + port);
1174 IntrospectionUtils.setProperty(protocolHandler, "maxThreads",
1175 "" + maxProcessors);
1176 IntrospectionUtils.setProperty(protocolHandler, "minSpareThreads",
1177 "" + minProcessors);
1178 IntrospectionUtils.setProperty(protocolHandler, "maxSpareThreads",
1179 "" + maxSpareProcessors);
1180 IntrospectionUtils.setProperty(protocolHandler, "backlog",
1181 "" + acceptCount);
1182 IntrospectionUtils.setProperty(protocolHandler, "tcpNoDelay",
1183 "" + tcpNoDelay);
1184 IntrospectionUtils.setProperty(protocolHandler, "soLinger",
1185 "" + connectionLinger);
1186 IntrospectionUtils.setProperty(protocolHandler, "soTimeout",
1187 "" + connectionTimeout);
1188 IntrospectionUtils.setProperty(protocolHandler, "timeout",
1189 "" + connectionUploadTimeout);
1190 IntrospectionUtils.setProperty(protocolHandler, "serverSoTimeout",
1191 "" + serverSocketTimeout);
1192 IntrospectionUtils.setProperty(protocolHandler, "disableUploadTimeout",
1193 "" + disableUploadTimeout);
1194 IntrospectionUtils.setProperty(protocolHandler, "maxKeepAliveRequests",
1195 "" + maxKeepAliveRequests);
1196 IntrospectionUtils.setProperty(protocolHandler, "tomcatAuthentication",
1197 "" + tomcatAuthentication);
1198 IntrospectionUtils.setProperty(protocolHandler, "compression",
1199 compression);
1200 IntrospectionUtils.setProperty(protocolHandler, "compressableMimeTypes",
1201 compressableMimeTypes);
1202 IntrospectionUtils.setProperty(protocolHandler, "maxHttpHeaderSize",
1203 "" + maxHttpHeaderSize);
1204 if (address != null) {
1205 IntrospectionUtils.setProperty(protocolHandler, "address",
1206 address);
1207 }
1208
1209 // Configure secure socket factory
1210 if (factory instanceof CoyoteServerSocketFactory) {
1211 IntrospectionUtils.setProperty(protocolHandler, "secure",
1212 "" + true);
1213 CoyoteServerSocketFactory ssf =
1214 (CoyoteServerSocketFactory) factory;
1215 IntrospectionUtils.setProperty(protocolHandler, "algorithm",
1216 ssf.getAlgorithm());
1217 IntrospectionUtils.setProperty(protocolHandler, "clientauth",
1218 ssf.getClientAuth());
1219 IntrospectionUtils.setProperty(protocolHandler, "keystore",
1220 ssf.getKeystoreFile());
1221 IntrospectionUtils.setProperty(protocolHandler, "randomfile",
1222 ssf.getRandomFile());
1223 IntrospectionUtils.setProperty(protocolHandler, "rootfile",
1224 ssf.getRootFile());
1225
1226 IntrospectionUtils.setProperty(protocolHandler, "keypass",
1227 ssf.getKeystorePass());
1228 IntrospectionUtils.setProperty(protocolHandler, "keytype",
1229 ssf.getKeystoreType());
1230 IntrospectionUtils.setProperty(protocolHandler, "protocol",
1231 ssf.getProtocol());
1232 IntrospectionUtils.setProperty(protocolHandler,
1233 "sSLImplementation",
1234 ssf.getSSLImplementation());
1235 } else {
1236 IntrospectionUtils.setProperty(protocolHandler, "secure",
1237 "" + false);
1238 }
1239
1240 try {
1241 protocolHandler.init();
1242 } catch (Exception e) {
1243 throw new LifecycleException
1244 (sm.getString
1245 ("coyoteConnector.protocolHandlerInitializationFailed", e));
1246 }
1247 }
1248
1249
1250 /**
1251 * Begin processing requests via this Connector.
1252 *
1253 * @exception LifecycleException if a fatal startup error occurs
1254 */
1255 public void start() throws LifecycleException {
1256
1257 // Validate and update our current state
1258 if (started)
1259 throw new LifecycleException
1260 (sm.getString("coyoteConnector.alreadyStarted"));
1261 lifecycle.fireLifecycleEvent(START_EVENT, null);
1262 started = true;
1263
1264 // We can't register earlier - the JMX registration of this happens
1265 // in Server.start callback
1266 if( this.oname != null ) {
1267 // We are registred - register the adapter as well.
1268 try {
1269 Registry.getRegistry().registerComponent(protocolHandler,
1270 this.domain +
1271 ":type=protocolHandler,className=" + protocolHandlerClassName, null);
1272 } catch( Exception ex ) {
1273 ex.printStackTrace();
1274 }
1275 } else {
1276 log( "Coyote can't register jmx for protocol");
1277 }
1278
1279 try {
1280 protocolHandler.start();
1281 } catch (Exception e) {
1282 throw new LifecycleException
1283 (sm.getString
1284 ("coyoteConnector.protocolHandlerStartFailed", e));
1285 }
1286
1287 }
1288
1289
1290 /**
1291 * Terminate processing requests via this Connector.
1292 *
1293 * @exception LifecycleException if a fatal shutdown error occurs
1294 */
1295 public void stop() throws LifecycleException {
1296
1297 // Validate and update our current state
1298 if (!started)
1299 throw new LifecycleException
1300 (sm.getString("coyoteConnector.notStarted"));
1301 lifecycle.fireLifecycleEvent(STOP_EVENT, null);
1302 started = false;
1303
1304 try {
1305 protocolHandler.destroy();
1306 } catch (Exception e) {
1307 throw new LifecycleException
1308 (sm.getString
1309 ("coyoteConnector.protocolHandlerDestroyFailed", e));
1310 }
1311
1312 }
1313
1314 protected String domain;
1315 protected ObjectName oname;
1316 protected MBeanServer mserver;
1317
1318 public ObjectName getObjectName() {
1319 return oname;
1320 }
1321
1322 public String getDomain() {
1323 return domain;
1324 }
1325
1326 public ObjectName preRegister(MBeanServer server,
1327 ObjectName name) throws Exception {
1328 oname=name;
1329 mserver=server;
1330 domain=name.getDomain();
1331 return name;
1332 }
1333
1334 public void postRegister(Boolean registrationDone) {
1335 }
1336
1337 public void preDeregister() throws Exception {
1338 }
1339
1340 public void postDeregister() {
1341 }
1342
1343 }