KickJava   Java API By Example, From Geeks To Geeks.

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


1
2
3 /*
4  * The contents of this file are subject to the terms
5  * of the Common Development and Distribution License
6  * (the "License"). You may not use this file except
7  * in compliance with the License.
8  *
9  * You can obtain a copy of the license at
10  * glassfish/bootstrap/legal/CDDLv1.0.txt or
11  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
12  * See the License for the specific language governing
13  * permissions and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL
16  * HEADER in each file and include the License file at
17  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
18  * add the following below this CDDL HEADER, with the
19  * fields enclosed by brackets "[]" replaced with your
20  * own identifying information: Portions Copyright [yyyy]
21  * [name of copyright owner]
22  *
23  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24  *
25  * Portions Copyright Apache Software Foundation.
26  */

27
28
29 package org.apache.coyote.tomcat5;
30
31 import java.lang.reflect.Constructor JavaDoc;
32 import java.net.URLEncoder JavaDoc;
33 import java.lang.reflect.Method JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.StringTokenizer JavaDoc;
36 import java.util.Vector JavaDoc;
37 import java.util.HashMap JavaDoc;
38 import java.util.Iterator JavaDoc;
39
40 // START OF SJSAS 8.1 PE 6191830
41
import java.security.cert.X509Certificate JavaDoc;
42 // END OF SJSAS 8.1 PE 6191830
43
import javax.management.ObjectName JavaDoc;
44 import javax.management.MBeanServer JavaDoc;
45 import javax.management.MBeanRegistration JavaDoc;
46 import javax.management.MalformedObjectNameException JavaDoc;
47
48 import javax.servlet.http.HttpServletRequest JavaDoc;
49
50 import com.sun.org.apache.commons.modeler.Registry;
51 import com.sun.org.apache.commons.logging.Log;
52 import com.sun.org.apache.commons.logging.LogFactory;
53
54 import org.apache.tomcat.util.IntrospectionUtils;
55 import org.apache.tomcat.util.http.mapper.Mapper;
56
57 import org.apache.coyote.Adapter;
58 import org.apache.coyote.ProtocolHandler;
59
60 import org.apache.catalina.Connector;
61 import org.apache.catalina.Container;
62 import org.apache.catalina.Lifecycle;
63 import org.apache.catalina.LifecycleException;
64 import org.apache.catalina.LifecycleListener;
65 import org.apache.catalina.Logger;
66 import org.apache.catalina.Request;
67 import org.apache.catalina.Response;
68 import org.apache.catalina.Service;
69 import org.apache.catalina.Engine;
70 // START OF SJSAS 8.1 PE 6191830
71
import org.apache.catalina.Globals;
72 // END OF SJSAS 8.1 PE 6191830
73
import org.apache.catalina.core.ContainerBase;
74 import org.apache.catalina.core.StandardEngine;
75 import org.apache.catalina.net.DefaultServerSocketFactory;
76 import org.apache.catalina.net.ServerSocketFactory;
77 import org.apache.catalina.util.LifecycleSupport;
78 import org.apache.catalina.util.StringManager;
79 // START S1AS 6188932
80
import com.sun.appserv.ProxyHandler;
81 // END S1AS 6188932
82

83 /**
84  * Implementation of a Coyote connector for Tomcat 5.x.
85  *
86  * @author Craig R. McClanahan
87  * @author Remy Maucherat
88  * @version $Revision: 1.10 $ $Date: 2006/03/12 01:27:09 $
89  */

