001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *  http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    package org.apache.geronimo.tomcat.connector;
020    
021    import java.util.Map;
022    
023    import org.apache.geronimo.gbean.GBeanInfo;
024    import org.apache.geronimo.gbean.GBeanInfoBuilder;
025    import org.apache.geronimo.management.geronimo.WebManager;
026    import org.apache.geronimo.system.serverinfo.ServerInfo;
027    import org.apache.geronimo.tomcat.TomcatContainer;
028    
029    public class Http11APRConnectorGBean extends BaseHttp11ConnectorGBean implements Http11APRProtocol {
030    
031        private String certificateFile;
032        private String certificateKeyFile;
033        private String caCertificateFile;
034        private String caCertificatePath;
035        private String certificateChainFile;
036        private String revocationPath;
037        private String revocationFile;
038        
039        public Http11APRConnectorGBean(String name, Map initParams, String host, int port, TomcatContainer container, ServerInfo serverInfo) throws Exception {
040            super(name, initParams, "org.apache.coyote.http11.Http11AprProtocol", host, port, container, serverInfo);
041        }
042    
043        @Override
044        public int getDefaultPort() {
045            return 80;
046        }
047    
048        @Override
049        public String getGeronimoProtocol() {
050            return WebManager.PROTOCOL_HTTP;
051        }
052    
053        public int getPollTime() {
054            Object value = connector.getAttribute("pollTime");
055            return value == null ? 2000 : new Integer(value.toString()).intValue();
056        }
057    
058        public int getPollerSize() {
059            Object value = connector.getAttribute("pollerSize");
060            return value == null ? 8192 : new Integer(value.toString()).intValue();
061        }
062    
063        public int getSendfileSize() {
064            Object value = connector.getAttribute("sendfileSize");
065            return value == null ? 8192 : new Integer(value.toString()).intValue();
066        }
067    
068        public String getSslCACertificateFile() {
069            return caCertificateFile;
070        }
071    
072        public String getSslCACertificatePath() {
073            return caCertificatePath;
074        }
075    
076        public String getSslCertificateChainFile() {
077            return certificateChainFile; 
078        }
079    
080        public String getSslCertificateFile() {
081            return certificateFile; 
082        }
083    
084        public String getSslCertificateKeyFile() {
085            return certificateKeyFile; 
086        }
087    
088        public String getSslCipherSuite() {
089            return (String) connector.getAttribute("SSLCipherSuite");
090        }
091        
092        public String getSslProtocol() {
093            return (String) connector.getAttribute("SSLProtocol");
094        }
095    
096        public String getSslCARevocationFile() {
097            return revocationFile;
098        }
099    
100        public String getSslCARevocationPath() {
101            return revocationPath;
102        }
103    
104        public String getSslVerifyClient() {
105            return (String) connector.getAttribute("SSLVerifyClient");
106        }
107    
108        public int getSslVerifyDepth() {
109            Object value = connector.getAttribute("SSLVerifyDepth");
110            return value == null ? 10 : new Integer(value.toString()).intValue();
111        }
112    
113        public boolean getUseSendfile() {
114            Object value = connector.getAttribute("useSendfile");
115            return value == null ? true : new Boolean(value.toString()).booleanValue();
116        }
117    
118        public void setPollTime(int pollTime) {
119            connector.setAttribute("pollTime", pollTime);
120        }
121    
122        public void setPollerSize(int pollerSize) {
123            connector.setAttribute("pollerSize", pollerSize);
124        }
125    
126        public void setSendfileSize(int sendfileSize) {
127            connector.setAttribute("sendfileSize", sendfileSize);
128        }
129    
130        public void setSslCACertificateFile(String sslCACertificateFile) {
131            if (sslCACertificateFile != null && sslCACertificateFile.equals(""))
132                sslCACertificateFile = null;
133            caCertificateFile = sslCACertificateFile;
134            if (caCertificateFile == null)
135                connector.setAttribute("SSLCACertificateFile", null);
136            else
137                connector.setAttribute("SSLCACertificateFile", serverInfo.resolveServerPath(caCertificateFile));
138        }
139    
140        public void setSslCACertificatePath(String sslCACertificatePath) {
141            if (sslCACertificatePath != null && sslCACertificatePath.equals(""))
142                sslCACertificatePath = null;
143            caCertificatePath = sslCACertificatePath;
144            if (caCertificatePath == null)
145                connector.setAttribute("SSLCACertificatePath", null);
146            else
147                connector.setAttribute("SSLCACertificatePath", serverInfo.resolveServerPath(caCertificatePath));
148        }
149    
150        public void setSslCertificateChainFile(String sslCertificateChainFile) {
151            if (sslCertificateChainFile != null && sslCertificateChainFile.equals(""))
152                sslCertificateChainFile = null;
153            certificateChainFile = sslCertificateChainFile;
154            if (certificateChainFile == null)
155                connector.setAttribute("SSLCertificateChainFile", null);
156            else
157                connector.setAttribute("SSLCertificateChainFile", serverInfo.resolveServerPath(certificateChainFile));
158        }
159    
160        public void setSslCertificateFile(String sslCertificateFile) {
161            if (sslCertificateFile != null && sslCertificateFile.equals(""))
162                sslCertificateFile = null;
163            certificateFile = sslCertificateFile;
164            if (certificateFile == null)
165                connector.setAttribute("SSLCertificateFile", null);
166            else
167                connector.setAttribute("SSLCertificateFile", serverInfo.resolveServerPath(certificateFile));
168        }
169    
170        public void setSslCertificateKeyFile(String sslCertificateKeyFile) {
171            if (sslCertificateKeyFile != null && sslCertificateKeyFile.equals(""))
172                sslCertificateKeyFile = null;
173            certificateKeyFile = sslCertificateKeyFile;
174            if (certificateKeyFile == null)
175                connector.setAttribute("SSLCertificateKeyFile", null);
176            else
177                connector.setAttribute("SSLCertificateKeyFile", serverInfo.resolveServerPath(certificateKeyFile));
178        }
179    
180        public void setSslCipherSuite(String sslCipherSuite) {
181            connector.setAttribute("SSLCipherSuite", sslCipherSuite);
182        }
183    
184        public void setSslPassword(String sslPassword) {
185            if (sslPassword != null && sslPassword.equals(""))
186                sslPassword = null;
187            connector.setAttribute("SSLPassword", sslPassword);
188        }
189        
190        public void setSslProtocol(String sslProtocol) {
191            connector.setAttribute("SSLProtocol", sslProtocol);
192        }
193    
194        public void setSslCARevocationFile(String sslCARevocationFile) {
195            if (sslCARevocationFile!= null && sslCARevocationFile.equals("")) 
196                sslCARevocationFile = null;
197            revocationFile = sslCARevocationFile;
198            if (revocationFile == null)
199                connector.setAttribute("SSLCARevocationFile", null);
200            else
201                connector.setAttribute("SSLCARevocationFile", serverInfo.resolveServerPath(revocationFile));
202        }
203    
204        public void setSslCARevocationPath(String sslCARevocationPath) {
205            if (sslCARevocationPath!= null && sslCARevocationPath.equals("")) 
206                sslCARevocationPath = null;
207            revocationPath = sslCARevocationPath;
208            if (revocationPath == null)
209                connector.setAttribute("SSLCARevocationPath", null);
210            else
211                connector.setAttribute("SSLCARevocationPath", serverInfo.resolveServerPath(revocationPath));
212    
213        }
214    
215        public void setSslVerifyClient(String sslVerifyClient) {
216            connector.setAttribute("SSLVerifyClient", sslVerifyClient);
217        }
218    
219        public void setSslVerifyDepth(int sslVerifyDepth) {
220            connector.setAttribute("SSLVerifyDepth", sslVerifyDepth);
221        }
222    
223        public void setUseSendfile(boolean useSendfile) {
224            connector.setAttribute("useSendfile", useSendfile);
225        }
226        
227        public static final GBeanInfo GBEAN_INFO;
228    
229        static {
230            GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("Tomcat Connector HTTP APR", Http11APRConnectorGBean.class, BaseHttp11ConnectorGBean.GBEAN_INFO);
231            infoFactory.addInterface(Http11APRProtocol.class, 
232                    new String[] {
233                        //APR Attributes
234                        "pollTime",
235                        "pollerSize",
236                        "useSendfile",
237                        "sendfileSize",
238                        //SSL Attributes
239                        "sslProtocol",
240                        "sslCipherSuite",
241                        "sslCertificateFile",
242                        "sslCertificateKeyFile",
243                        "sslPassword",
244                        "sslVerifyClient",
245                        "sslVerifyDepth",
246                        "sslCACertificateFile",
247                        "sslCACertificatePath",
248                        "sslCertificateChainFile",
249                        "sslCARevocationFile",
250                        "sslCARevocationPath"
251                    },
252                    new String[] {
253                        //APR Attributes
254                        "pollTime",
255                        "pollerSize",
256                        "useSendfile",
257                        "sendfileSize",
258                        //SSL Attributes
259                        "sslProtocol",
260                        "sslCipherSuite",
261                        "sslCertificateFile",
262                        "sslCertificateKeyFile",
263                        "sslPassword",
264                        "sslVerifyClient",
265                        "sslVerifyDepth",
266                        "sslCACertificateFile",
267                        "sslCACertificatePath",
268                        "sslCertificateChainFile",
269                        "sslCARevocationFile",
270                        "sslCARevocationPath"
271                    }
272            );
273            infoFactory.setConstructor(new String[] { "name", "initParams", "host", "port", "TomcatContainer", "ServerInfo"});
274            GBEAN_INFO = infoFactory.getBeanInfo();
275        }
276        
277        public static GBeanInfo getGBeanInfo() {
278            return GBEAN_INFO;
279        }
280    
281    }