1 17 package org.apache.servicemix.http; 18 19 import java.io.File ; 20 import java.io.FileInputStream ; 21 import java.io.FileOutputStream ; 22 import java.io.IOException ; 23 import java.util.Properties ; 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 34 public class HttpConfiguration implements HttpConfigurationMBean { 35 36 public static final String DEFAULT_JETTY_CONNECTOR_CLASS_NAME = SelectChannelConnector.class.getName(); 37 public static final String MAPPING_DEFAULT = "/jbi"; 38 public final static String CONFIG_FILE = "component.properties"; 39 40 private String rootDir; 41 private Properties properties = new Properties (); 42 private boolean streamingEnabled = false; 43 private String jettyConnectorClassName = DEFAULT_JETTY_CONNECTOR_CLASS_NAME; 44 private transient KeystoreManager keystoreManager; 45 private transient AuthenticationService authenticationService; 46 47 50 private String authenticationServiceName = "java:comp/env/smx/AuthenticationService"; 51 52 55 private String keystoreManagerName = "java:comp/env/smx/KeystoreManager"; 56 57 61 private int jettyThreadPoolSize = 255; 62 63 66 private int maxConnectionsPerHost = 32; 67 68 71 private int maxTotalConnections = 256; 72 73 76 private boolean jettyManagement; 77 78 82 private boolean managed = false; 83 84 88 private transient String mapping = MAPPING_DEFAULT; 89 90 93 public String getRootDir() { 94 return rootDir; 95 } 96 97 100 public void setRootDir(String rootDir) { 101 this.rootDir = rootDir; 102 } 103 104 107 public String getMapping() { 108 return mapping; 109 } 110 111 114 public void setMapping(String 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 127 public boolean isManaged() { 128 return managed; 129 } 130 131 134 public void setManaged(boolean managed) { 135 this.managed = managed; 136 } 137 138 141 public boolean isJettyManagement() { 142 return jettyManagement; 143 } 144 145 148 public void setJettyManagement(boolean jettyManagement) { 149 this.jettyManagement = jettyManagement; 150 } 151 152 155 public AuthenticationService getAuthenticationService() { 156 return authenticationService; 157 } 158 159 162 public void setAuthenticationService(AuthenticationService authenticationService) { 163 this.authenticationService = authenticationService; 164 } 165 166 169 public String getAuthenticationServiceName() { 170 return authenticationServiceName; 171 } 172 173 176 public void setAuthenticationServiceName(String authenticationServiceName) { 177 this.authenticationServiceName = authenticationServiceName; 178 save(); 179 } 180 181 184 public KeystoreManager getKeystoreManager() { 185 return keystoreManager; 186 } 187 188 191 public void setKeystoreManager(KeystoreManager keystoreManager) { 192 this.keystoreManager = keystoreManager; 193 } 194 195 198 public String getKeystoreManagerName() { 199 return keystoreManagerName; 200 } 201 202 205 public void setKeystoreManagerName(String 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 getJettyConnectorClassName() { 220 return jettyConnectorClassName; 221 } 222 223 public void setJettyConnectorClassName(String 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 f = new File (rootDir, CONFIG_FILE); 266 try { 267 this.properties.store(new FileOutputStream (f), null); 268 } catch (Exception e) { 269 throw new RuntimeException ("Could not store component configuration", e); 270 } 271 } 272 } 273 274 public boolean load() { 275 if (rootDir == null) { 276 return false; 277 } 278 File f = new File (rootDir, CONFIG_FILE); 279 if (!f.exists()) { 280 return false; 281 } 282 try { 283 properties.load(new FileInputStream (f)); 284 } catch (IOException e) { 285 throw new RuntimeException ("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 |