KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > coyote > tomcat4 > CoyoteConnector


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 java.util.Vector JavaDoc;
21 import org.apache.tomcat.util.IntrospectionUtils;
22
23 import org.apache.coyote.Adapter;
24 import org.apache.coyote.ProtocolHandler;
25
26 import org.apache.catalina.Connector;
27 import org.apache.catalina.Container;
28 import org.apache.catalina.Lifecycle;
29 import org.apache.catalina.LifecycleException;
30 import org.apache.catalina.LifecycleListener;
31 import org.apache.catalina.Logger;
32 import org.apache.catalina.Request;
33 import org.apache.catalina.Response;
34 import org.apache.catalina.Service;
35 import org.apache.catalina.net.DefaultServerSocketFactory;
36 import org.apache.catalina.net.ServerSocketFactory;
37 import org.apache.catalina.util.LifecycleSupport;
38 import org.apache.catalina.util.StringManager;
39 import org.apache.commons.modeler.Registry;
40
41 import javax.management.MBeanRegistration JavaDoc;
42 import javax.management.ObjectName JavaDoc;
43 import javax.management.MBeanServer JavaDoc;
44
45
46 /**
47  * Implementation of a Coyote connector for Tomcat 4.x.
48  *
49  * @author Craig R. McClanahan
50  * @author Remy Maucherat
51  * @version $Revision: 1.35 $ $Date: 2004/08/29 17:14:41 $
52  */

