1 23 24 29 30 package com.sun.enterprise.web; 31 32 import java.util.ArrayList ; 33 import java.util.logging.Logger ; 34 import java.util.logging.Level ; 35 import java.util.ResourceBundle ; 36 import com.sun.logging.LogDomains; 37 38 import com.sun.enterprise.config.ConfigContext; 39 import org.apache.catalina.core.StandardContext; 40 import com.sun.enterprise.web.session.PersistenceType; 42 import com.sun.enterprise.deployment.runtime.web.SessionManager; 43 import com.sun.enterprise.deployment.runtime.web.ManagerProperties; 44 import com.sun.enterprise.deployment.runtime.web.StoreProperties; 45 import com.sun.enterprise.deployment.runtime.web.WebProperty; 46 import com.sun.enterprise.deployment.WebBundleDescriptor; 47 48 52 public class SessionManagerConfigurationHelper { 53 54 55 public SessionManagerConfigurationHelper( 56 WebModule ctx, SessionManager smBean, WebBundleDescriptor wbd, WebModuleConfig wmInfo) { 57 _ctx = ctx; 58 _smBean = smBean; 59 _wbd = wbd; 60 _wmInfo = wmInfo; 61 _systemApps.add("com_sun_web_ui"); 62 _systemApps.add(Constants.DEFAULT_WEB_MODULE_PREFIX + "admingui"); 63 _systemApps.add("adminapp"); 64 _systemApps.add("admingui"); 65 66 if (_logger == null) { 67 _logger = LogDomains.getLogger(LogDomains.WEB_LOGGER); 68 _rb = _logger.getResourceBundle(); 69 } 70 } 71 72 private boolean isSystemApp(String appName) { 73 return _systemApps.contains(appName); 74 } 75 76 public void initializeConfiguration() { 77 78 ConfigContext dynamicConfigContext = null; 79 com.sun.enterprise.config.serverbeans.WebModule wmBean = _wmInfo.getBean(); 80 if(wmBean != null) { 82 dynamicConfigContext = wmBean.getConfigContext(); 83 } 85 87 boolean isAppDistributable = false; 88 if (_wbd != null) 89 isAppDistributable = _wbd.isDistributable(); 90 if(_logger.isLoggable(Level.FINEST)) { 91 _logger.finest("Web App Distributable (" + getApplicationId(_ctx) + "): " + isAppDistributable); 92 } 93 94 PersistenceType persistence = PersistenceType.MEMORY; 95 String persistenceFrequency = null; 96 String persistenceScope = null; 97 98 ServerConfigLookup serverConfigLookup = null; 101 105 if(dynamicConfigContext != null) { 106 serverConfigLookup = new ServerConfigLookup(dynamicConfigContext); 107 } else { 108 serverConfigLookup = new ServerConfigLookup(); 109 } 110 111 String contextRoot = ((WebModule)_ctx).getContextRoot(); 114 String j2eeAppName = ((StandardContext)_ctx).getJ2EEApplication(); 115 boolean isAvailabilityEnabled = 116 serverConfigLookup.calculateWebAvailabilityEnabledFromConfig(contextRoot, j2eeAppName); 118 if(_logger.isLoggable(Level.FINEST)) { 120 _logger.finest("AvailabilityGloballyEnabled = " + isAvailabilityEnabled); 121 } 122 if(isAvailabilityEnabled) { 123 persistence = PersistenceType.HA; 126 persistenceFrequency = "time-based"; 127 persistenceScope = "session"; 128 } 129 130 PersistenceType serverDefaultPersistenceType = 132 serverConfigLookup.getPersistenceTypeFromConfig(); 133 134 if(serverDefaultPersistenceType != null) { 135 persistence = serverDefaultPersistenceType; 137 persistenceFrequency = serverConfigLookup.getPersistenceFrequencyFromConfig(); 138 persistenceScope = serverConfigLookup.getPersistenceScopeFromConfig(); 139 } 140 String insLevelPersistenceTypeString = null; 141 if(persistence != null) { 142 insLevelPersistenceTypeString = persistence.getType(); 143 } 144 if(_logger.isLoggable(Level.FINEST)) { 145 _logger.finest("instance-level persistence-type = " + insLevelPersistenceTypeString); 146 _logger.finest("instance-level persistenceFrequency = " + persistenceFrequency); 147 _logger.finest("instance-level persistenceScope = " + persistenceScope); 148 } 149 150 String webAppLevelPersistenceFrequency = null; 151 String webAppLevelPersistenceScope = null; 152 153 if (_smBean != null) { 154 String pType = _smBean.getAttributeValue(SessionManager.PERSISTENCE_TYPE); 157 if(_logger.isLoggable(Level.FINEST)) { 158 _logger.finest("webAppLevelPersistenceType = " + pType); 159 } 160 persistence = PersistenceType.parseType(pType, persistence); 163 164 webAppLevelPersistenceFrequency = getPersistenceFrequency(_smBean); 165 webAppLevelPersistenceScope = getPersistenceScope(_smBean); 166 if(_logger.isLoggable(Level.FINEST)) { 167 _logger.finest("webAppLevelPersistenceFrequency = " + webAppLevelPersistenceFrequency); 168 _logger.finest("webAppLevelPersistenceScope = " + webAppLevelPersistenceScope); 169 } 170 } 171 172 if(webAppLevelPersistenceFrequency != null) { 174 persistenceFrequency = webAppLevelPersistenceFrequency; 175 } 176 if(webAppLevelPersistenceScope != null) { 177 persistenceScope = webAppLevelPersistenceScope; 178 } 179 if(_logger.isLoggable(Level.FINEST)) { 180 _logger.finest("IN WebContainer>>ConfigureSessionManager after web level check"); 181 _logger.finest("AFTER_WEB_PERSISTENCE-TYPE IS = " + persistence.getType()); 182 _logger.finest("AFTER_WEB_PERSISTENCE_FREQUENCY IS = " + persistenceFrequency); 183 _logger.finest("AFTER_WEB_PERSISTENCE_SCOPE IS = " + persistenceScope); 184 } 185 186 String frequency = null; 188 String scope = null; 189 if( persistence == PersistenceType.MEMORY 190 | persistence == PersistenceType.FILE 191 | persistence == PersistenceType.CUSTOM) { 192 } else { 194 frequency = persistenceFrequency; 195 scope = persistenceScope; 196 } 197 198 if(!isAppDistributable && persistence != PersistenceType.MEMORY) { 201 String wmName = getApplicationId(_ctx); 202 if(_logger.isLoggable(Level.FINEST)) { 203 _logger.finest("is " + wmName + " a system app: " + isSystemApp(wmName)); 204 } 205 if (isAvailabilityEnabled && !wmName.equals(Constants.DEFAULT_WEB_MODULE_NAME) && !this.isSystemApp(wmName)) { 208 Object [] params = { getApplicationId(_ctx), persistence.getType(), frequency, scope }; 210 _logger.log(Level.INFO, "webcontainer.invalidSessionManagerConfig2", 211 params); 212 } 213 persistence = PersistenceType.MEMORY; 215 frequency = null; 216 scope = null; 217 } 218 219 if(!isAvailabilityEnabled) { 221 persistence = PersistenceType.MEMORY; 223 frequency = null; 224 scope = null; 225 } 226 227 if(_logger.isLoggable(Level.FINEST)) { 228 _logger.finest("IN WebContainer>>ConfigureSessionManager before builder factory"); 229 _logger.finest("FINAL_PERSISTENCE-TYPE IS = " + persistence.getType()); 230 _logger.finest("FINAL_PERSISTENCE_FREQUENCY IS = " + frequency); 231 _logger.finest("FINAL_PERSISTENCE_SCOPE IS = " + scope); 232 } 233 234 _persistence = persistence; 235 _persistenceFrequency = frequency; 236 _persistenceScope = scope; 237 238 } 239 240 244 public String getApplicationId(WebModule ctx) { 245 com.sun.enterprise.web.WebModule wm = 246 (com.sun.enterprise.web.WebModule)ctx; 247 return wm.getID(); 248 } 249 250 256 private String getPersistenceFrequency(SessionManager smBean) { 257 String persistenceFrequency = null; 258 ManagerProperties mgrBean = smBean.getManagerProperties(); 259 if ((mgrBean != null) && (mgrBean.sizeWebProperty() > 0)) { 260 WebProperty[] props = mgrBean.getWebProperty(); 261 for (int i = 0; i < props.length; i++) { 262 String name = props[i].getAttributeValue(WebProperty.NAME); 265 String value = props[i].getAttributeValue(WebProperty.VALUE); 266 if (name.equalsIgnoreCase("persistenceFrequency")) { 267 persistenceFrequency = value; 268 } 269 } 270 } 271 return persistenceFrequency; 272 } 273 274 280 private String getPersistenceScope(SessionManager smBean) { 281 String persistenceScope = null; 282 StoreProperties storeBean = smBean.getStoreProperties(); 283 if ((storeBean != null) && (storeBean.sizeWebProperty() > 0)) { 284 WebProperty[] props = storeBean.getWebProperty(); 285 for (int i = 0; i < props.length; i++) { 286 String name = props[i].getAttributeValue(WebProperty.NAME); 289 String value = props[i].getAttributeValue(WebProperty.VALUE); 290 if (name.equalsIgnoreCase("persistenceScope")) { 291 persistenceScope = value; 292 } 293 } 294 } 295 return persistenceScope; 296 } 297 298 public void checkInitialization() { 299 if(!_initialized) { 300 initializeConfiguration(); 301 _initialized = true; 302 } 303 } 304 305 public PersistenceType getPersistenceType() { 306 checkInitialization(); 307 return _persistence; 308 } 309 310 public String getPersistenceFrequency() { 311 checkInitialization(); 312 return _persistenceFrequency; 313 } 314 315 public String getPersistenceScope() { 316 checkInitialization(); 317 return _persistenceScope; 318 } 319 320 WebModule _ctx = null; 321 SessionManager _smBean = null; 322 WebBundleDescriptor _wbd = null; 323 WebModuleConfig _wmInfo = null; 324 PersistenceType _persistence = PersistenceType.MEMORY; 325 String _persistenceFrequency = null; 326 String _persistenceScope = null; 327 boolean _initialized = false; 328 ArrayList _systemApps = new ArrayList (); 329 330 333 protected static Logger _logger = null; 334 335 338 protected static ResourceBundle _rb = null; 339 340 } 341 | Popular Tags |