90
91
92 public class CoyoteConnector
93     implements Connector, Lifecycle, MBeanRegistration JavaDoc
94 {
95     private static Log log = LogFactory.getLog(CoyoteConnector.class);
96
97     // ---------------------------------------------- Adapter Configuration --//
98

99     // START SJSAS 6363251
100
/**
101      * Coyote Adapter class name.
102      * Defaults to the CoyoteAdapter.
103      */

104     private String JavaDoc defaultClassName =
105         "org.apache.coyote.tomcat5.CoyoteAdapter";
106     // END SJSAS 6363251
107

108     
109     // ----------------------------------------------------- Instance Variables
110

111     /**
112      * Holder for our configured properties.
113      */

114     private HashMap JavaDoc properties = new HashMap JavaDoc();
115
116     /**
117      * The <code>Service</code> we are associated with (if any).
118      */

119     private Service service = null;
120
121
122     /**
123      * The accept count for this Connector.
124      */

125     private int acceptCount = 10;
126
127
128     /**
129      * The IP address on which to bind, if any. If <code>null</code>, all
130      * addresses on the server will be bound.
131      */

132     private String JavaDoc address = null;
133                                                                            
134
135     /**
136      * Do we allow TRACE ?
137      */

138     private boolean allowTrace = true;
139
140
141     /**
142      * The input buffer size we should create on input streams.
143      */

144     private int bufferSize = 4096;
145
146
147     /**
148      * The Container used for processing requests received by this Connector.
149      */

150     protected Container container = null;
151
152
153     /**
154      * Compression value.
155      */

156     private String JavaDoc compression = "off";
157
158
159     /**
160      * The debugging detail level for this component.
161      */

162     private int debug = 0;
163
164
165     /**
166      * The "enable DNS lookups" flag for this Connector.
167      */

168     private boolean enableLookups = false;
169
170
171     /**
172      * The server socket factory for this component.
173      */

174     private ServerSocketFactory factory = null;
175
176     /**
177      * Maximum size of a HTTP header. 4KB is the default.
178      */

179     private int maxHttpHeaderSize = 4 * 1024;
180
181     /*
182      * Is generation of X-Powered-By response header enabled/disabled?
183      */

184     private boolean xpoweredBy;
185
186
187     /**
188      * Descriptive information about this Connector implementation.
189      */

190     private static final String JavaDoc info =
191         "org.apache.coyote.tomcat5.CoyoteConnector/2.0";
192
193
194     /**
195      * The lifecycle event support for this component.
196      */

197     protected LifecycleSupport lifecycle = new LifecycleSupport(this);
198
199
200     /**
201      * The minimum number of processors to start at initialization time.
202      */

203     protected int minProcessors = 5;
204
205
206     /**
207      * The maximum number of processors allowed, or <0 for unlimited.
208      */

209     private int maxProcessors = 20;
210
211
212     /**
213      * Linger value on the incoming connection.
214      * Note : a value inferior to 0 means no linger.
215      */

216     private int connectionLinger = Constants.DEFAULT_CONNECTION_LINGER;
217
218
219     /**
220      * Timeout value on the incoming connection.
221      * Note : a value of 0 means no timeout.
222      */

223     private int connectionTimeout = Constants.DEFAULT_CONNECTION_TIMEOUT;
224
225
226     /**
227      * Timeout value on the incoming connection during request processing.
228      * Note : a value of 0 means no timeout.
229      */

230     private int connectionUploadTimeout =
231         Constants.DEFAULT_CONNECTION_UPLOAD_TIMEOUT;
232
233
234     /**
235      * Timeout value on the server socket.
236      * Note : a value of 0 means no timeout.
237      */

238     private int serverSocketTimeout = Constants.DEFAULT_SERVER_SOCKET_TIMEOUT;
239
240
241     /**
242      * The port number on which we listen for requests.
243      */

244     private int port = 8080;
245
246
247     /**
248      * The server name to which we should pretend requests to this Connector
249      * were directed. This is useful when operating Tomcat behind a proxy
250      * server, so that redirects get constructed accurately. If not specified,
251      * the server name included in the <code>Host</code> header is used.
252      */

253     private String JavaDoc proxyName = null;
254
255
256     /**
257      * The server port to which we should pretent requests to this Connector
258      * were directed. This is useful when operating Tomcat behind a proxy
259      * server, so that redirects get constructed accurately. If not specified,
260      * the port number specified by the <code>port</code> property is used.
261      */

262     private int proxyPort = 0;
263
264
265     /**
266      * The redirect port for non-SSL to SSL redirects.
267      */

268     private int redirectPort = 443;
269
270
271     // BEGIN S1AS 5000999
272
/**
273      * The default host.
274      */

275     private String JavaDoc defaultHost;
276     // END S1AS 5000999
277

278
279     /**
280      * The request scheme that will be set on all requests received
281      * through this connector.
282      */

283     private String JavaDoc scheme = "http";
284
285
286     /**
287      * The secure connection flag that will be set on all requests received
288      * through this connector.
289      */

290     private boolean secure = false;
291
292     /** For jk, do tomcat authentication if true, trust server if false
293      */

294     private boolean tomcatAuthentication = true;
295
296     /**
297      * The string manager for this package.
298      */

299     private StringManager sm =
300         StringManager.getManager(Constants.Package);
301
302
303     /**
304      * Flag to disable setting a seperate time-out for uploads.
305      * If <code>true</code>, then the <code>timeout</code> parameter is
306      * ignored. If <code>false</code>, then the <code>timeout</code>
307      * parameter is used to control uploads.
308      */

309     private boolean disableUploadTimeout = false;
310
311     /**
312      * Maximum number of Keep-Alive requests to honor per connection.
313      */

314     private int maxKeepAliveRequests = 100;
315
316
317     /**
318      * Maximum size of a POST which will be automatically parsed by the
319      * container. 2MB by default.
320      */

321     private int maxPostSize = 2 * 1024 * 1024;
322
323
324     /**
325      * Has this component been initialized yet?
326      */

327     private boolean initialized = false;
328
329
330     /**
331      * Has this component been started yet?
332      */

333     private boolean started = false;
334
335
336     /**
337      * The shutdown signal to our background thread
338      */

339     private boolean stopped = false;
340
341
342     /**
343      * The background thread.
344      */

345     private Thread JavaDoc thread = null;
346
347
348     /**
349      * Use TCP no delay ?
350      */

351     private boolean tcpNoDelay = true;
352
353
354     /**
355      * Coyote Protocol handler class name.
356      * Defaults to the Coyote HTTP/1.1 protocolHandler.
357      */

358     private String JavaDoc protocolHandlerClassName =
359         "org.apache.coyote.http11.Http11Protocol";
360
361     /**
362      * Coyote protocol handler.
363      */

364     private ProtocolHandler protocolHandler = null;
365
366
367     /**
368      * Coyote adapter.
369      */

370     private Adapter adapter = null;
371
372
373      /**
374       * Mapper.
375       */

376      private Mapper mapper = new Mapper();
377
378
379     /**
380      * Mapper listener.
381      */

382     private MapperListener mapperListener = new MapperListener(mapper);
383
384
385     /**
386      * URI encoding.
387      */

388     private String JavaDoc URIEncoding = null;
389
390
391     // START SJSAS 6331392
392
private boolean isEnabled = true;
393     // END SJSAS 6331392
394

395
396     // START S1AS 6188932
397
/**
398      * Flag indicating whether this connector is receiving its requests from
399      * a trusted intermediate server
400      */

401     protected boolean authPassthroughEnabled = false;
402
403     protected ProxyHandler proxyHandler = null;
404     // END S1AS 6188932
405

406     // ------------------------------------------------------------- Properties
407

408     /**
409      * Return a configured property.
410      */

411     public Object JavaDoc getProperty(String JavaDoc name) {
412         return properties.get(name);
413     }
414
415     /**
416      * Set a configured property.
417      */

418     public void setProperty(String JavaDoc name, Object JavaDoc value) {
419         properties.put(name, value);
420     }
421
422     /**
423      * remove a configured property.
424      */

425     public void removeProperty(String JavaDoc name) {
426         properties.remove(name);
427     }
428
429     /**
430      * Return the <code>Service</code> with which we are associated (if any).
431      */

432     public Service getService() {
433
434         return (this.service);
435
436     }
437
438
439     /**
440      * Set the <code>Service</code> with which we are associated (if any).
441      *
442      * @param service The service that owns this Engine
443      */

444     public void setService(Service service) {
445
446         this.service = service;
447         setProperty("service", service);
448
449     }
450
451
452     /**
453      * Get the value of compression.
454      */

455     public String JavaDoc getCompression() {
456
457         return (compression);
458
459     }
460
461
462     /**
463      * Set the value of compression.
464      *
465      * @param compression The new compression value, which can be "on", "off"
466      * or "force"
467      */

468     public void setCompression(String JavaDoc compression) {
469
470         this.compression = compression;
471         setProperty("compression", compression);
472
473     }
474
475
476     /**
477      * Return the connection linger for this Connector.
478      */

479     public int getConnectionLinger() {
480
481         return (connectionLinger);
482
483     }
484
485
486     /**
487      * Set the connection linger for this Connector.
488      *
489      * @param count The new connection linge
490      */

491     public void setConnectionLinger(int connectionLinger) {
492
493         this.connectionLinger = connectionLinger;
494         setProperty("soLinger", String.valueOf(connectionLinger));
495
496     }
497
498
499     /**
500      * Return the connection timeout for this Connector.
501      */

502     public int getConnectionTimeout() {
503
504         return (connectionTimeout);
505
506     }
507
508
509     /**
510      * Set the connection timeout for this Connector.
511      *
512      * @param count The new connection timeout
513      */

514     public void setConnectionTimeout(int connectionTimeout) {
515
516         this.connectionTimeout = connectionTimeout;
517         setProperty("soTimeout", String.valueOf(connectionTimeout));
518
519     }
520
521
522     /**
523      * Return the connection upload timeout for this Connector.
524      */

525     public int getConnectionUploadTimeout() {
526
527         return (connectionUploadTimeout);
528
529     }
530
531
532     /**
533      * Set the connection upload timeout for this Connector.
534      *
535      * @param connectionUploadTimeout The new connection upload timeout
536      */

537     public void setConnectionUploadTimeout(int connectionUploadTimeout) {
538
539         this.connectionUploadTimeout = connectionUploadTimeout;
540         setProperty("timeout", String.valueOf(connectionUploadTimeout));
541
542     }
543
544
545     /**
546      * Return the server socket timeout for this Connector.
547      */

548     public int getServerSocketTimeout() {
549
550         return (serverSocketTimeout);
551
552     }
553
554
555     /**
556      * Set the server socket timeout for this Connector.
557      *
558      * @param connectionUploadTimeout The new server socket timeout
559      */

560     public void setServerSocketTimeout(int serverSocketTimeout) {
561
562         this.serverSocketTimeout = serverSocketTimeout;
563         setProperty("serverSoTimeout", String.valueOf(serverSocketTimeout));
564
565     }
566
567
568     /**
569      * Return the accept count for this Connector.
570      */

571     public int getAcceptCount() {
572
573         return (acceptCount);
574
575     }
576
577
578     /**
579      * Set the accept count for this Connector.
580      *
581      * @param count The new accept count
582      */

583     public void setAcceptCount(int count) {
584
585         this.acceptCount = count;
586         setProperty("backlog", String.valueOf(count));
587
588     }
589
590
591     /**
592      * Return the bind IP address for this Connector.
593      */

594     public String JavaDoc getAddress() {
595
596         return (this.address);
597
598     }
599
600
601     /**
602      * Set the bind IP address for this Connector.
603      *
604      * @param address The bind IP address
605      */

606     public void setAddress(String JavaDoc address) {
607
608         this.address = address;
609         setProperty("address", address);
610
611     }
612
613                                                                            
614                                                                            
615     /**
616      * True if the TRACE method is allowed. Default value is "false".
617      */

618     public boolean getAllowTrace() {
619                                                                            
620         return (this.allowTrace);
621                                                                            
622     }
623                                                                            
624                                                                            
625     /**
626      * Set the allowTrace flag, to disable or enable the TRACE HTTP method. *
627      * @param allowTrace The new allowTrace flag
628      */

629     public void setAllowTrace(boolean allowTrace) {
630                                                                            
631         this.allowTrace = allowTrace;
632         setProperty("allowTrace", String.valueOf(allowTrace));
633                                                                            
634     }
635
636
637     /**
638      * Is this connector available for processing requests?
639      */

640     public boolean isAvailable() {
641
642         return (started);
643
644     }
645
646
647     /**
648      * Return the input buffer size for this Connector.
649      */

650     public int getBufferSize() {
651
652         return (this.bufferSize);
653
654     }
655
656
657     /**
658      * Set the input buffer size for this Connector.
659      *
660      * @param bufferSize The new input buffer size.
661      */

662     public void setBufferSize(int bufferSize) {
663
664         this.bufferSize = bufferSize;
665         setProperty("bufferSize", String.valueOf(bufferSize));
666
667     }
668
669
670     /**
671      * Return the Container used for processing requests received by this
672      * Connector.
673      */

674     public Container getContainer() {
675         if( container==null ) {
676             // Lazy - maybe it was added later
677
findContainer();
678         }
679         return (container);
680
681     }
682
683
684     /**
685      * Set the Container used for processing requests received by this
686      * Connector.
687      *
688      * @param container The new Container to use
689      */

690     public void setContainer(Container container) {
691
692         this.container = container;
693
694     }
695
696
697     /**
698      * Return the debugging detail level for this component.
699      */

700     public int getDebug() {
701
702         return (debug);
703
704     }
705
706
707     /**
708      * Set the debugging detail level for this component.
709      *
710      * @param debug The new debugging detail level
711      */

712     public void setDebug(int debug) {
713
714         this.debug = debug;
715
716     }
717
718
719     /**
720      * Return the "enable DNS lookups" flag.
721      */

722     public boolean getEnableLookups() {
723
724         return (this.enableLookups);
725
726     }
727
728
729     /**
730      * Set the "enable DNS lookups" flag.
731      *
732      * @param enableLookups The new "enable DNS lookups" flag value
733      */

734     public void setEnableLookups(boolean enableLookups) {
735
736         this.enableLookups = enableLookups;
737         setProperty("enableLookups", String.valueOf(enableLookups));
738
739     }
740
741
742     /**
743      * Return the server socket factory used by this Container.
744      */

745     public ServerSocketFactory getFactory() {
746
747         return (this.factory);
748
749     }
750
751
752     /**
753      * Set the server socket factory used by this Container.
754      *
755      * @param factory The new server socket factory
756      */

757     public void setFactory(ServerSocketFactory factory) {
758
759         this.factory = factory;
760
761     }
762
763
764     /**
765      * Return descriptive information about this Connector implementation.
766      */

767     public String JavaDoc getInfo() {
768
769         return (info);
770
771     }
772
773
774      /**
775       * Return the mapper.
776       */

777      public Mapper getMapper() {
778
779          return (mapper);
780
781      }
782
783
784     /**
785      * Return the minimum number of processors to start at initialization.
786      */

787     public int getMinProcessors() {
788
789         return (minProcessors);
790
791     }
792
793
794     /**
795      * Set the minimum number of processors to start at initialization.
796      *
797      * @param minProcessors The new minimum processors
798      */

799     public void setMinProcessors(int minProcessors) {
800
801         this.minProcessors = minProcessors;
802         setProperty("minThreads", String.valueOf(minProcessors));
803
804     }
805
806
807     /**
808      * Return the maximum number of processors allowed, or <0 for unlimited.
809      */

810     public int getMaxProcessors() {
811
812         return (maxProcessors);
813
814     }
815
816
817     /**
818      * Set the maximum number of processors allowed, or <0 for unlimited.
819      *
820      * @param maxProcessors The new maximum processors
821      */

822     public void setMaxProcessors(int maxProcessors) {
823
824         this.maxProcessors = maxProcessors;
825         setProperty("maxThreads", String.valueOf(maxProcessors));
826
827     }
828
829
830     /**
831      * Return the maximum size of a POST which will be automatically
832      * parsed by the container.
833      */

834     public int getMaxPostSize() {
835
836         return (maxPostSize);
837
838     }
839
840
841     /**
842      * Set the maximum size of a POST which will be automatically
843      * parsed by the container.
844      *
845      * @param maxPostSize The new maximum size in bytes of a POST which will
846      * be automatically parsed by the container
847      */

848     public void setMaxPostSize(int maxPostSize) {
849
850         this.maxPostSize = maxPostSize;
851         setProperty("maxPostSize", String.valueOf(maxPostSize));
852     }
853
854
855     /**
856      * Return the port number on which we listen for requests.
857      */

858     public int getPort() {
859
860         return (this.port);
861
862     }
863
864
865     /**
866      * Set the port number on which we listen for requests.
867      *
868      * @param port The new port number
869      */

870     public void setPort(int port) {
871
872         this.port = port;
873         setProperty("port", String.valueOf(port));
874
875     }
876
877
878     /**
879      * Return the Coyote protocol handler in use.
880      */

881     public String JavaDoc getProtocol() {
882
883         if ("org.apache.coyote.http11.Http11Protocol".equals
884             (getProtocolHandlerClassName())) {
885             return "HTTP/1.1";
886         } else if ("org.apache.jk.server.JkCoyoteHandler".equals
887                    (getProtocolHandlerClassName())) {
888             return "AJP/1.3";
889         }
890         return null;
891
892     }
893
894
895     /**
896      * Set the Coyote protocol which will be used by the connector.
897      *
898      * @param protocol The Coyote protocol name
899      */

900     public void setProtocol(String JavaDoc protocol) {
901
902         if (protocol.equals("HTTP/1.1")) {
903             setProtocolHandlerClassName
904                 ("org.apache.coyote.http11.Http11Protocol");
905         } else if (protocol.equals("AJP/1.3")) {
906             setProtocolHandlerClassName
907                 ("org.apache.jk.server.JkCoyoteHandler");
908         } else {
909             setProtocolHandlerClassName(null);
910         }
911
912     }
913
914
915     /**
916      * Return the class name of the Coyote protocol handler in use.
917      */

918     public String JavaDoc getProtocolHandlerClassName() {
919
920         return (this.protocolHandlerClassName);
921
922     }
923
924
925     /**
926      * Set the class name of the Coyote protocol handler which will be used
927      * by the connector.
928      *
929      * @param protocolHandlerClassName The new class name
930      */

931     public void setProtocolHandlerClassName(String JavaDoc protocolHandlerClassName) {
932
933         this.protocolHandlerClassName = protocolHandlerClassName;
934
935     }
936
937
938     /**
939      * Return the protocol handler associated with the connector.
940      */

941     public ProtocolHandler getProtocolHandler() {
942
943         return (this.protocolHandler);
944
945     }
946
947
948     /**
949      * Return the proxy server name for this Connector.
950      */

951     public String JavaDoc getProxyName() {
952
953         return (this.proxyName);
954
955     }
956
957
958     /**
959      * Set the proxy server name for this Connector.
960      *
961      * @param proxyName The new proxy server name
962      */

963     public void setProxyName(String JavaDoc proxyName) {
964
965         if(proxyName != null && proxyName.length() > 0) {
966             this.proxyName = proxyName;
967             setProperty("proxyName", proxyName);
968         } else {
969             this.proxyName = null;
970             removeProperty("proxyName");
971         }
972
973     }
974
975
976     /**
977      * Return the proxy server port for this Connector.
978      */

979     public int getProxyPort() {
980
981         return (this.proxyPort);
982
983     }
984
985
986     /**
987      * Set the proxy server port for this Connector.
988      *
989      * @param proxyPort The new proxy server port
990      */

991     public void setProxyPort(int proxyPort) {
992
993         this.proxyPort = proxyPort;
994         setProperty("proxyPort", String.valueOf(proxyPort));
995
996     }
997
998
999     /**
1000     * Return the port number to which a request should be redirected if
1001     * it comes in on a non-SSL port and is subject to a security constraint
1002     * with a transport guarantee that requires SSL.
1003     */

1004    public int getRedirectPort() {
1005
1006        return (this.redirectPort);
1007
1008    }
1009
1010
1011    /**
1012     * Set the redirect port number.
1013     *
1014     * @param redirectPort The redirect port number (non-SSL to SSL)
1015     */

1016    public void setRedirectPort(int redirectPort) {
1017
1018        this.redirectPort = redirectPort;
1019        setProperty("redirectPort", String.valueOf(redirectPort));
1020
1021    }
1022
1023    /**
1024     * Return the flag that specifies upload time-out behavior.
1025     */

1026    public boolean getDisableUploadTimeout() {
1027        return disableUploadTimeout;
1028    }
1029
1030    /**
1031     * Set the flag to specify upload time-out behavior.
1032     *
1033     * @param isDisabled If <code>true</code>, then the <code>timeout</code>
1034     * parameter is ignored. If <code>false</code>, then the
1035     * <code>timeout</code> parameter is used to control uploads.
1036     */

1037    public void setDisableUploadTimeout( boolean isDisabled ) {
1038        disableUploadTimeout = isDisabled;
1039        setProperty("disableUploadTimeout", String.valueOf(isDisabled));
1040    }
1041
1042    /**
1043      * Return the maximum HTTP header size.
1044      */

1045    public int getMaxHttpHeaderSize() {
1046      return maxHttpHeaderSize;
1047    }
1048  
1049    /**
1050     * Set the maximum HTTP header size.
1051     */

1052    public void setMaxHttpHeaderSize(int size) {
1053        maxHttpHeaderSize = size;
1054        setProperty("maxHttpHeaderSize", String.valueOf(size));
1055    }
1056
1057    /**
1058     * Return the Keep-Alive policy for the connection.
1059     */

1060    public boolean getKeepAlive() {
1061        return ((maxKeepAliveRequests != 0) && (maxKeepAliveRequests != 1));
1062    }
1063
1064    /**
1065     * Set the keep-alive policy for this connection.
1066     */

1067    public void setKeepAlive(boolean keepAlive) {
1068        if (!keepAlive) {
1069            setMaxKeepAliveRequests(1);
1070        }
1071    }
1072
1073    /**
1074     * Return the maximum number of Keep-Alive requests to honor
1075     * per connection.
1076     */

1077    public int getMaxKeepAliveRequests() {
1078        return maxKeepAliveRequests;
1079    }
1080
1081    /**
1082     * Set the maximum number of Keep-Alive requests to honor per connection.
1083     */

1084    public void setMaxKeepAliveRequests(int mkar) {
1085        maxKeepAliveRequests = mkar;
1086        setProperty("maxKeepAliveRequests", String.valueOf(mkar));
1087    }
1088
1089    /**
1090     * Return the scheme that will be assigned to requests received
1091     * through this connector. Default value is "http".
1092     */

1093    public String JavaDoc getScheme() {
1094
1095        return (this.scheme);
1096
1097    }
1098
1099
1100    /**
1101     * Set the scheme that will be assigned to requests received through
1102     * this connector.
1103     *
1104     * @param scheme The new scheme
1105     */

1106    public void setScheme(String JavaDoc scheme) {
1107
1108        this.scheme = scheme;
1109        setProperty("scheme", scheme);
1110
1111    }
1112
1113
1114    /**
1115     * Return the secure connection flag that will be assigned to requests
1116     * received through this connector. Default value is "false".
1117     */

1118    public boolean getSecure() {
1119
1120        return (this.secure);
1121
1122    }
1123
1124
1125    /**
1126     * Set the secure connection flag that will be assigned to requests
1127     * received through this connector.
1128     *
1129     * @param secure The new secure connection flag
1130     */

1131    public void setSecure(boolean secure) {
1132
1133        this.secure = secure;
1134        setProperty("secure", String.valueOf(secure));
1135
1136    }
1137
1138    public boolean getTomcatAuthentication() {
1139        return tomcatAuthentication;
1140    }
1141
1142    public void setTomcatAuthentication(boolean tomcatAuthentication) {
1143        this.tomcatAuthentication = tomcatAuthentication;
1144        setProperty("tomcatAuthentication", String.valueOf(tomcatAuthentication));
1145    }
1146    
1147
1148    /**
1149     * Return the TCP no delay flag value.
1150     */

1151    public boolean getTcpNoDelay() {
1152
1153        return (this.tcpNoDelay);
1154
1155    }
1156
1157
1158    /**
1159     * Set the TCP no delay flag which will be set on the socket after
1160     * accepting a connection.
1161     *
1162     * @param tcpNoDelay The new TCP no delay flag
1163     */

1164    public void setTcpNoDelay(boolean tcpNoDelay) {
1165
1166        this.tcpNoDelay = tcpNoDelay;
1167        setProperty("tcpNoDelay", String.valueOf(tcpNoDelay));
1168
1169    }
1170
1171
1172    /**
1173     * Return the character encoding to be used for the URI.
1174     */

1175    public String JavaDoc getURIEncoding() {
1176
1177        return (this.URIEncoding);
1178
1179    }
1180
1181
1182    /**
1183     * Set the URI encoding to be used for the URI.
1184     *
1185     * @param URIEncoding The new URI character encoding.
1186     */

1187    public void setURIEncoding(String JavaDoc URIEncoding) {
1188
1189        this.URIEncoding = URIEncoding;
1190        setProperty("uRIEncoding", URIEncoding);
1191
1192    }
1193
1194
1195    /**
1196     * Indicates whether the generation of an X-Powered-By response header for
1197     * servlet-generated responses is enabled or disabled for this Connector.
1198     *
1199     * @return true if generation of X-Powered-By response header is enabled,
1200     * false otherwise
1201     */

1202    public boolean isXpoweredBy() {
1203        return xpoweredBy;
1204    }
1205
1206
1207    /**
1208     * Enables or disables the generation of an X-Powered-By header (with value
1209     * Servlet/2.4) for all servlet-generated responses returned by this
1210     * Connector.
1211     *
1212     * @param xpoweredBy true if generation of X-Powered-By response header is
1213     * to be enabled, false otherwise
1214     */

1215    public void setXpoweredBy(boolean xpoweredBy) {
1216        this.xpoweredBy = xpoweredBy;
1217        setProperty("xpoweredBy", String.valueOf(xpoweredBy));
1218    }
1219
1220
1221    // BEGIN S1AS 5000999
1222
/**
1223     * Sets the default host for this Connector.
1224     *
1225     * @param defaultHost The default host for this Connector
1226     */

1227    public void setDefaultHost(String JavaDoc defaultHost) {
1228        this.defaultHost = defaultHost;
1229    }
1230
1231    /**
1232     * Gets the default host of this Connector.
1233     *
1234     * @return The default host of this Connector
1235     */

1236    public String JavaDoc getDefaultHost() {
1237        return this.defaultHost;
1238    }
1239    // END S1AS 5000999
1240

1241
1242    // START S1AS 6188932
1243
/**
1244     * Returns the value of this connector's authPassthroughEnabled flag.
1245     *
1246     * @return true if this connector is receiving its requests from
1247     * a trusted intermediate server, false otherwise
1248     */

1249    public boolean getAuthPassthroughEnabled() {
1250        return this.authPassthroughEnabled;
1251    }
1252
1253    /**
1254     * Sets the value of this connector's authPassthroughEnabled flag.
1255     *
1256     * @param authPassthroughEnabled true if this connector is receiving its
1257     * requests from a trusted intermediate server, false otherwise
1258     */

1259    public void setAuthPassthroughEnabled(boolean authPassthroughEnabled) {
1260        this.authPassthroughEnabled = authPassthroughEnabled;
1261    }
1262
1263    /**
1264     * Gets the ProxyHandler instance associated with this CoyoteConnector.
1265     *
1266     * @return ProxyHandler instance associated with this CoyoteConnector,
1267     * or null
1268     */

1269    public ProxyHandler getProxyHandler() {
1270        return proxyHandler;
1271    }
1272
1273    /**
1274     * Sets the ProxyHandler implementation for this CoyoteConnector to use.
1275     *
1276     * @param proxyHandler ProxyHandler instance to use
1277     */

1278    public void setProxyHandler(ProxyHandler proxyHandler) {
1279        this.proxyHandler = proxyHandler;
1280    }
1281    // END S1AS 6188932
1282

1283
1284    // START SJSAS 6331392
1285
public void setIsEnabled(boolean isEnabled) {
1286        this.isEnabled = isEnabled;
1287    }
1288
1289    public boolean isEnabled() {
1290        return isEnabled;
1291    }
1292    // END SJSAS 6331392
1293

1294
1295    // --------------------------------------------------------- Public Methods
1296

1297
1298    /**
1299     * Create (or allocate) and return a Request object suitable for
1300     * specifying the contents of a Request to the responsible Container.
1301     */

1302    public Request JavaDoc createRequest() {
1303
1304        CoyoteRequest request = new CoyoteRequest();
1305        request.setConnector(this);
1306        return (request);
1307
1308    }
1309
1310
1311    /**
1312     * Create (or allocate) and return a Response object suitable for
1313     * receiving the contents of a Response from the responsible Container.
1314     */

1315    public Response createResponse() {
1316
1317        CoyoteResponse response = new CoyoteResponse();
1318        response.setConnector(this);
1319        return (response);
1320
1321    }
1322
1323
1324    // -------------------------------------------------------- Private Methods
1325

1326
1327    /**
1328     * Log a message on the Logger associated with our Container (if any).
1329     *
1330     * @param message Message to be logged
1331     */

1332    private void log(String JavaDoc message) {
1333
1334        Logger logger = container.getLogger();
1335        String JavaDoc localName = "CoyoteConnector";
1336        if (logger != null)
1337            logger.log(localName + " " + message);
1338        else
1339            System.out.println(localName + " " + message);
1340
1341    }
1342
1343
1344    /**
1345     * Log a message on the Logger associated with our Container (if any).
1346     *
1347     * @param message Message to be logged
1348     * @param throwable Associated exception
1349     */

1350    private void log(String JavaDoc message, Throwable JavaDoc throwable) {
1351
1352        Logger logger = container.getLogger();
1353        String JavaDoc localName = "CoyoteConnector";
1354        if (logger != null)
1355            logger.log(localName + " " + message, throwable);
1356        else {
1357            System.out.println(localName + " " + message);
1358            throwable.printStackTrace(System.out);
1359        }
1360
1361    }
1362
1363
1364    // ------------------------------------------------------ Lifecycle Methods
1365

1366
1367    /**
1368     * Add a lifecycle event listener to this component.
1369     *
1370     * @param listener The listener to add
1371     */

1372    public void addLifecycleListener(LifecycleListener listener) {
1373
1374        lifecycle.addLifecycleListener(listener);
1375
1376    }
1377
1378
1379    /**
1380     * Get the lifecycle listeners associated with this lifecycle. If this
1381     * Lifecycle has no listeners registered, a zero-length array is returned.
1382     */

1383    public LifecycleListener[] findLifecycleListeners() {
1384
1385        return null;//lifecycle.findLifecycleListeners();
1386

1387    }
1388
1389
1390    /**
1391     * Remove a lifecycle event listener from this component.
1392     *
1393     * @param listener The listener to add
1394     */

1395    public void removeLifecycleListener(LifecycleListener listener) {
1396
1397        lifecycle.removeLifecycleListener(listener);
1398
1399    }
1400
1401    /**
1402     * Initialize this connector (create ServerSocket here!)
1403     */

1404    public void initialize()
1405        throws LifecycleException
1406    {
1407        if (initialized) {
1408            log.info(sm.getString("coyoteConnector.alreadyInitialized"));
1409            return;
1410        }
1411
1412        this.initialized = true;
1413
1414        if( oname == null && (container instanceof StandardEngine)) {
1415            try {
1416                // we are loaded directly, via API - and no name was given to us
1417
StandardEngine cb=(StandardEngine)container;
1418                String JavaDoc encodedAddr = null;
1419                if (getAddress() != null) {
1420                    encodedAddr = URLEncoder.encode(getAddress());
1421                }
1422                String JavaDoc addSuffix=(getAddress()==null) ?"": ",address=" + encodedAddr;
1423                oname=new ObjectName JavaDoc(cb.getName() + ":type=Connector,port="+
1424                        getPort() + addSuffix);
1425                Registry.getRegistry().registerComponent(this, oname, null);
1426                controller=oname;
1427            } catch (Exception JavaDoc e) {
1428                log.error( "Error registering connector ", e);
1429            }
1430            log.debug("Creating name for connector " + oname);
1431        }
1432        
1433
1434        //START SJSAS 6363251
1435
// Initializa adapter
1436
//adapter = new CoyoteAdapter(this);
1437
//END SJSAS 6363251
1438
// Instantiate Adapter
1439
//START SJSAS 6363251
1440
if ( adapter == null){
1441            try {
1442                Class JavaDoc clazz = Class.forName(defaultClassName);
1443                Constructor JavaDoc constructor =
1444                        clazz.getConstructor(new Class JavaDoc[]{CoyoteConnector.class});
1445                adapter =
1446                        (Adapter)constructor.newInstance(new Object JavaDoc[]{this});
1447            } catch (Exception JavaDoc e) {
1448                throw new LifecycleException
1449                    (sm.getString
1450                     ("coyoteConnector.apadterClassInstantiationFailed", e));
1451            }
1452        }
1453        //END SJSAS 6363251
1454

1455        // Instantiate protocol handler
1456
if ( protocolHandler == null ) {
1457            try {
1458                Class JavaDoc clazz = Class.forName(protocolHandlerClassName);
1459                protocolHandler = (ProtocolHandler) clazz.newInstance();
1460            } catch (Exception JavaDoc e) {
1461                throw new LifecycleException
1462                    (sm.getString
1463                     ("coyoteConnector.protocolHandlerInstantiationFailed", e));
1464            }
1465        }
1466        protocolHandler.setAdapter(adapter);
1467
1468        IntrospectionUtils.setProperty(protocolHandler, "jkHome",
1469                                       System.getProperty("catalina.base"));
1470
1471        // Configure secure socket factory
1472
// XXX For backwards compatibility only.
1473
if (factory instanceof CoyoteServerSocketFactory) {
1474            IntrospectionUtils.setProperty(protocolHandler, "secure",
1475                                           "" + true);
1476            CoyoteServerSocketFactory ssf =
1477                (CoyoteServerSocketFactory) factory;
1478            IntrospectionUtils.setProperty(protocolHandler, "algorithm",
1479                                           ssf.getAlgorithm());
1480            if (ssf.getClientAuth()) {
1481                IntrospectionUtils.setProperty(protocolHandler, "clientauth",
1482                                               "" + ssf.getClientAuth());
1483            }
1484            IntrospectionUtils.setProperty(protocolHandler, "keystore",
1485                                           ssf.getKeystoreFile());
1486            IntrospectionUtils.setProperty(protocolHandler, "randomfile",
1487                                           ssf.getRandomFile());
1488            IntrospectionUtils.setProperty(protocolHandler, "rootfile",
1489                                           ssf.getRootFile());
1490
1491            IntrospectionUtils.setProperty(protocolHandler, "keypass",
1492                                           ssf.getKeystorePass());
1493            IntrospectionUtils.setProperty(protocolHandler, "keytype",
1494                                           ssf.getKeystoreType());
1495            IntrospectionUtils.setProperty(protocolHandler, "protocol",
1496                                           ssf.getProtocol());
1497            IntrospectionUtils.setProperty(protocolHandler, "protocols",
1498                                           ssf.getProtocols());
1499            IntrospectionUtils.setProperty(protocolHandler,
1500                                           "sSLImplementation",
1501                                           ssf.getSSLImplementation());
1502            IntrospectionUtils.setProperty(protocolHandler, "ciphers",
1503                                           ssf.getCiphers());
1504            IntrospectionUtils.setProperty(protocolHandler, "keyAlias",
1505                                           ssf.getKeyAlias());
1506        } else {
1507            IntrospectionUtils.setProperty(protocolHandler, "secure",
1508                                           "" + secure);
1509        }
1510
1511        /* Set the configured properties. This only sets the ones that were
1512         * explicitly configured. Default values are the responsibility of
1513         * the protocolHandler.
1514         */

1515        Iterator JavaDoc keys = properties.keySet().iterator();
1516        while( keys.hasNext() ) {
1517            String JavaDoc name = (String JavaDoc)keys.next();
1518            String JavaDoc value = properties.get(name).toString();
1519        String JavaDoc trnName = translateAttributeName(name);
1520            IntrospectionUtils.setProperty(protocolHandler, trnName, value);
1521        }
1522        
1523
1524        try {
1525            protocolHandler.init();
1526        } catch (Exception JavaDoc e) {
1527            throw new LifecycleException
1528                (sm.getString
1529                 ("coyoteConnector.protocolHandlerInitializationFailed", e));
1530        }
1531    }
1532
1533    /*
1534     * Translate the attribute name from the legacy Factory names to their
1535     * internal protocol names.
1536     */

1537    private String JavaDoc translateAttributeName(String JavaDoc name) {
1538    if ("clientAuth".equals(name)) {
1539        return "clientauth";
1540    } else if ("keystoreFile".equals(name)) {
1541        return "keystore";
1542    } else if ("randomFile".equals(name)) {
1543        return "randomfile";
1544    } else if ("rootFile".equals(name)) {
1545        return "rootfile";
1546    } else if ("keystorePass".equals(name)) {
1547        return "keypass";
1548    } else if ("keystoreType".equals(name)) {
1549        return "keytype";
1550    } else if ("sslProtocol".equals(name)) {
1551        return "protocol";
1552    } else if ("sslProtocols".equals(name)) {
1553        return "protocols";
1554    }
1555    return name;
1556    }
1557
1558
1559    /**
1560     * Begin processing requests via this Connector.
1561     *
1562     * @exception LifecycleException if a fatal startup error occurs
1563     */

1564    public void start() throws LifecycleException {
1565        if( !initialized )
1566            initialize();
1567
1568        // Validate and update our current state
1569
if (started) {
1570            log.info(sm.getString("coyoteConnector.alreadyStarted"));
1571            return;
1572        }
1573        lifecycle.fireLifecycleEvent(START_EVENT, null);
1574        started = true;
1575
1576        // We can't register earlier - the JMX registration of this happens
1577
// in Server.start callback
1578
if ( this.oname != null ) {
1579            // We are registred - register the adapter as well.
1580
try {
1581                Registry.getRegistry().registerComponent
1582                    (protocolHandler, this.domain, "protocolHandler",
1583                     "type=protocolHandler,className="
1584                     + protocolHandlerClassName);
1585            } catch (Exception JavaDoc ex) {
1586                log.error(sm.getString
1587                          ("coyoteConnector.protocolRegistrationFailed"), ex);
1588            }
1589        } else {
1590            log.info(sm.getString
1591                     ("coyoteConnector.cannotRegisterProtocol"));
1592        }
1593
1594        try {
1595            protocolHandler.start();
1596        } catch (Exception JavaDoc e) {
1597            throw new LifecycleException
1598                (sm.getString
1599                 ("coyoteConnector.protocolHandlerStartFailed", e));
1600        }
1601
1602        if( this.domain != null ) {
1603            mapperListener.setDomain( domain );
1604            // BEGIN S1AS 5000999
1605
mapperListener.setPort(this.getPort());
1606            mapperListener.setDefaultHost(this.defaultHost);
1607            // END S1AS 5000999
1608
//mapperListener.setEngine( service.getContainer().getName() );
1609
mapperListener.init();
1610            try {
1611                Registry.getRegistry().registerComponent
1612                        (mapper, this.domain, "Mapper",
1613                                "type=Mapper");
1614            } catch (Exception JavaDoc ex) {
1615                log.error(sm.getString
1616                        ("coyoteConnector.protocolRegistrationFailed"), ex);
1617            }
1618        }
1619    }
1620
1621
1622    /**
1623     * Terminate processing requests via this Connector.
1624     *
1625     * @exception LifecycleException if a fatal shutdown error occurs
1626     */

1627    public void stop() throws LifecycleException {
1628
1629        // Validate and update our current state
1630
if (!started) {
1631            log.error(sm.getString("coyoteConnector.notStarted"));
1632            return;
1633
1634        }
1635        lifecycle.fireLifecycleEvent(STOP_EVENT, null);
1636        started = false;
1637
1638        // START PWC 6393300
1639
if ( domain != null){
1640            try {
1641                Registry.getRegistry().unregisterComponent(new ObjectName JavaDoc(domain,"type", "Mapper"));
1642                Registry.getRegistry().unregisterComponent(new ObjectName JavaDoc(domain
1643                        + ":type=protocolHandler,className="
1644                        + protocolHandlerClassName));
1645            } catch (MalformedObjectNameException JavaDoc e) {
1646                log.info( "Error unregistering mapper ", e);
1647            }
1648        }
1649        // END PWC 6393300
1650

1651        try {
1652            protocolHandler.destroy();
1653        } catch (Exception JavaDoc e) {
1654            throw new LifecycleException
1655                (sm.getString
1656                 ("coyoteConnector.protocolHandlerDestroyFailed", e));
1657        }
1658
1659    }
1660
1661    // -------------------- Management methods --------------------
1662

1663    public boolean getClientAuth() {
1664        boolean ret = false;
1665
1666        String JavaDoc prop = (String JavaDoc) getProperty("clientauth");
1667        if (prop != null) {
1668            ret = Boolean.valueOf(prop).booleanValue();
1669        } else {
1670            ServerSocketFactory factory = this.getFactory();
1671            if (factory instanceof CoyoteServerSocketFactory) {
1672                ret = ((CoyoteServerSocketFactory)factory).getClientAuth();
1673            }
1674        }
1675
1676        return ret;
1677    }
1678
1679    public void setClientAuth(boolean clientAuth) {
1680        setProperty("clientauth", String.valueOf(clientAuth));
1681        ServerSocketFactory factory = this.getFactory();
1682        if (factory instanceof CoyoteServerSocketFactory) {
1683            ((CoyoteServerSocketFactory)factory).setClientAuth(clientAuth);
1684        }
1685    }
1686
1687
1688    public String JavaDoc getKeystoreFile() {
1689        String JavaDoc ret = (String JavaDoc) getProperty("keystore");
1690        if (ret == null) {
1691            ServerSocketFactory factory = this.getFactory();
1692            if (factory instanceof CoyoteServerSocketFactory) {
1693                ret = ((CoyoteServerSocketFactory)factory).getKeystoreFile();
1694            }
1695        }
1696
1697        return ret;
1698    }
1699
1700    public void setKeystoreFile(String JavaDoc keystoreFile) {
1701        setProperty("keystore", keystoreFile);
1702        ServerSocketFactory factory = this.getFactory();
1703        if (factory instanceof CoyoteServerSocketFactory) {
1704            ((CoyoteServerSocketFactory)factory).setKeystoreFile(keystoreFile);
1705        }
1706    }
1707
1708    /**
1709     * Return keystorePass
1710     */

1711    public String JavaDoc getKeystorePass() {
1712        String JavaDoc ret = (String JavaDoc) getProperty("keypass");
1713        if (ret == null) {
1714            ServerSocketFactory factory = getFactory();
1715            if (factory instanceof CoyoteServerSocketFactory ) {
1716                return ((CoyoteServerSocketFactory)factory).getKeystorePass();
1717            }
1718        }
1719
1720        return ret;
1721    }
1722
1723    /**
1724     * Set keystorePass
1725     */

1726    public void setKeystorePass(String JavaDoc keystorePass) {
1727        setProperty("keypass", keystorePass);
1728        ServerSocketFactory factory = getFactory();
1729        if( factory instanceof CoyoteServerSocketFactory ) {
1730            ((CoyoteServerSocketFactory)factory).setKeystorePass(keystorePass);
1731        }
1732    }
1733
1734    /**
1735     * Gets the list of SSL cipher suites that are to be enabled
1736     *
1737     * @return Comma-separated list of SSL cipher suites, or null if all
1738     * cipher suites supported by the underlying SSL implementation are being
1739     * enabled
1740     */

1741    public String JavaDoc getCiphers() {
1742        String JavaDoc ret = (String JavaDoc) getProperty("ciphers");
1743        if (ret == null) {
1744            ServerSocketFactory factory = getFactory();
1745            if (factory instanceof CoyoteServerSocketFactory) {
1746                ret = ((CoyoteServerSocketFactory)factory).getCiphers();
1747            }
1748        }
1749
1750        return ret;
1751    }
1752
1753    /**
1754     * Sets the SSL cipher suites that are to be enabled.
1755     *
1756     * Only those SSL cipher suites that are actually supported by
1757     * the underlying SSL implementation will be enabled.
1758     *
1759     * @param ciphers Comma-separated list of SSL cipher suites
1760     */

1761    public void setCiphers(String JavaDoc ciphers) {
1762        setProperty("ciphers", ciphers);
1763        ServerSocketFactory factory = getFactory();
1764        if (factory instanceof CoyoteServerSocketFactory) {
1765            ((CoyoteServerSocketFactory)factory).setCiphers(ciphers);
1766        }
1767    }
1768
1769    /**
1770     * Sets the number of seconds after which SSL sessions expire and are
1771     * removed from the SSL sessions cache.
1772     */

1773    public void setSSLSessionTimeout(String JavaDoc timeout) {
1774        setProperty("sslSessionTimeout", timeout);
1775    }
1776
1777    /**
1778     * Sets the number of seconds after which SSL3 sessions expire and are
1779     * removed from the SSL sessions cache.
1780     */

1781    public void setSSL3SessionTimeout(String JavaDoc timeout) {
1782        setProperty("ssl3SessionTimeout", timeout);
1783    }
1784
1785    /**
1786     * Sets the number of SSL sessions that may be cached
1787     */

1788    public void setSSLSessionCacheSize(String JavaDoc cacheSize) {
1789        setProperty("sslSessionCacheSize", cacheSize);
1790    }
1791
1792    /**
1793     * Gets the alias name of the keypair and supporting certificate chain
1794     * used by this Connector to authenticate itself to SSL clients.
1795     *
1796     * @return The alias name of the keypair and supporting certificate chain
1797     */

1798    public String JavaDoc getKeyAlias() {
1799        String JavaDoc ret = (String JavaDoc) getProperty("keyAlias");
1800        if (ret == null) {
1801            ServerSocketFactory factory = getFactory();
1802            if (factory instanceof CoyoteServerSocketFactory) {
1803                ret = ((CoyoteServerSocketFactory)factory).getKeyAlias();
1804            }
1805        }
1806
1807        return ret;
1808    }
1809
1810    /**
1811     * Sets the alias name of the keypair and supporting certificate chain
1812     * used by this Connector to authenticate itself to SSL clients.
1813     *
1814     * @param alias The alias name of the keypair and supporting certificate
1815     * chain
1816     */

1817    public void setKeyAlias(String JavaDoc alias) {
1818        setProperty("keyAlias", alias);
1819        ServerSocketFactory factory = getFactory();
1820        if (factory instanceof CoyoteServerSocketFactory) {
1821            ((CoyoteServerSocketFactory)factory).setKeyAlias(alias);
1822        }
1823    }
1824
1825    /**
1826     * Gets the SSL protocol variant to be used.
1827     *
1828     * @return SSL protocol variant
1829     */

1830    public String JavaDoc getSslProtocol() {
1831        String JavaDoc ret = (String JavaDoc) getProperty("sslProtocol");
1832        if (ret == null) {
1833            ServerSocketFactory factory = getFactory();
1834            if (factory instanceof CoyoteServerSocketFactory) {
1835                ret = ((CoyoteServerSocketFactory)factory).getProtocol();
1836            }
1837        }
1838
1839        return ret;
1840    }
1841
1842    /**
1843     * Sets the SSL protocol variant to be used.
1844     *
1845     * @param sslProtocol SSL protocol variant
1846     */

1847    public void setSslProtocol(String JavaDoc sslProtocol) {
1848        setProperty("sslProtocol", sslProtocol);
1849        ServerSocketFactory factory = getFactory();
1850        if (factory instanceof CoyoteServerSocketFactory) {
1851            ((CoyoteServerSocketFactory)factory).setProtocol(sslProtocol);
1852        }
1853    }
1854
1855    /**
1856     * Gets the SSL protocol variants to be enabled.
1857     *
1858     * @return Comma-separated list of SSL protocol variants
1859     */

1860    public String JavaDoc getSslProtocols() {
1861        String JavaDoc ret = (String JavaDoc) getProperty("sslProtocols");
1862        if (ret == null) {
1863            ServerSocketFactory factory = getFactory();
1864            if (factory instanceof CoyoteServerSocketFactory) {
1865                ret = ((CoyoteServerSocketFactory)factory).getProtocols();
1866            }
1867        }
1868
1869        return ret;
1870    }
1871
1872    /**
1873     * Sets the SSL protocol variants to be enabled.
1874     *
1875     * @param sslProtocols Comma-separated list of SSL protocol variants
1876     */

1877    public void setSslProtocols(String JavaDoc sslProtocols) {
1878        setProperty("sslProtocols", sslProtocols);
1879        ServerSocketFactory factory = getFactory();
1880        if (factory instanceof CoyoteServerSocketFactory) {
1881            ((CoyoteServerSocketFactory)factory).setProtocols(sslProtocols);
1882        }
1883    }
1884    
1885    // START OF SJSAS 8.1 PE 6191830
1886
/**
1887     * Get the underlying WebContainer certificate for the request
1888     */

1889    public X509Certificate JavaDoc[] getCertificates(Request JavaDoc request) {
1890        
1891        CoyoteRequest cRequest = null;
1892        if (request instanceof CoyoteRequest) {
1893            cRequest=(CoyoteRequest) request;
1894        } else {
1895            return null;
1896        }
1897        
1898        X509Certificate JavaDoc certs[] = (X509Certificate JavaDoc[])
1899        cRequest.getAttribute(Globals.CERTIFICATES_ATTR);
1900        if ((certs == null) || (certs.length < 1)) {
1901            certs = (X509Certificate JavaDoc[])
1902            cRequest.getAttribute(Globals.SSL_CERTIFICATE_ATTR);
1903        }
1904        return certs;
1905    }
1906    // END OF SJSAS 8.1 PE 6191830
1907

1908
1909    // -------------------- JMX registration --------------------
1910
protected String JavaDoc domain;
1911    protected ObjectName JavaDoc oname;
1912    protected MBeanServer JavaDoc mserver;
1913    ObjectName JavaDoc controller;
1914
1915    public ObjectName JavaDoc getController() {
1916        return controller;
1917    }
1918
1919    public void setController(ObjectName JavaDoc controller) {
1920        this.controller = controller;
1921    }
1922
1923    public ObjectName JavaDoc getObjectName() {
1924        return oname;
1925    }
1926
1927    public String JavaDoc getDomain() {
1928        return domain;
1929    }
1930
1931    public ObjectName JavaDoc preRegister(MBeanServer JavaDoc server,
1932                                  ObjectName JavaDoc name) throws Exception JavaDoc {
1933        oname=name;
1934        mserver=server;
1935        domain=name.getDomain();
1936        return name;
1937    }
1938
1939    public void postRegister(Boolean JavaDoc registrationDone) {
1940    }
1941
1942    public void preDeregister() throws Exception JavaDoc {
1943    }
1944
1945    public void postDeregister() {
1946        try {
1947            if( started ) {
1948                stop();
1949            }
1950        } catch( Throwable JavaDoc t ) {
1951            log.error( "Unregistering - can't stop", t);
1952        }
1953    }
1954    
1955    private void findContainer() {
1956        try {
1957            // Register to the service
1958
ObjectName JavaDoc parentName=new ObjectName JavaDoc( domain + ":" +
1959                    "type=Service");
1960            
1961            log.debug("Adding to " + parentName );
1962            if( mserver.isRegistered(parentName )) {
1963                mserver.invoke(parentName, "addConnector", new Object JavaDoc[] { this },
1964                        new String JavaDoc[] {"org.apache.catalina.Connector"});
1965                // As a side effect we'll get the container field set
1966
// Also initialize will be called
1967
//return;
1968
}
1969            // XXX Go directly to the Engine
1970
// initialize(); - is called by addConnector
1971
ObjectName JavaDoc engName=new ObjectName JavaDoc( domain + ":" + "type=Engine");
1972            if( mserver.isRegistered(engName )) {
1973                Object JavaDoc obj=mserver.getAttribute(engName, "managedResource");
1974                log.debug("Found engine " + obj + " " + obj.getClass());
1975                container=(Container)obj;
1976                
1977                // Internal initialize - we now have the Engine
1978
initialize();
1979                
1980                log.debug("Initialized");
1981                // As a side effect we'll get the container field set
1982
// Also initialize will be called
1983
return;
1984            }
1985        } catch( Exception JavaDoc ex ) {
1986            log.error( "Error finding container " + ex);
1987        }
1988    }
1989
1990    public void init() throws Exception JavaDoc {
1991
1992        if( this.getService() != null ) {
1993            log.debug( "Already configured" );
1994            return;
1995        }
1996        if( container==null ) {
1997            findContainer();
1998        }
1999    }
2000
2001    public void destroy() throws Exception JavaDoc {
2002        if( oname!=null && controller==oname ) {
2003            log.debug("Unregister itself " + oname );
2004            Registry.getRegistry().unregisterComponent(oname);
2005        }
2006        if( getService() == null)
2007            return;
2008        getService().removeConnector(this);
2009    }
2010
2011    
2012    // START SJSAS 6363251
2013
/**
2014     * Set the <code>Adapter</code> used by this connector.
2015     */

2016    public void setAdapter(Adapter adapter){
2017        this.adapter = adapter;
2018    }
2019    
2020    
2021    /**
2022     * Get the <code>Adapter</code> used by this connector.
2023     */

2024    public Adapter getAdapter(){
2025        return adapter;
2026    }
2027 
2028    
2029    /**
2030     * Set the <code>ProtocolHandler</code> used by this connector.
2031     */

2032    public void setProtocolHandler(ProtocolHandler protocolHandler){
2033        this.protocolHandler = protocolHandler;
2034    }
2035    // END SJSAS 6363251
2036

2037}
2038
Popular Tags