53
54 public final class CoyoteConnector
55     implements Connector, Lifecycle, MBeanRegistration JavaDoc {
56
57
58     // ----------------------------------------------------- Instance Variables
59

60
61     /**
62      * The <code>Service</code> we are associated with (if any).
63      */

64     private Service service = null;
65
66
67     /**
68      * The accept count for this Connector.
69      */

70     private int acceptCount = 10;
71
72
73     /**
74      * The IP address on which to bind, if any. If <code>null</code>, all
75      * addresses on the server will be bound.
76      */

77     private String JavaDoc address = null;
78
79
80     /**
81      * Do we allow TRACE ?
82      */

83     private boolean allowTrace = false;
84
85
86     /**
87      * The input buffer size we should create on input streams.
88      */

89     private int bufferSize = 2048;
90
91
92     /**
93      * The Container used for processing requests received by this Connector.
94      */

95     protected Container container = null;
96
97
98     /**
99      * The set of processors that have ever been created.
100      */

101     private Vector JavaDoc created = new Vector JavaDoc();
102
103
104     /**
105      * The current number of processors that have been created.
106      */

107     private int curProcessors = 0;
108
109
110     /**
111      * The debugging detail level for this component.
112      */

113     private int debug = 0;
114
115
116     /**
117      * The "enable DNS lookups" flag for this Connector.
118      */

119     private boolean enableLookups = false;
120
121
122     /**
123      * The server socket factory for this component.
124      */

125     private ServerSocketFactory factory = null;
126
127
128     /**
129      * Descriptive information about this Connector implementation.
130      */

131     private static final String JavaDoc info =
132         "org.apache.coyote.tomcat4.CoyoteConnector2/1.0";
133
134
135     /**
136      * The lifecycle event support for this component.
137      */

138     protected LifecycleSupport lifecycle = new LifecycleSupport(this);
139
140
141     /**
142      * The minimum number of processors to start at initialization time.
143      */

144     protected int minProcessors = 5;
145
146
147     /**
148      * The maximum amount of spare processors.
149      */

150     protected int maxSpareProcessors = 5;
151
152
153     /**
154      * The maximum number of processors allowed, or <0 for unlimited.
155      */

156     private int maxProcessors = 20;
157
158
159     /**
160      * Linger value on the incoming connection.
161      * Note : a value inferior to 0 means no linger.
162      */

163     private int connectionLinger = Constants.DEFAULT_CONNECTION_LINGER;
164
165
166     /**
167      * Timeout value on the incoming connection.
168      * Note : a value of 0 means no timeout.
169      */

170     private int connectionTimeout = Constants.DEFAULT_CONNECTION_TIMEOUT;
171
172
173     /**
174      * Timeout value on the incoming connection during request processing.
175      * Note : a value of 0 means no timeout.
176      */

177     private int connectionUploadTimeout =
178         Constants.DEFAULT_CONNECTION_UPLOAD_TIMEOUT;
179
180
181     /**
182      * Timeout value on the server socket.
183      * Note : a value of 0 means no timeout.
184      */

185     private int serverSocketTimeout = Constants.DEFAULT_SERVER_SOCKET_TIMEOUT;
186
187
188     /**
189      * The port number on which we listen for requests.
190      */

191     private int port = 8080;
192
193
194     /**
195      * The server name to which we should pretend requests to this Connector
196      * were directed. This is useful when operating Tomcat behind a proxy
197      * server, so that redirects get constructed accurately. If not specified,
198      * the server name included in the <code>Host</code> header is used.
199      */

200     private String JavaDoc proxyName = null;
201
202
203     /**
204      * The server port to which we should pretent requests to this Connector
205      * were directed. This is useful when operating Tomcat behind a proxy
206      * server, so that redirects get constructed accurately. If not specified,
207      * the port number specified by the <code>port</code> property is used.
208      */

209     private int proxyPort = 0;
210
211
212     /**
213      * The redirect port for non-SSL to SSL redirects.
214      */

215     private int redirectPort = 443;
216
217
218     /**
219      * The request scheme that will be set on all requests received
220      * through this connector.
221      */

222     private String JavaDoc scheme = "http";
223
224
225     /**
226      * The secure connection flag that will be set on all requests received
227      * through this connector.
228      */

229     private boolean secure = false;
230
231     /** For jk, do tomcat authentication if true, trust server if false
232      */

233     private boolean tomcatAuthentication = true;
234
235     /**
236      * The string manager for this package.
237      */

238     private StringManager sm =
239         StringManager.getManager(Constants.Package);
240
241
242     /**
243      * Has this component been initialized yet?
244      */

245     private boolean initialized = false;
246
247
248     /**
249      * Has this component been started yet?
250      */

251     private boolean started = false;
252
253
254     /**
255      * The shutdown signal to our background thread
256      */

257     private boolean stopped = false;
258
259
260     /**
261      * The background thread.
262      */

263     private Thread JavaDoc thread = null;
264
265
266     /**
267      * Use TCP no delay ?
268      */

269     private boolean tcpNoDelay = true;
270
271
272     /**
273      * Flag to disable setting a seperate time-out for uploads.
274      * If <code>true</code>, then the <code>timeout</code> parameter is
275      * ignored. If <code>false</code>, then the <code>timeout</code>
276      * parameter is used to control uploads.
277      */

278     private boolean disableUploadTimeout = false;
279
280     /**
281      * Maximum number of Keep-Alive requests to honor per connection.
282      */

283     private int maxKeepAliveRequests = 100;
284
285
286     /**
287      * Compression value.
288      */

289     private String JavaDoc compression = "off";
290
291
292     /**
293      * Coyote Protocol handler class name.
294      * Defaults to the Coyote HTTP/1.1 protocolHandler.
295      */

296     private String JavaDoc protocolHandlerClassName =
297         "org.apache.coyote.http11.Http11Protocol";
298
299
300     /**
301      * Use URI validation for Tomcat 4.0.x.
302      */

303     private boolean useURIValidationHack = true;
304
305
306     /**
307      * Coyote protocol handler.
308      */

309     private ProtocolHandler protocolHandler = null;
310
311
312     /**
313      * Coyote adapter.
314      */

315     private Adapter adapter = null;
316
317
318      /**
319       * URI encoding.
320       */

321      private String JavaDoc URIEncoding = null;
322
323
324      /**
325       * URI encoding as body.
326       */

327      private boolean useBodyEncodingForURI = true;
328
329
330     // ------------------------------------------------------------- Properties
331

332
333     /**
334      * Return the <code>Service</code> with which we are associated (if any).
335      */

336     public Service getService() {
337
338         return (this.service);
339
340     }
341
342
343     /**
344      * Set the <code>Service</code> with which we are associated (if any).
345      *
346      * @param service The service that owns this Engine
347      */

348     public void setService(Service service) {
349
350         this.service = service;
351
352     }
353
354
355     /**
356      * Return the connection linger for this Connector.
357      */

358     public int getConnectionLinger() {
359
360         return (connectionLinger);
361
362     }
363
364
365     /**
366      * Set the connection linger for this Connector.
367      *
368      * @param connectionLinger The new connection linger
369      */

370     public void setConnectionLinger(int connectionLinger) {
371
372         this.connectionLinger = connectionLinger;
373
374     }
375
376
377     /**
378      * Return the connection timeout for this Connector.
379      */

380     public int getConnectionTimeout() {
381
382         return (connectionTimeout);
383
384     }
385
386
387     /**
388      * Set the connection timeout for this Connector.
389      *
390      * @param connectionTimeout The new connection timeout
391      */

392     public void setConnectionTimeout(int connectionTimeout) {
393
394         this.connectionTimeout = connectionTimeout;
395
396     }
397
398
399     /**
400      * Return the connection upload timeout for this Connector.
401      */

402     public int getConnectionUploadTimeout() {
403
404         return (connectionUploadTimeout);
405
406     }
407
408
409     /**
410      * Set the connection upload timeout for this Connector.
411      *
412      * @param connectionUploadTimeout The new connection upload timeout
413      */

414     public void setConnectionUploadTimeout(int connectionUploadTimeout) {
415
416         this.connectionUploadTimeout = connectionUploadTimeout;
417
418     }
419
420
421     /**
422      * Return the server socket timeout for this Connector.
423      */

424     public int getServerSocketTimeout() {
425
426         return (serverSocketTimeout);
427
428     }
429
430
431     /**
432      * Set the server socket timeout for this Connector.
433      *
434      * @param serverSocketTimeout The new server socket timeout
435      */

436     public void setServerSocketTimeout(int serverSocketTimeout) {
437
438         this.serverSocketTimeout = serverSocketTimeout;
439
440     }
441
442
443     /**
444      * Return the accept count for this Connector.
445      */

446     public int getAcceptCount() {
447
448         return (acceptCount);
449
450     }
451
452
453     /**
454      * Set the accept count for this Connector.
455      *
456      * @param count The new accept count
457      */

458     public void setAcceptCount(int count) {
459
460         this.acceptCount = count;
461
462     }
463
464
465     /**
466      * Return the bind IP address for this Connector.
467      */

468     public String JavaDoc getAddress() {
469
470         return (this.address);
471
472     }
473
474
475     /**
476      * Set the bind IP address for this Connector.
477      *
478      * @param address The bind IP address
479      */

480     public void setAddress(String JavaDoc address) {
481
482         this.address = address;
483
484     }
485
486
487     /**
488      * True if the TRACE method is allowed. Default value is "false".
489      */

490     public boolean getAllowTrace() {
491
492         return (this.allowTrace);
493
494     }
495
496
497     /**
498      * Set the allowTrace flag, to disable or enable the TRACE HTTP method.
499      *
500      * @param allowTrace The new allowTrace flag
501      */

502     public void setAllowTrace(boolean allowTrace) {
503
504         this.allowTrace = allowTrace;
505
506     }
507
508     /**
509      * Is this connector available for processing requests?
510      */

511     public boolean isAvailable() {
512
513         return (started);
514
515     }
516
517
518     /**
519      * Return the input buffer size for this Connector.
520      */

521     public int getBufferSize() {
522
523         return (this.bufferSize);
524
525     }
526
527
528     /**
529      * Set the input buffer size for this Connector.
530      *
531      * @param bufferSize The new input buffer size.
532      */

533     public void setBufferSize(int bufferSize) {
534
535         this.bufferSize = bufferSize;
536
537     }
538
539
540     /**
541      * Return the Container used for processing requests received by this
542      * Connector.
543      */

544     public Container getContainer() {
545
546         return (container);
547
548     }
549
550
551     /**
552      * Set the Container used for processing requests received by this
553      * Connector.
554      *
555      * @param container The new Container to use
556      */

557     public void setContainer(Container container) {
558
559         this.container = container;
560
561     }
562
563
564     /**
565      * Get the value of compression.
566      */

567     public String JavaDoc getCompression() {
568
569         return (compression);
570
571     }
572
573
574     /**
575      * Set the value of compression.
576      *
577      * @param compression The new compression value, which can be "on", "off"
578      * or "force"
579      */

580     public void setCompression(String JavaDoc compression) {
581
582         this.compression = compression;
583
584     }
585
586
587     /**
588      * Return the current number of processors that have been created.
589      */

590     public int getCurProcessors() {
591
592         return (curProcessors);
593
594     }
595
596
597     /**
598      * Return the debugging detail level for this component.
599      */

600     public int getDebug() {
601
602         return (debug);
603
604     }
605
606
607     /**
608      * Set the debugging detail level for this component.
609      *
610      * @param debug The new debugging detail level
611      */

612     public void setDebug(int debug) {
613
614         this.debug = debug;
615
616     }
617
618
619     /**
620      * Return the "enable DNS lookups" flag.
621      */

622     public boolean getEnableLookups() {
623
624         return (this.enableLookups);
625
626     }
627
628
629     /**
630      * Set the "enable DNS lookups" flag.
631      *
632      * @param enableLookups The new "enable DNS lookups" flag value
633      */

634     public void setEnableLookups(boolean enableLookups) {
635
636         this.enableLookups = enableLookups;
637
638     }
639
640
641     /**
642      * Return the server socket factory used by this Container.
643      */

644     public ServerSocketFactory getFactory() {
645
646         if (this.factory == null) {
647             synchronized (this) {
648                 this.factory = new DefaultServerSocketFactory();
649             }
650         }
651         return (this.factory);
652
653     }
654
655
656     /**
657      * Set the server socket factory used by this Container.
658      *
659      * @param factory The new server socket factory
660      */

661     public void setFactory(ServerSocketFactory factory) {
662
663         this.factory = factory;
664
665     }
666
667
668     /**
669      * Return descriptive information about this Connector implementation.
670      */

671     public String JavaDoc getInfo() {
672
673         return (info);
674
675     }
676
677
678     /**
679      * Return the minimum number of processors to start at initialization.
680      */

681     public int getMinProcessors() {
682
683         return (minProcessors);
684
685     }
686
687
688     /**
689      * Set the minimum number of processors to start at initialization.
690      *
691      * @param minProcessors The new minimum processors
692      */

693     public void setMinProcessors(int minProcessors) {
694
695         this.minProcessors = minProcessors;
696
697     }
698
699
700     /**
701      * Return the maximum number of processors allowed, or <0 for unlimited.
702      */

703     public int getMaxProcessors() {
704
705         return (maxProcessors);
706
707     }
708
709
710     /**
711      * Set the maximum number of processors allowed, or <0 for unlimited.
712      *
713      * @param maxProcessors The new maximum processors
714      */

715     public void setMaxProcessors(int maxProcessors) {
716
717         this.maxProcessors = maxProcessors;
718
719     }
720
721
722     /**
723      * Return the maximum number of spare processors allowed.
724      */

725     public int getMaxSpareProcessors() {
726
727         return (maxSpareProcessors);
728
729     }
730
731
732     /**
733      * Set the maximum number of spare processors allowed.
734      *
735      * @param maxSpareProcessors The new maximum of spare processors
736      */

737     public void setMaxSpareProcessors(int maxSpareProcessors) {
738
739         this.maxSpareProcessors = maxSpareProcessors;
740
741     }
742
743
744     /**
745      * Return the port number on which we listen for requests.
746      */

747     public int getPort() {
748
749         return (this.port);
750
751     }
752
753
754     /**
755      * Set the port number on which we listen for requests.
756      *
757      * @param port The new port number
758      */

759     public void setPort(int port) {
760
761         this.port = port;
762
763     }
764
765
766     /**
767      * Return the class name of the Coyote protocol handler in use.
768      */

769     public String JavaDoc getProtocolHandlerClassName() {
770
771         return (this.protocolHandlerClassName);
772
773     }
774
775
776     /**
777      * Set the class name of the Coyote protocol handler which will be used
778      * by the connector.
779      *
780      * @param protocolHandlerClassName The new class name
781      */

782     public void setProtocolHandlerClassName(String JavaDoc protocolHandlerClassName) {
783
784         this.protocolHandlerClassName = protocolHandlerClassName;
785
786     }
787
788
789     /**
790      * Return the proxy server name for this Connector.
791      */

792     public String JavaDoc getProxyName() {
793
794         return (this.proxyName);
795
796     }
797
798
799     /**
800      * Set the proxy server name for this Connector.
801      *
802      * @param proxyName The new proxy server name
803      */

804     public void setProxyName(String JavaDoc proxyName) {
805
806         if(! "".equals(proxyName) ) {
807             this.proxyName = proxyName;
808         } else {
809             this.proxyName = null;
810         }
811
812     }
813
814
815     /**
816      * Return the proxy server port for this Connector.
817      */

818     public int getProxyPort() {
819
820         return (this.proxyPort);
821
822     }
823
824
825     /**
826      * Set the proxy server port for this Connector.
827      *
828      * @param proxyPort The new proxy server port
829      */

830     public void setProxyPort(int proxyPort) {
831
832         this.proxyPort = proxyPort;
833
834     }
835
836
837     /**
838      * Return the port number to which a request should be redirected if
839      * it comes in on a non-SSL port and is subject to a security constraint
840      * with a transport guarantee that requires SSL.
841      */

842     public int getRedirectPort() {
843
844         return (this.redirectPort);
845
846     }
847
848
849     /**
850      * Set the redirect port number.
851      *
852      * @param redirectPort The redirect port number (non-SSL to SSL)
853      */

854     public void setRedirectPort(int redirectPort) {
855
856         this.redirectPort = redirectPort;
857
858     }
859
860     /**
861      * Return the flag that specifies upload time-out behavior.
862      */

863     public boolean getDisableUploadTimeout() {
864         return disableUploadTimeout;
865     }
866
867     /**
868      * Set the flag to specify upload time-out behavior.
869      *
870      * @param isDisabled If <code>true</code>, then the <code>timeout</code>
871      * parameter is ignored. If <code>false</code>, then the
872      * <code>timeout</code> parameter is used to control uploads.
873      */

874     public void setDisableUploadTimeout( boolean isDisabled ) {
875         disableUploadTimeout = isDisabled;
876     }
877
878     /**
879      * Return the maximum number of Keep-Alive requests to honor per connection.
880      */

881     public int getMaxKeepAliveRequests() {
882         return maxKeepAliveRequests;
883     }
884
885     /**
886      * Set the maximum number of Keep-Alive requests to honor per connection.
887      */

888     public void setMaxKeepAliveRequests(int mkar) {
889         maxKeepAliveRequests = mkar;
890     }
891
892     /**
893      * Return the scheme that will be assigned to requests received
894      * through this connector. Default value is "http".
895      */

896     public String JavaDoc getScheme() {
897
898         return (this.scheme);
899
900     }
901
902
903     /**
904      * Set the scheme that will be assigned to requests received through
905      * this connector.
906      *
907      * @param scheme The new scheme
908      */

909     public void setScheme(String JavaDoc scheme) {
910
911         this.scheme = scheme;
912
913     }
914
915
916     /**
917      * Return the secure connection flag that will be assigned to requests
918      * received through this connector. Default value is "false".
919      */

920     public boolean getSecure() {
921
922         return (this.secure);
923
924     }
925
926
927     /**
928      * Set the secure connection flag that will be assigned to requests
929      * received through this connector.
930      *
931      * @param secure The new secure connection flag
932      */

933     public void setSecure(boolean secure) {
934
935         this.secure = secure;
936
937     }
938
939     public boolean getTomcatAuthentication() {
940         return tomcatAuthentication;
941     }
942
943     public void setTomcatAuthentication(boolean tomcatAuthentication) {
944         this.tomcatAuthentication = tomcatAuthentication;
945     }
946
947     /**
948      * Return the TCP no delay flag value.
949      */

950     public boolean getTcpNoDelay() {
951
952         return (this.tcpNoDelay);
953
954     }
955
956
957     /**
958      * Set the TCP no delay flag which will be set on the socket after
959      * accepting a connection.
960      *
961      * @param tcpNoDelay The new TCP no delay flag
962      */

963     public void setTcpNoDelay(boolean tcpNoDelay) {
964
965         this.tcpNoDelay = tcpNoDelay;
966
967     }
968
969
970      /**
971       * Return the character encoding to be used for the URI.
972       */

973      public String JavaDoc getURIEncoding() {
974
975          return (this.URIEncoding);
976
977      }
978
979
980      /**
981       * Set the URI encoding to be used for the URI.
982       *
983       * @param URIEncoding The new URI character encoding.
984       */

985      public void setURIEncoding(String JavaDoc URIEncoding) {
986
987          this.URIEncoding = URIEncoding;
988
989      }
990
991
992      /**
993       * Return the true if the entity body encoding should be used for the URI.
994       */

995      public boolean getUseBodyEncodingForURI() {
996
997          return (this.useBodyEncodingForURI);
998
999      }
1000
1001
1002     /**
1003      * Set if the entity body encoding should be used for the URI.
1004      *
1005      * @param useBodyEncodingForURI The new value for the flag.
1006      */

1007     public void setUseBodyEncodingForURI(boolean useBodyEncodingForURI) {
1008
1009         this.useBodyEncodingForURI = useBodyEncodingForURI;
1010
1011     }
1012
1013
1014    /**
1015     * Return the value of the Uri validation flag.
1016     */

1017    public boolean getUseURIValidationHack() {
1018
1019        return (this.useURIValidationHack);
1020
1021    }
1022
1023
1024    /**
1025     * Set the value of the Uri validation flag.
1026     *
1027     * @param useURIValidationHack The new flag value
1028     */

1029    public void setUseURIValidationHack(boolean useURIValidationHack) {
1030
1031        this.useURIValidationHack = useURIValidationHack;
1032
1033    }
1034
1035
1036    // --------------------------------------------------------- Public Methods
1037

1038
1039    /**
1040     * Create (or allocate) and return a Request object suitable for
1041     * specifying the contents of a Request to the responsible Container.
1042     */

1043    public Request createRequest() {
1044
1045        CoyoteRequest request = new CoyoteRequest();
1046        request.setConnector(this);
1047        return (request);
1048
1049    }
1050
1051
1052    /**
1053     * Create (or allocate) and return a Response object suitable for
1054     * receiving the contents of a Response from the responsible Container.
1055     */

1056    public Response createResponse() {
1057
1058        CoyoteResponse response = new CoyoteResponse();
1059        response.setConnector(this);
1060        return (response);
1061
1062    }
1063
1064
1065    // -------------------------------------------------------- Private Methods
1066

1067
1068    /**
1069     * Log a message on the Logger associated with our Container (if any).
1070     *
1071     * @param message Message to be logged
1072     */

1073    private void log(String JavaDoc message) {
1074
1075        Logger logger = container.getLogger();
1076        String JavaDoc localName = "CoyoteConnector";
1077        if (logger != null)
1078            logger.log(localName + " " + message);
1079        else
1080            System.out.println(localName + " " + message);
1081
1082    }
1083
1084
1085    /**
1086     * Log a message on the Logger associated with our Container (if any).
1087     *
1088     * @param message Message to be logged
1089     * @param throwable Associated exception
1090     */

1091    private void log(String JavaDoc message, Throwable JavaDoc throwable) {
1092
1093        Logger logger = container.getLogger();
1094        String JavaDoc localName = "CoyoteConnector";
1095        if (logger != null)
1096            logger.log(localName + " " + message, throwable);
1097        else {
1098            System.out.println(localName + " " + message);
1099            throwable.printStackTrace(System.out);
1100        }
1101
1102    }
1103
1104
1105    // ------------------------------------------------------ Lifecycle Methods
1106

1107
1108    /**
1109     * Add a lifecycle event listener to this component.
1110     *
1111     * @param listener The listener to add
1112     */

1113    public void addLifecycleListener(LifecycleListener listener) {
1114
1115        lifecycle.addLifecycleListener(listener);
1116
1117    }
1118
1119
1120    /**
1121     * Get the lifecycle listeners associated with this lifecycle. If this
1122     * Lifecycle has no listeners registered, a zero-length array is returned.
1123     */

1124    public LifecycleListener[] findLifecycleListeners() {
1125
1126        return null;//lifecycle.findLifecycleListeners();
1127

1128    }
1129
1130
1131    /**
1132     * Remove a lifecycle event listener from this component.
1133     *
1134     * @param listener The listener to add
1135     */

1136    public void removeLifecycleListener(LifecycleListener listener) {
1137
1138        lifecycle.removeLifecycleListener(listener);
1139
1140    }
1141
1142
1143    /**
1144     * Initialize this connector (create ServerSocket here!)
1145     */

1146    public void initialize()
1147        throws LifecycleException {
1148
1149        if (initialized)
1150            throw new LifecycleException
1151                (sm.getString("coyoteConnector.alreadyInitialized"));
1152
1153        this.initialized = true;
1154
1155        // Initializa adapter
1156
adapter = new CoyoteAdapter(this);
1157
1158        // Instantiate protocol handler
1159
try {
1160            Class JavaDoc clazz = Class.forName(protocolHandlerClassName);
1161            protocolHandler = (ProtocolHandler) clazz.newInstance();
1162        } catch (Exception JavaDoc e) {
1163            e.printStackTrace();
1164            throw new LifecycleException
1165                (sm.getString
1166                 ("coyoteConnector.protocolHandlerInstantiationFailed", e));
1167        }
1168        protocolHandler.setAdapter(adapter);
1169
1170        IntrospectionUtils.setProperty(protocolHandler, "jkHome",
1171                                       System.getProperty("catalina.base"));
1172
1173        // Set attributes
1174
IntrospectionUtils.setProperty(protocolHandler, "port", "" + port);
1175        IntrospectionUtils.setProperty(protocolHandler, "maxThreads",
1176                                       "" + maxProcessors);
1177        IntrospectionUtils.setProperty(protocolHandler, "minSpareThreads",
1178                                       "" + minProcessors);
1179        IntrospectionUtils.setProperty(protocolHandler, "maxSpareThreads",
1180                                       "" + maxSpareProcessors);
1181        IntrospectionUtils.setProperty(protocolHandler, "backlog",
1182                                       "" + acceptCount);
1183        IntrospectionUtils.setProperty(protocolHandler, "tcpNoDelay",
1184                                       "" + tcpNoDelay);
1185        IntrospectionUtils.setProperty(protocolHandler, "soLinger",
1186                                       "" + connectionLinger);
1187        IntrospectionUtils.setProperty(protocolHandler, "soTimeout",
1188                                       "" + connectionTimeout);
1189        IntrospectionUtils.setProperty(protocolHandler, "timeout",
1190                                       "" + connectionUploadTimeout);
1191        IntrospectionUtils.setProperty(protocolHandler, "serverSoTimeout",
1192                                       "" + serverSocketTimeout);
1193        IntrospectionUtils.setProperty(protocolHandler, "disableUploadTimeout",
1194                                       "" + disableUploadTimeout);
1195        IntrospectionUtils.setProperty(protocolHandler, "maxKeepAliveRequests",
1196                                       "" + maxKeepAliveRequests);
1197        IntrospectionUtils.setProperty(protocolHandler, "tomcatAuthentication",
1198                                       "" + tomcatAuthentication);
1199        IntrospectionUtils.setProperty(protocolHandler, "compression",
1200                                       compression);
1201        if (address != null) {
1202            IntrospectionUtils.setProperty(protocolHandler, "address",
1203                                           address);
1204        }
1205
1206        // Configure secure socket factory
1207
if (factory instanceof CoyoteServerSocketFactory) {
1208            IntrospectionUtils.setProperty(protocolHandler, "secure",
1209                                           "" + true);
1210            CoyoteServerSocketFactory ssf =
1211                (CoyoteServerSocketFactory) factory;
1212            IntrospectionUtils.setProperty(protocolHandler, "algorithm",
1213                                           ssf.getAlgorithm());
1214        IntrospectionUtils.setProperty(protocolHandler, "clientauth",
1215                                           ssf.getClientAuth());
1216            IntrospectionUtils.setProperty(protocolHandler, "keystore",
1217                                           ssf.getKeystoreFile());
1218            IntrospectionUtils.setProperty(protocolHandler, "randomfile",
1219                                           ssf.getRandomFile());
1220            IntrospectionUtils.setProperty(protocolHandler, "rootfile",
1221                                           ssf.getRootFile());
1222
1223            IntrospectionUtils.setProperty(protocolHandler, "keypass",
1224                                           ssf.getKeystorePass());
1225            IntrospectionUtils.setProperty(protocolHandler, "keytype",
1226                                           ssf.getKeystoreType());
1227            IntrospectionUtils.setProperty(protocolHandler, "protocol",
1228                                           ssf.getProtocol());
1229            IntrospectionUtils.setProperty(protocolHandler,
1230                                           "sSLImplementation",
1231                                           ssf.getSSLImplementation());
1232        } else {
1233            IntrospectionUtils.setProperty(protocolHandler, "secure",
1234                                           "" + false);
1235        }
1236
1237        try {
1238            protocolHandler.init();
1239        } catch (Exception JavaDoc e) {
1240            throw new LifecycleException
1241                (sm.getString
1242                 ("coyoteConnector.protocolHandlerInitializationFailed", e));
1243        }
1244    }
1245
1246
1247    /**
1248     * Begin processing requests via this Connector.
1249     *
1250     * @exception LifecycleException if a fatal startup error occurs
1251     */

1252    public void start() throws LifecycleException {
1253
1254        // Validate and update our current state
1255
if (started)
1256            throw new LifecycleException
1257                (sm.getString("coyoteConnector.alreadyStarted"));
1258        lifecycle.fireLifecycleEvent(START_EVENT, null);
1259        started = true;
1260
1261        // We can't register earlier - the JMX registration of this happens
1262
// in Server.start callback
1263
if( this.oname != null ) {
1264            // We are registred - register the adapter as well.
1265
try {
1266                Registry.getRegistry().registerComponent(protocolHandler,
1267                        this.domain +
1268                        ":type=protocolHandler,className=" + protocolHandlerClassName, null);
1269            } catch( Exception JavaDoc ex ) {
1270                ex.printStackTrace();
1271            }
1272        } else {
1273            log( "Coyote can't register jmx for protocol");
1274        }
1275
1276        try {
1277            protocolHandler.start();
1278        } catch (Exception JavaDoc e) {
1279            throw new LifecycleException
1280                (sm.getString
1281                 ("coyoteConnector.protocolHandlerStartFailed", e));
1282        }
1283
1284    }
1285
1286
1287    /**
1288     * Terminate processing requests via this Connector.
1289     *
1290     * @exception LifecycleException if a fatal shutdown error occurs
1291     */

1292    public void stop() throws LifecycleException {
1293
1294        // Validate and update our current state
1295
if (!started)
1296            throw new LifecycleException
1297                (sm.getString("coyoteConnector.notStarted"));
1298        lifecycle.fireLifecycleEvent(STOP_EVENT, null);
1299        started = false;
1300
1301        try {
1302            protocolHandler.destroy();
1303        } catch (Exception JavaDoc e) {
1304            throw new LifecycleException
1305                (sm.getString
1306                 ("coyoteConnector.protocolHandlerDestroyFailed", e));
1307        }
1308
1309    }
1310
1311    protected String JavaDoc domain;
1312    protected ObjectName JavaDoc oname;
1313    protected MBeanServer JavaDoc mserver;
1314
1315    public ObjectName JavaDoc getObjectName() {
1316        return oname;
1317    }
1318
1319    public String JavaDoc getDomain() {
1320        return domain;
1321    }
1322
1323    public ObjectName JavaDoc preRegister(MBeanServer JavaDoc server,
1324                                  ObjectName JavaDoc name) throws Exception JavaDoc {
1325        oname=name;
1326        mserver=server;
1327        domain=name.getDomain();
1328        return name;
1329    }
1330
1331    public void postRegister(Boolean JavaDoc registrationDone) {
1332    }
1333
1334    public void preDeregister() throws Exception JavaDoc {
1335    }
1336
1337    public void postDeregister() {
1338    }
1339
1340}
1341
Popular Tags