KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > http > HttpConfiguration


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.http;
18
19 import java.io.File JavaDoc;
20 import java.io.FileInputStream JavaDoc;
21 import java.io.FileOutputStream JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.util.Properties JavaDoc;
24
25 import org.apache.servicemix.jbi.security.auth.AuthenticationService;
26 import org.apache.servicemix.jbi.security.keystore.KeystoreManager;
27 import org.mortbay.jetty.nio.SelectChannelConnector;
28
29 /**
30  *
31  * @author gnodet
32  * @org.apache.xbean.XBean element="configuration"
33  */

34 public class HttpConfiguration implements HttpConfigurationMBean {
35
36     public static final String JavaDoc DEFAULT_JETTY_CONNECTOR_CLASS_NAME = SelectChannelConnector.class.getName();
37     public static final String JavaDoc MAPPING_DEFAULT = "/jbi";
38     public final static String JavaDoc CONFIG_FILE = "component.properties";
39     
40     private String JavaDoc rootDir;
41     private Properties JavaDoc properties = new Properties JavaDoc();
42     private boolean streamingEnabled = false;
43     private String JavaDoc jettyConnectorClassName = DEFAULT_JETTY_CONNECTOR_CLASS_NAME;
44     private transient KeystoreManager keystoreManager;
45     private transient AuthenticationService authenticationService;
46     
47     /**
48      * The JNDI name of the AuthenticationService object
49      */

50     private String JavaDoc authenticationServiceName = "java:comp/env/smx/AuthenticationService";
51     
52     /**
53      * The JNDI name of the KeystoreManager object
54      */

55     private String JavaDoc keystoreManagerName = "java:comp/env/smx/KeystoreManager";
56
57     /**
58      * The maximum number of threads for the Jetty thread pool. It's set
59      * to 255 by default to match the default value in Jetty.
60      */

61     private int jettyThreadPoolSize = 255;
62     
63     /**
64      * Maximum number of concurrent requests to the same host.
65      */

66     private int maxConnectionsPerHost = 32;
67     
68     /**
69      * Maximum number of concurrent requests.
70      */

71     private int maxTotalConnections = 256;
72     
73     /**
74      * If true, use register jetty mbeans
75      */

76     private boolean jettyManagement;
77     
78     /**
79      * If the component is deployed in a web container and uses
80      * a servlet instead of starting its own web server.
81      */

82     private boolean managed = false;
83     
84     /**
85      * When managed is true, this is the servlet mapping used
86      * to access the component.
87      */

88     private transient String JavaDoc mapping = MAPPING_DEFAULT;
89
90     /**
91      * @return Returns the rootDir.
92      */

93     public String JavaDoc getRootDir() {
94         return rootDir;
95     }
96
97     /**
98      * @param rootDir The rootDir to set.
99      */

100     public void setRootDir(String JavaDoc rootDir) {
101         this.rootDir = rootDir;
102     }
103
104     /**
105      * @return the mapping
106      */

107     public String JavaDoc getMapping() {
108         return mapping;
109     }
110
111     /**
112      * @param mapping the mapping to set
113      */

114     public void setMapping(String JavaDoc mapping) {
115         if (!mapping.startsWith("/")) {
116             mapping = "/" + mapping;
117         }
118         if (mapping.endsWith("/")) {
119             mapping = mapping.substring(0, mapping.length() - 1);
120         }
121         this.mapping = mapping;
122     }
123
124     /**
125      * @return the managed
126      */

127     public boolean isManaged() {
128         return managed;
129     }
130
131     /**
132      * @param managed the managed to set
133      */

134     public void setManaged(boolean managed) {
135         this.managed = managed;
136     }
137
138     /**
139      * @return the jettyManagement
140      */

141     public boolean isJettyManagement() {
142         return jettyManagement;
143     }
144
145     /**
146      * @param jettyManagement the jettyManagement to set
147      */

148     public void setJettyManagement(boolean jettyManagement) {
149         this.jettyManagement = jettyManagement;
150     }
151
152     /**
153      * @return the authenticationService
154      */

155     public AuthenticationService getAuthenticationService() {
156         return authenticationService;
157     }
158
159     /**
160      * @param authenticationService the authenticationService to set
161      */

162     public void setAuthenticationService(AuthenticationService authenticationService) {
163         this.authenticationService = authenticationService;
164     }
165
166     /**
167      * @return the authenticationServiceName
168      */

169     public String JavaDoc getAuthenticationServiceName() {
170         return authenticationServiceName;
171     }
172
173     /**
174      * @param authenticationServiceName the authenticationServiceName to set
175      */

176     public void setAuthenticationServiceName(String JavaDoc authenticationServiceName) {
177         this.authenticationServiceName = authenticationServiceName;
178         save();
179     }
180
181     /**
182      * @return the keystoreManager
183      */

184     public KeystoreManager getKeystoreManager() {
185         return keystoreManager;
186     }
187
188     /**
189      * @param keystoreManager the keystoreManager to set
190      */

191     public void setKeystoreManager(KeystoreManager keystoreManager) {
192         this.keystoreManager = keystoreManager;
193     }
194
195     /**
196      * @return the keystoreManagerName
197      */

198     public String JavaDoc getKeystoreManagerName() {
199         return keystoreManagerName;
200     }
201
202     /**
203      * @param keystoreManagerName the keystoreManagerName to set
204      */

205     public void setKeystoreManagerName(String JavaDoc keystoreManagerName) {
206         this.keystoreManagerName = keystoreManagerName;
207         save();
208     }
209
210     public boolean isStreamingEnabled() {
211         return streamingEnabled;
212     }
213
214     public void setStreamingEnabled(boolean streamingEnabled) {
215         this.streamingEnabled = streamingEnabled;
216         save();
217     }
218
219     public String JavaDoc getJettyConnectorClassName() {
220         return jettyConnectorClassName;
221     }
222
223     public void setJettyConnectorClassName(String JavaDoc jettyConnectorClassName) {
224         this.jettyConnectorClassName = jettyConnectorClassName;
225         save();
226     }
227
228     public int getJettyThreadPoolSize() {
229         return jettyThreadPoolSize;
230     }
231
232     public void setJettyThreadPoolSize(int jettyThreadPoolSize) {
233         this.jettyThreadPoolSize = jettyThreadPoolSize;
234         save();
235     }
236     
237     public int getMaxConnectionsPerHost() {
238         return maxConnectionsPerHost;
239     }
240
241     public void setMaxConnectionsPerHost(int maxConnectionsPerHost) {
242         this.maxConnectionsPerHost = maxConnectionsPerHost;
243         save();
244     }
245
246     public int getMaxTotalConnections() {
247         return maxTotalConnections;
248     }
249
250     public void setMaxTotalConnections(int maxTotalConnections) {
251         this.maxTotalConnections = maxTotalConnections;
252         save();
253     }
254     
255     public void save() {
256         properties.setProperty("jettyThreadPoolSize", Integer.toString(jettyThreadPoolSize));
257         properties.setProperty("jettyConnectorClassName", jettyConnectorClassName);
258         properties.setProperty("streamingEnabled", Boolean.toString(streamingEnabled));
259         properties.setProperty("maxConnectionsPerHost", Integer.toString(maxConnectionsPerHost));
260         properties.setProperty("maxTotalConnections", Integer.toString(maxTotalConnections));
261         properties.setProperty("keystoreManagerName", keystoreManagerName);
262         properties.setProperty("authenticationServiceName", authenticationServiceName);
263         properties.setProperty("jettyManagement", Boolean.toString(jettyManagement));
264         if (rootDir != null) {
265             File JavaDoc f = new File JavaDoc(rootDir, CONFIG_FILE);
266             try {
267                 this.properties.store(new FileOutputStream JavaDoc(f), null);
268             } catch (Exception JavaDoc e) {
269                 throw new RuntimeException JavaDoc("Could not store component configuration", e);
270             }
271         }
272     }
273     
274     public boolean load() {
275         if (rootDir == null) {
276             return false;
277         }
278         File JavaDoc f = new File JavaDoc(rootDir, CONFIG_FILE);
279         if (!f.exists()) {
280             return false;
281         }
282         try {
283             properties.load(new FileInputStream JavaDoc(f));
284         } catch (IOException JavaDoc e) {
285             throw new RuntimeException JavaDoc("Could not load component configuration", e);
286         }
287         if (properties.getProperty("jettyThreadPoolSize") != null) {
288             jettyThreadPoolSize = Integer.parseInt(properties.getProperty("jettyThreadPoolSize"));
289         }
290         if (properties.getProperty("jettyConnectorClassName") != null) {
291             jettyConnectorClassName = properties.getProperty("jettyConnectorClassName");
292         }
293         if (properties.getProperty("streamingEnabled") != null) {
294             streamingEnabled = Boolean.valueOf(properties.getProperty("streamingEnabled")).booleanValue();
295         }
296         if (properties.getProperty("maxConnectionsPerHost") != null) {
297             maxConnectionsPerHost = Integer.parseInt(properties.getProperty("maxConnectionsPerHost"));
298         }
299         if (properties.getProperty("maxTotalConnections") != null) {
300             maxTotalConnections = Integer.parseInt(properties.getProperty("maxTotalConnections"));
301         }
302         if (properties.getProperty("keystoreManagerName") != null) {
303             keystoreManagerName = properties.getProperty("keystoreManagerName");
304         }
305         if (properties.getProperty("authenticationServiceName") != null) {
306             authenticationServiceName = properties.getProperty("authenticationServiceName");
307         }
308         if (properties.getProperty("jettyManagement") != null) {
309             jettyManagement = Boolean.valueOf(properties.getProperty("jettyManagement")).booleanValue();
310         }
311         return true;
312     }
313
314 }
315
Popular Tags