1 23 24 package com.sun.enterprise.web; 25 26 import com.sun.enterprise.util.OS; 27 import java.io.File ; 28 import java.net.MalformedURLException ; 29 import java.net.URL ; 30 import java.net.URLClassLoader ; 31 import java.text.MessageFormat ; 32 import java.util.Iterator ; 33 import java.util.HashMap ; 34 import java.util.Hashtable ; 36 import java.util.ArrayList ; 37 import java.util.List ; 39 import java.util.ListIterator ; 40 import java.util.logging.Logger ; 41 import java.util.logging.Level ; 42 import java.util.ResourceBundle ; 43 import java.util.Set ; 44 import java.util.Vector ; 45 import javax.naming.NamingException ; 46 47 import org.apache.catalina.startup.Embedded; 48 import org.apache.catalina.Container; 49 import org.apache.catalina.Context; 50 import org.apache.catalina.Deployer; 51 import org.apache.catalina.Engine; 52 import org.apache.catalina.Loader; 53 import org.apache.catalina.Lifecycle; 54 import org.apache.catalina.LifecycleException; 55 import org.apache.catalina.LifecycleListener; 56 import org.apache.catalina.Manager; 57 import org.apache.catalina.Valve; 58 import org.apache.catalina.core.StandardContext; 59 import org.apache.catalina.core.StandardEngine; 60 import org.apache.catalina.core.StandardHost; 61 import org.apache.catalina.deploy.ErrorPage; 62 import org.apache.catalina.loader.WebappLoader; 63 import org.apache.catalina.session.FileStore; 64 import org.apache.catalina.session.PersistentManager; 65 import org.apache.catalina.session.StandardManager; 66 import org.apache.catalina.util.LifecycleSupport; 67 import org.apache.catalina.util.ServerInfo; 68 import org.apache.catalina.startup.TldConfig; 69 import org.apache.catalina.startup.DigesterFactory; 70 import org.apache.catalina.valves.RemoteAddrValve; 71 import org.apache.catalina.valves.RemoteHostValve; 72 import org.apache.jasper.compiler.TldLocationsCache; 73 import org.apache.jasper.xmlparser.ParserUtils; 74 import org.apache.coyote.tomcat5.CoyoteRequest; 75 import com.sun.enterprise.config.ConfigBean; 76 import com.sun.enterprise.config.ConfigContext; 77 import com.sun.enterprise.config.ConfigBeansFactory; 78 import com.sun.enterprise.config.ConfigException; 79 import com.sun.enterprise.config.serverbeans.ApplicationHelper; 80 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 81 import com.sun.enterprise.config.serverbeans.Applications; 82 import com.sun.enterprise.config.serverbeans.J2eeApplication; 83 import com.sun.enterprise.config.serverbeans.LogService; 84 import com.sun.enterprise.config.serverbeans.Config; 85 import com.sun.enterprise.config.serverbeans.DasConfig; 86 import com.sun.enterprise.config.serverbeans.Server; 87 import com.sun.enterprise.config.serverbeans.HttpService; 88 import com.sun.enterprise.config.serverbeans.HttpProtocol; 89 import com.sun.enterprise.config.serverbeans.ElementProperty; 90 import com.sun.enterprise.instance.InstanceEnvironment; 91 import com.sun.enterprise.server.ApplicationRegistry; 92 import com.sun.enterprise.server.StandaloneWebModulesManager; 93 import com.sun.enterprise.server.ServerContext; 94 import com.sun.enterprise.server.pluggable.WebContainerFeatureFactory; 95 import com.sun.enterprise.deployment.runtime.web.SunWebApp; 96 import com.sun.enterprise.deployment.runtime.web.CookieProperties; 97 import com.sun.enterprise.deployment.runtime.web.ManagerProperties; 98 import com.sun.enterprise.deployment.runtime.web.SessionConfig; 99 import com.sun.enterprise.deployment.runtime.web.SessionManager; 100 import com.sun.enterprise.deployment.runtime.web.SessionProperties; 101 import com.sun.enterprise.deployment.runtime.web.StoreProperties; 102 import com.sun.enterprise.deployment.runtime.web.WebProperty; 103 import com.sun.enterprise.deployment.Application; 104 import com.sun.enterprise.deployment.util.WebValidatorWithoutCL; 105 import com.sun.enterprise.deployment.util.WebBundleVisitor; 106 import com.sun.enterprise.management.util.J2EEModuleUtil; 107 import com.sun.enterprise.util.io.FileUtils; 108 import com.sun.enterprise.util.logging.IASLevel; 109 import com.sun.enterprise.util.StringUtils; 110 import com.sun.enterprise.web.logger.IASLogger; 111 import com.sun.enterprise.web.session.PersistenceType; 112 import com.sun.enterprise.web.session.SessionCookieConfig; 113 import com.sun.enterprise.security.web.SingleSignOn; 114 115 import com.sun.enterprise.security.SecurityUtil; 116 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapper; 117 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactory; 118 119 import com.sun.enterprise.deployment.Application; 120 import com.sun.enterprise.deployment.WebBundleDescriptor; 121 import com.sun.enterprise.deployment.WebServicesDescriptor; 122 import com.sun.enterprise.deployment.WebServiceEndpoint; 123 import com.sun.enterprise.instance.WebModulesManager; 124 import com.sun.enterprise.instance.AppsManager; 125 import com.sun.enterprise.Switch; 126 import com.sun.appserv.server.ServerLifecycleException; 127 import com.sun.appserv.server.util.ASClassLoaderUtil; 128 import com.sun.appserv.server.util.Version; 129 import com.sun.logging.LogDomains; 130 131 import com.sun.web.security.WebSecurityManager; 132 import com.sun.web.security.WebSecurityManagerFactory; 133 import com.sun.web.security.RealmAdapter; 134 135 import java.util.HashSet ; 137 import javax.management.j2ee.statistics.Stats ; 138 import com.sun.enterprise.deployment.WebComponentDescriptor; 139 import com.sun.enterprise.admin.monitor.stats.ServletStats; 140 import com.sun.enterprise.web.stats.ServletStatsImpl; 141 import com.sun.enterprise.web.monitor.PwcServletStats; 142 import com.sun.enterprise.web.monitor.impl.PwcServletStatsImpl; 143 import com.sun.enterprise.admin.monitor.stats.WebModuleStats; 144 import com.sun.enterprise.web.stats.WebModuleStatsImpl; 145 import com.sun.enterprise.web.monitor.PwcWebModuleStats; 146 import com.sun.enterprise.web.monitor.impl.PwcWebModuleStatsImpl; 147 import com.sun.enterprise.admin.monitor.registry.MonitoringRegistry; 148 import com.sun.enterprise.admin.monitor.registry.MonitoringRegistrationException; 149 import com.sun.enterprise.admin.monitor.registry.MonitoringLevel; 150 import com.sun.enterprise.admin.monitor.registry.MonitoringLevelListener; 151 import com.sun.enterprise.admin.monitor.registry.MonitoredObjectType; 152 import com.sun.enterprise.config.serverbeans.MonitoringService; 153 import com.sun.enterprise.config.serverbeans.ModuleMonitoringLevels; 154 155 import com.sun.enterprise.admin.event.ApplicationDeployEvent; 158 import com.sun.enterprise.admin.event.ApplicationDeployEventListener; 159 import com.sun.enterprise.admin.event.ModuleDeployEvent; 160 import com.sun.enterprise.admin.event.ModuleDeployEventListener; 161 import com.sun.enterprise.admin.event.AdminEventListenerRegistry; 162 164 import com.sun.enterprise.config.serverbeans.Domain; 166 import com.sun.enterprise.config.serverbeans.Servers; 167 import com.sun.enterprise.config.serverbeans.ApplicationRef; 168 170 178 public class WebContainer 179 implements Lifecycle, 180 ApplicationDeployEventListener, 181 ModuleDeployEventListener, 182 MonitoringLevelListener { 183 184 186 public static final String DISABLED = "disabled"; 187 public static final String OFF = "off"; 188 public static final String ON = "on"; 189 public static final String STATE = "state"; 190 public static final String SSO_ENABLED="sso-enabled"; 191 public static final String SSO_MAX_IDLE="sso-max-inactive-seconds"; 192 public static final String SSO_REAP_INTERVAL="sso-reap-interval-seconds"; 193 public static final String ADMIN_VS = "__asadmin"; 194 public static final String DISPATCHER_MAX_DEPTH="dispatcher-max-depth"; 195 196 static final int DEFAULT_REAP_INTERVAL = 60; 198 public static final String JWS_APPCLIENT_EAR_NAME = "__JWSappclients"; 199 public static final String JWS_APPCLIENT_WAR_NAME = "sys"; 200 private static final String JWS_APPCLIENT_MODULE_NAME = JWS_APPCLIENT_EAR_NAME + ":" + JWS_APPCLIENT_WAR_NAME + ".war"; 201 202 private static final String DOC_BUILDER_FACTORY_PROPERTY = 203 "javax.xml.parsers.DocumentBuilderFactory"; 204 private static final String DOC_BUILDER_FACTORY_IMPL = 205 "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"; 206 207 209 212 protected EmbeddedWebContainer _embedded = null; 213 214 218 219 222 protected ServerContext _serverContext = null; 223 224 227 protected ConfigContext _configContext = null; 228 229 protected Domain domain = null; 230 protected InstanceEnvironment instance = null; 231 protected WebModulesManager webModulesManager = null; 232 protected AppsManager appsManager = null; 233 234 237 private Server _serverBean = null; 238 239 242 private String _id = null; 243 244 247 protected static Logger _logger = null; 248 249 252 protected static ResourceBundle _rb = null; 253 254 257 protected static MonitoringLevel monitoringLevel; 258 259 262 protected Level _logLevel = null; 263 264 270 protected int _debug = 0; 271 272 276 private String _modulesWorkRoot = null; 277 278 282 private String modulesStubRoot = null; 283 285 289 protected String _modulesRoot = null; 290 291 294 private String _appsWorkRoot = null; 295 296 300 private String appsStubRoot = null; 301 303 307 private boolean _reloadingEnabled = false; 308 309 316 private int _pollInterval = 2; 317 318 322 private StandaloneWebModulesManager _reloadManager = null; 323 324 327 private LifecycleSupport _lifecycle = new LifecycleSupport(this); 328 329 332 protected boolean _started = false; 333 334 337 private WebSecurityManagerFactory webSecurityManagerFactory 338 = WebSecurityManagerFactory.getInstance(); 339 340 private EjbWebServiceRegistryListener ejbWebServiceRegistryListener; 341 342 343 private static final String DOL_DEPLOYMENT = 344 "com.sun.enterprise.web.deployment.backend"; 345 346 349 protected static boolean useDOLforDeployment = true; 350 351 356 private String instanceClassPath; 357 358 359 static{ 360 if (System.getProperty(DOL_DEPLOYMENT) != null){ 361 useDOLforDeployment = Boolean.valueOf( 362 System.getProperty(DOL_DEPLOYMENT)).booleanValue(); 363 } 364 } 365 366 369 protected static WebContainer webContainer; 370 372 376 protected WebContainer(String id, ServerContext context) { 377 378 _id = id; 379 _serverContext = context; 380 381 _configContext = _serverContext.getConfigContext(); 382 383 String rootDir = _serverContext.getInstallRoot(); 384 String name = _serverContext.getInstanceName(); 385 instance = new InstanceEnvironment(rootDir, name); 386 _modulesWorkRoot = instance.getWebModuleCompileJspPath(); 387 _appsWorkRoot = instance.getApplicationCompileJspPath(); 388 _modulesRoot = instance.getModuleRepositoryPath(); 389 390 instanceClassPath = getInstanceClassPath(instance); 391 392 ejbWebServiceRegistryListener = new EjbWebServiceRegistryListener(this); 393 394 modulesStubRoot = instance.getModuleStubPath(); 396 appsStubRoot = instance.getApplicationStubPath(); 397 399 if (_logger == null) { 402 _logger = LogDomains.getLogger(LogDomains.WEB_LOGGER); 403 _rb = _logger.getResourceBundle(); 404 } 405 406 try { 407 webModulesManager = new WebModulesManager(instance); 408 appsManager = new AppsManager(instance); 409 } catch (ConfigException cx) { 410 _logger.log(Level.WARNING, 411 "Error in creating web modules manager: ", cx); 412 } 413 414 setNoTldScan(); 415 416 LogService logService = null; 417 418 try { 419 domain = (Domain) _configContext.getRootConfigBean(); 420 421 _serverBean = ServerBeansFactory.getServerBean(_configContext); 422 423 getDynamicReloadingSettings(ServerBeansFactory.getDasConfigBean(_configContext)); 424 425 Config cfg = ServerBeansFactory.getConfigBean(_configContext); 426 logService = cfg.getLogService(); 427 initLogLevel(logService); 428 initMonitoringLevel(cfg.getMonitoringService()); 429 430 ElementProperty maxDepth 431 = ServerBeansFactory.getWebContainerBean(_configContext).getElementPropertyByName(DISPATCHER_MAX_DEPTH); 432 if (maxDepth != null && maxDepth.getValue() != null) { 433 434 int depth = -1; 435 try { 436 depth = Integer.parseInt(maxDepth.getValue()); 437 } catch (Exception e) {} 438 439 if (depth > 0) { 440 CoyoteRequest.setMaxDispatchDepth(depth); 441 if (_logger.isLoggable(Level.FINE)) { 442 _logger.fine("Maximum depth for nested request " 443 + "dispatches set to " 444 + maxDepth.getValue()); 445 } 446 } 447 } 448 449 } catch (ConfigException e) { 450 _logger.log(Level.SEVERE, "webcontainer.configError", e); 451 } 452 453 String logServiceFile = null; 454 if (logService != null) { 455 logServiceFile = logService.getFile(); 456 } 457 _embedded = new EmbeddedWebContainer(_logger, _serverContext, this, 458 logServiceFile); 459 _embedded.setUseNaming(false); 460 if (_debug > 1) 461 _embedded.setDebug(_debug); 462 _embedded.setLogger(new IASLogger(_logger)); 463 464 DigesterFactory.setSchemaResourcePrefix("/schemas/"); 465 DigesterFactory.setDtdResourcePrefix("/dtds/"); 466 ParserUtils.setSchemaResourcePrefix("/schemas/"); 467 ParserUtils.setDtdResourcePrefix("/dtds/"); 468 469 477 String serverInfo = System.getProperty("product.name"); 478 if (serverInfo != null) { 479 ServerInfo.setServerInfo(serverInfo); 480 } else { 481 ServerInfo.setServerInfo(Version.getVersion()); 482 } 483 484 WebDebugMonitor debugMonitor = new WebDebugMonitor(); 487 HashMap monitorMap = debugMonitor.getDebugMonitoringDetails(); 488 debugMonitoring = ((Boolean ) monitorMap.get("debugMonitoring")).booleanValue(); 489 debugMonitoringPeriodMS = ((Long ) monitorMap.get( 490 "debugMonitoringPeriodMS")).longValue(); 491 492 if (debugMonitoring) { 493 _timer.schedule(new DebugMonitor(_embedded), 0L, 494 debugMonitoringPeriodMS); 495 } 496 } 499 500 private static boolean debugMonitoring=false; 503 private static long debugMonitoringPeriodMS = 30000L; 504 private static WebContainerTimer _timer = new WebContainerTimer(); 505 508 509 511 514 public String getID() { 515 return _id; 516 } 517 518 520 private HealthChecker _healthChecker = null; 521 public HealthChecker getHealthChecker() { 522 return _healthChecker; 523 } 524 525 private void initHealthChecker() { 526 WebContainerFeatureFactory webContainerFeatureFactory = 528 _serverContext.getPluggableFeatureFactory().getWebContainerFeatureFactory(); 529 HealthChecker healthChecker = 530 webContainerFeatureFactory.getHADBHealthChecker(this); 531 if(_logger.isLoggable(Level.FINEST)) { 532 _logger.finest("WebContainer>>initHealthChecker - healthChecker = " + healthChecker); 533 } 534 if(healthChecker != null) { 535 _healthChecker = healthChecker; 536 try { 537 _healthChecker.start(); 538 } catch (LifecycleException ex) {} 539 } 540 } 541 542 private void stopHealthChecker() { 543 if(_healthChecker != null) { 544 try { 545 _healthChecker.stop(); 546 } catch (LifecycleException ex) {} 547 _healthChecker = null; 548 } 549 } 550 551 553 554 556 private WebContainerAdminEventProcessor _adminEventProcessor = null; 557 558 public void registerAdminEvents() { 560 561 AdminEventListenerRegistry.addApplicationDeployEventListener(this); 562 AdminEventListenerRegistry.addModuleDeployEventListener(this); 563 WebContainerFeatureFactory webContainerFeatureFactory = 564 _serverContext.getPluggableFeatureFactory().getWebContainerFeatureFactory(); 565 _adminEventProcessor = 566 webContainerFeatureFactory.getWebContainerAdminEventProcessor(); 567 _adminEventProcessor.init(_embedded); 568 } 569 570 public void unregisterAdminEvents() { 571 AdminEventListenerRegistry.removeEventListener(this); 572 _adminEventProcessor = null; 573 } 574 575 public void applicationDeployed(ApplicationDeployEvent deployEvent) { 576 _adminEventProcessor.applicationDeployed(deployEvent); 577 } 578 579 public void applicationUndeployed(ApplicationDeployEvent deployEvent) { 580 _adminEventProcessor.applicationUndeployed(deployEvent); 581 } 582 583 public void applicationRedeployed(ApplicationDeployEvent deployEvent) { 584 _adminEventProcessor.applicationRedeployed(deployEvent); 585 } 586 587 public void applicationEnabled(ApplicationDeployEvent deployEvent) { 588 } 589 590 public void applicationDisabled(ApplicationDeployEvent deployEvent) { 591 } 592 593 public void moduleDeployed(ModuleDeployEvent deployEvent) { 594 _adminEventProcessor.moduleDeployed(deployEvent); 595 } 596 597 public void moduleUndeployed(ModuleDeployEvent deployEvent) { 598 _adminEventProcessor.moduleUndeployed(deployEvent); 599 } 600 601 public void moduleRedeployed(ModuleDeployEvent deployEvent) { 602 _adminEventProcessor.moduleRedeployed(deployEvent); 603 } 604 605 public void moduleEnabled(ModuleDeployEvent deployEvent) { 606 } 607 608 public void moduleDisabled(ModuleDeployEvent deployEvent) { 609 } 610 612 613 615 public void registerMonitoringLevelEvents() { 616 MonitoringRegistry monitoringRegistry = 617 _serverContext.getMonitoringRegistry(); 618 monitoringRegistry.registerMonitoringLevelListener( 619 this, MonitoredObjectType.SERVLET); 620 } 621 622 public void unregisterMonitoringLevelEvents() { 623 MonitoringRegistry monitoringRegistry = 624 _serverContext.getMonitoringRegistry(); 625 monitoringRegistry.unregisterMonitoringLevelListener(this); 626 } 627 628 public void setLevel(MonitoringLevel level) { 629 } 631 632 public void changeLevel(MonitoringLevel from, MonitoringLevel to, 633 Stats handback) { 634 } 636 637 public void changeLevel(MonitoringLevel from, MonitoringLevel to, 638 MonitoredObjectType type) { 639 if (MonitoredObjectType.SERVLET.equals(type)) { 640 monitoringLevel = to; 641 if(MonitoringLevel.OFF.equals(to)) { 642 this.resetMonitorStatistics(); 643 } 644 } 645 } 646 647 652 public static MonitoringLevel getMonitoringLevel() { 653 return monitoringLevel; 654 } 655 656 661 public static boolean isMonitoringEnabled() { 662 return (!MonitoringLevel.OFF.equals(monitoringLevel)); 663 } 664 665 private void resetMonitorStatistics() { 666 MonitorUtil.resetMonitorStats(_embedded, _serverContext); 667 } 668 669 670 672 675 public VirtualServer createVS(String vsID, 676 com.sun.enterprise.config.serverbeans.VirtualServer vsBean, 677 String docroot, 678 String logFile, 679 MimeMap mimeMap, 680 HttpProtocol httpProtocol) { 681 682 VirtualServer vs = (VirtualServer) _embedded.createHost(vsID, 684 vsBean, 685 docroot, 686 logFile, 687 mimeMap); 688 689 configureVirtualServerState(vs, vsBean); 690 configureRemoteAddressFilterValve(vs, vsBean); 691 configureRemoteHostFilterValve(vs, vsBean, httpProtocol); 692 configureSSOValve(vs, vsBean); 693 configureRedirect(vs, vsBean); 694 configureErrorPage(vs, vsBean); 695 696 return vs; 697 } 698 699 701 702 707 public void addLifecycleListener(LifecycleListener listener) { 708 _lifecycle.addLifecycleListener(listener); 709 } 710 711 712 717 public void removeLifecycleListener(LifecycleListener listener) { 718 _lifecycle.removeLifecycleListener(listener); 719 } 720 721 private void doSchemaCheck() { 722 SchemaUpdater schemaUpdater = 723 _serverContext.getPluggableFeatureFactory().getSchemaUpdater(); 724 try { 725 schemaUpdater.doSchemaCheck(); 726 } catch (Exception ex) { 727 _logger.log(Level.SEVERE, "schemaupdater.error", ex); 728 } 729 } 730 731 741 public void start() throws LifecycleException { 742 if (_started) { 743 String msg = _rb.getString("webcontainer.alreadyStarted"); 744 throw new LifecycleException(msg); 745 } 746 747 if (System.getProperty(DOC_BUILDER_FACTORY_PROPERTY) == null) { 748 System.setProperty(DOC_BUILDER_FACTORY_PROPERTY, 749 DOC_BUILDER_FACTORY_IMPL); 750 } 751 752 registerAdminEvents(); 754 registerMonitoringLevelEvents(); 755 initHealthChecker(); 756 long btime = 0L; 757 if (_logger.isLoggable(Level.FINE)) { 758 _logger.fine("before schema check"); 759 btime = System.currentTimeMillis(); 760 } 761 doSchemaCheck(); 762 if (_logger.isLoggable(Level.FINE)) { 763 _logger.fine("after schema check time: " + (System.currentTimeMillis() - btime)); 764 } 765 767 ejbWebServiceRegistryListener.register(); 768 769 Engine[] engines = _embedded.getEngines(); 770 771 for (int j=0; j<engines.length; j++) { 772 Container[] vsList = engines[j].findChildren(); 773 for (int i = 0; i < vsList.length; i++) { 774 loadWebModules((VirtualServer)vsList[i]); 776 } 777 } 778 779 loadAllJ2EEApplicationWebModules(true); 781 782 loadSystemDefaultWebModules(); 790 791 _lifecycle.fireLifecycleEvent(START_EVENT, null); 792 _started = true; 793 _embedded.start(); 795 796 if (_reloadingEnabled) { 797 800 Applications appsBean = null; 801 try { 802 appsBean = ServerBeansFactory.getApplicationsBean(_configContext); 803 } catch (ConfigException e) { 804 String msg = _rb.getString("webcontainer.appsConfigError"); 805 _logger.log(Level.SEVERE, msg, e); 806 } 807 808 _reloadManager = new StandaloneWebModulesManager(_id, 809 _modulesRoot, 810 _pollInterval); 811 if (appsBean != null) { 812 com.sun.enterprise.config.serverbeans.WebModule[] wmBeans = appsBean.getWebModule(); 813 if (wmBeans != null && wmBeans.length > 0) { 814 _reloadManager.addWebModules(wmBeans); 815 } 816 } 817 } 818 enableAllWSEndpoints(); 819 } 820 821 830 public void stop() throws LifecycleException { 831 if (!_started) { 833 String msg = _rb.getString("webcontainer.notStarted"); 834 throw new LifecycleException(msg); 835 } 836 837 ejbWebServiceRegistryListener.unregister(); 838 839 unregisterAdminEvents(); 841 unregisterMonitoringLevelEvents(); 842 stopHealthChecker(); 843 844 WebContainerStartStopOperation startStopOperation = 845 this.getWebContainerStartStopOperation(); 846 854 ArrayList shutdownCleanupCapablesList = startStopOperation.doPreStop(); 855 857 _started = false; 858 859 try{ 861 _embedded.stop(); 862 } catch (LifecycleException ex){ 863 if (ex.getMessage().indexOf("has not been started") == -1){ 864 throw ex; 865 } 866 } 867 868 if (_reloadManager != null) { 869 _reloadManager.stop(); 872 _reloadManager = null; 873 } 874 875 startStopOperation.doPostStop(shutdownCleanupCapablesList); 877 } 879 880 884 public WebContainerStartStopOperation getWebContainerStartStopOperation() { 885 886 WebContainerFeatureFactory webContainerFeatureFactory = 888 _serverContext.getPluggableFeatureFactory().getWebContainerFeatureFactory(); 889 WebContainerStartStopOperation startStopOperation = 890 webContainerFeatureFactory.getWebContainerStartStopOperation(); 891 892 startStopOperation.init(_embedded); 893 return startStopOperation; 894 } 895 896 898 902 protected void loadWebModules(VirtualServer vs) { 903 WebModuleConfig wmInfo = null; 904 905 loadDefaultWebModule(vs,_serverBean); 906 907 List modules = vs.getWebModules(_serverBean, _modulesRoot); 909 if ((modules != null) && (modules.size() > 0)) { 910 ListIterator iterator = modules.listIterator(); 911 while (iterator.hasNext()) { 912 wmInfo = (WebModuleConfig) iterator.next(); 913 com.sun.enterprise.config.serverbeans.WebModule webBean = 914 wmInfo.getBean(); 915 if (webBean != null && 917 isEnabled(webBean.getConfigContext(), webBean.getName())) { 918 loadStandaloneWebModule(vs, wmInfo); 919 } 920 } 921 } 922 } 923 924 925 931 public void loadDefaultWebModule(VirtualServer vs, 932 Server serverBean){ 933 WebModuleConfig wmInfo = vs.getUserDefaultWebModuleConfig(serverBean); 934 if (wmInfo != null) { 935 loadStandaloneWebModule(vs, wmInfo); 940 } 941 } 942 943 944 948 protected void loadSystemDefaultWebModules() { 949 950 Engine[] engines = _embedded.getEngines(); 951 952 for (int j=0; j<engines.length; j++) { 953 Container[] vsArray = engines[j].findChildren(); 954 for (int i = 0; i < vsArray.length; i++) { 955 if (vsArray[i] instanceof VirtualServer) { 956 VirtualServer vs = (VirtualServer) vsArray[i]; 957 WebModuleConfig wmInfo = 958 vs.createSystemDefaultWebModuleIfNecessary(); 959 if (wmInfo != null) { 960 loadStandaloneWebModule(vs, wmInfo); 961 } 962 } 963 } 964 } 965 } 966 967 971 protected void loadStandaloneWebModule(VirtualServer vs, 972 WebModuleConfig wmInfo) { 973 loadWebModule(vs, wmInfo, "null"); 974 } 975 976 980 protected void loadAllJ2EEApplicationWebModules() { 981 loadAllJ2EEApplicationWebModules(false); 982 } 983 984 990 private void loadAllJ2EEApplicationWebModules(boolean isStartUp) { 991 992 Applications appsBean = null; 993 try { 994 appsBean = ServerBeansFactory.getApplicationsBean(_configContext); 995 } catch (ConfigException e) { 996 String msg = _rb.getString("webcontainer.appsConfigError"); 997 _logger.log(Level.SEVERE, msg, e); 998 } 999 1000 if (appsBean != null) { 1001 J2eeApplication[] j2eeAppBeans = appsBean.getJ2eeApplication(); 1002 if (j2eeAppBeans != null) { 1003 for (int i = 0; i < j2eeAppBeans.length; i++) { 1004 if ( isReferenced(j2eeAppBeans[i].getName()) ) { 1006 loadJ2EEApplicationWebModules(j2eeAppBeans[i]); 1007 } 1008 } 1010 } 1011 } 1012 } 1013 1014 1018 public void loadJ2EEApplicationWebModules(J2eeApplication j2eeAppBean) { 1019 if ((j2eeAppBean != null) && 1020 isEnabled(j2eeAppBean.getConfigContext(), j2eeAppBean.getName())) { 1021 String id = j2eeAppBean.getName(); 1022 String location = j2eeAppBean.getLocation(); 1023 String resourceType = j2eeAppBean.getObjectType(); 1024 1025 ApplicationRegistry registry = ApplicationRegistry.getInstance(); 1026 ClassLoader appLoader = registry.getClassLoaderForApplication(id); 1027 if (appLoader != null) { 1028 Application appDesc = registry.getApplication(appLoader); 1029 1030 if(appDesc == null){ 1032 Object [] params = { id }; 1033 _logger.log(Level.SEVERE, "webcontainer.notLoaded", 1034 params); 1035 } else { 1036 ConfigContext eventConfigContext = j2eeAppBean.getConfigContext(); 1038 String j2eeApplication = appDesc.getRegistrationName(); 1040 Set wbds = appDesc.getWebBundleDescriptors(); 1041 WebBundleDescriptor wbd = null; 1042 com.sun.enterprise.config.serverbeans.WebModule wm = null; 1043 WebModuleConfig wmInfo = null; 1044 for (Iterator itr = wbds.iterator(); itr.hasNext(); ) { 1045 StringBuffer dir = new StringBuffer (location); 1046 wbd = (WebBundleDescriptor) itr.next(); 1047 String moduleName = wbd.getModuleDescriptor().getArchiveUri(); 1048 dir.append(File.separator); 1049 dir.append(FileUtils.makeFriendlyFilename(moduleName)); 1050 1051 wm = new com.sun.enterprise.config.serverbeans.WebModule(); 1052 wm.setConfigContext(eventConfigContext); 1054 wm.setName(moduleName); 1056 wm.setContextRoot(wbd.getContextRoot()); 1057 wm.setLocation(dir.toString()); 1058 wm.setEnabled(true); 1059 wm.setObjectType(resourceType); 1060 1061 wmInfo = new WebModuleConfig(); 1062 wmInfo.setBean(wm); 1063 wmInfo.setDescriptor(wbd); 1064 wmInfo.setParentLoader(appLoader); 1065 wmInfo.setVirtualServers( 1066 getVirtualServers(id, 1067 j2eeAppBean.getConfigContext())); 1068 loadWebModule(wmInfo, j2eeApplication); 1069 } 1070 } } 1072 } 1073 } 1074 1075 1084 protected boolean isEnabled (ConfigContext config, String moduleName) { 1085 try { 1086 if (config == null) { 1087 config = _configContext; 1088 } 1089 1090 ConfigBean app = ApplicationHelper.findApplication(config, 1091 moduleName); 1092 Server server = ServerBeansFactory.getServerBean(config); 1093 ApplicationRef appRef = server.getApplicationRefByRef(moduleName); 1094 1095 return ((app != null && app.isEnabled()) && 1096 (appRef != null && appRef.isEnabled())); 1097 } catch (ConfigException e) { 1098 _logger.log(Level.WARNING, "Error finding " + moduleName, e); 1099 1100 return false; 1102 } 1103 } 1104 1105 1112 public List <Throwable > loadWebModule( 1113 WebModuleConfig wmInfo, String j2eeApplication) { 1114 1115 String vsIDs = wmInfo.getVirtualServers(); 1116 List vsList = StringUtils.parseStringList(vsIDs, " ,"); 1117 boolean loadToAll = (vsList == null) || (vsList.size() == 0); 1118 boolean loadAtLeastToOne = false; 1119 1120 Engine[] engines = _embedded.getEngines(); 1121 1122 List <Throwable > throwables = new ArrayList (); 1123 for (int j=0; j<engines.length; j++) { 1124 Container[] vsArray = engines[j].findChildren(); 1125 for (int i = 0; i < vsArray.length; i++) { 1126 if (vsArray[i] instanceof VirtualServer) { 1127 VirtualServer vs = (VirtualServer) vsArray[i]; 1128 1129 1135 if (vs.getID().equals(ADMIN_VS) && loadToAll) { 1136 continue; 1137 } 1138 1139 if ( loadToAll 1140 || vsList.contains(vs.getID()) 1141 || verifyAlias(vsList,vs)){ 1142 1143 Throwable t = loadWebModule(vs, wmInfo, j2eeApplication); 1144 if (t != null) { 1145 throwables.add(t); 1146 } 1147 loadAtLeastToOne = true; 1148 } 1149 } 1150 } 1151 } 1152 if (!loadAtLeastToOne) { 1153 Object [] params = {wmInfo.getName(), vsIDs}; 1154 _logger.log(Level.SEVERE, "webcontainer.moduleNotLoadedToVS", 1155 params); 1156 } 1157 return throwables; 1158 } 1159 1160 1161 1164 private boolean verifyAlias(List vsList,VirtualServer vs){ 1165 for(int i=0; i < vs.getAliases().length; i++){ 1166 if (vsList.contains(vs.getAliases()[i]) ){ 1167 return true; 1168 } 1169 } 1170 return false; 1171 } 1172 1173 1177 protected Throwable loadWebModule(VirtualServer vs, WebModuleConfig wmInfo, 1178 String j2eeApplication) { 1179 String wmName = wmInfo.getName(); 1180 if (wmName.indexOf(Constants.NAME_SEPARATOR) != -1) { 1181 wmInfo.setWorkDirBase(_appsWorkRoot); 1182 wmInfo.setStubBaseDir(appsStubRoot); 1184 } else { 1186 wmInfo.setWorkDirBase(_modulesWorkRoot); 1187 wmInfo.setStubBaseDir(modulesStubRoot); 1189 } 1191 1192 String wmContextPath = wmInfo.getContextPath(); 1193 String displayContextPath = null; 1194 if (wmContextPath.equals("")) 1195 displayContextPath = "/"; 1196 else 1197 displayContextPath = wmContextPath; 1198 1199 HashMap adHocPaths = null; 1200 HashMap adHocSubtrees = null; 1201 WebModule ctx = (WebModule)vs.findChild(wmContextPath); 1202 if (ctx != null) { 1203 if (ctx instanceof AdHocWebModule) { 1204 1211 if (ctx.hasAdHocPaths()) { 1212 adHocPaths = ctx.getAdHocPaths(); 1213 } 1214 if (ctx.hasAdHocSubtrees()) { 1215 adHocSubtrees = ctx.getAdHocSubtrees(); 1216 } 1217 vs.removeChild(ctx); 1218 } else if (Constants.DEFAULT_WEB_MODULE_NAME 1219 .equals(ctx.getModuleName())) { 1220 1227 unloadWebModule(wmContextPath, 1228 ctx.getJ2EEApplication(), 1229 vs.getName(), 1230 null, 1231 true); 1232 } else if (!ctx.getAvailable()){ 1233 1238 ctx.setAvailable(true); 1239 return null; 1240 } else { 1241 Object [] params = { vs.getID(), displayContextPath, wmName }; 1242 _logger.log(Level.WARNING, "webcontainer.duplicateContextRoot", 1243 params); 1244 return null; 1245 } 1246 } 1247 1248 Object [] params = { wmName, vs.getID(), displayContextPath }; 1249 if (wmName.equals(Constants.DEFAULT_WEB_MODULE_NAME)) 1250 _logger.log(Level.FINE, "webcontainer.loadModule", params); 1251 else 1252 _logger.log(Level.INFO, "webcontainer.loadModule", params); 1253 1254 String docBase = null; 1255 if (JWS_APPCLIENT_MODULE_NAME.equals(wmName)) { 1256 File installRootFile = new File (System.getProperty("com.sun.aas.installRoot")); 1257 String path = installRootFile.toURI().getPath(); 1258 if (OS.isWindows()) { 1259 path = path.substring(1); } 1261 docBase = path; 1262 } else { 1263 docBase = wmInfo.getLocation(); 1264 } 1265 ctx = (WebModule) _embedded.createContext(wmContextPath, 1266 docBase, 1267 vs.getDefaultWebXmlLocation(), 1268 useDOLforDeployment, 1269 wmInfo.getDescriptor()); 1270 1271 String engineName = vs.getParent().getName(); 1273 String j2eeServer = _serverContext.getInstanceName(); 1274 String domain = _serverContext.getDefaultDomainName(); 1275 String server = domain + ":j2eeType=J2EEServer,name=" + j2eeServer; 1276 String [] javaVMs = J2EEModuleUtil.getjavaVMs(); 1277 ctx.setDomain(domain); 1278 1279 ctx.setJ2EEServer(j2eeServer); 1280 ctx.setJ2EEApplication(j2eeApplication); 1281 ctx.setEngineName(engineName); 1282 ctx.setServer(server); 1283 ctx.setJavaVMs(javaVMs); 1284 ctx.setCachingAllowed(true); 1285 ctx.setCacheControls(vs.getCacheControls()); 1286 1287 if (adHocPaths != null) { 1288 ctx.addAdHocPaths(adHocPaths); 1289 } 1290 if (adHocSubtrees != null) { 1291 ctx.addAdHocSubtrees(adHocSubtrees); 1292 } 1293 1294 WebBundleDescriptor wbd = wmInfo.getDescriptor(); 1296 1297 if (wmInfo.getBean() != null) { 1299 String contextRoot = wmInfo.getBean().getContextRoot(); 1300 ctx.setContextRoot(contextRoot); 1301 if (wbd != null) { 1302 wbd.setContextRoot(contextRoot); 1303 } 1304 } else { 1305 _logger.log(Level.WARNING, "Unable to set context root", wmInfo); 1307 } 1308 1309 String wmInfoWorkDir = wmInfo.getWorkDir(); 1315 if (wmInfoWorkDir != null) { 1316 StringBuffer workDir = new StringBuffer (wmInfo.getWorkDir()); 1317 if (wmName.equals(Constants.DEFAULT_WEB_MODULE_NAME)) { 1318 workDir.append("-"); 1319 workDir.append(FileUtils.makeFriendlyFilename(vs.getID())); 1320 } 1321 ctx.setWorkDir(workDir.toString()); 1322 } 1323 1324 ClassLoader parentLoader = wmInfo.getParentLoader(); 1325 if (parentLoader == null) { 1326 parentLoader = _serverContext.getSharedClassLoader(); 1329 } 1330 ctx.setParentClassLoader(parentLoader); 1331 1332 Throwable exception = null; 1333 Switch sw = Switch.getSwitch(); 1334 try{ 1335 if (wbd != null) { 1338 String altDDName = wbd.getModuleDescriptor(). 1339 getAlternateDescriptor(); 1340 if (altDDName != null) { 1341 1344 String appName = wmName.substring(0, 1346 wmName.indexOf(Constants.NAME_SEPARATOR)); 1347 String appLoc = 1348 appsManager.getGeneratedXMLLocation(appName); 1349 if (! FileUtils.safeIsDirectory(appLoc)) { 1350 appLoc = wmInfo.getLocation()+"/.."; 1351 } 1352 1353 if (altDDName.startsWith("/")) { 1354 altDDName = appLoc+altDDName.trim(); 1355 } 1356 else { 1357 altDDName = appLoc+"/"+altDDName.trim(); 1358 } 1359 Object [] objs = {altDDName, wmName}; 1360 _logger.log(Level.INFO, "webcontainer.altDDName", objs); 1361 ctx.setAltDDName(altDDName); 1362 1363 } 1364 if (wbd.hasWebServices()) { 1369 ctx.setHasWebServices(true); 1370 1371 String [] endpointAddresses; 1373 WebServicesDescriptor webService = wbd.getWebServices(); 1374 Vector endpointList = new Vector (); 1375 for (Iterator endpoints = webService.getEndpoints().iterator(); 1376 endpoints.hasNext();) { 1377 WebServiceEndpoint wse = (WebServiceEndpoint) endpoints.next(); 1378 if (wbd.getContextRoot()!=null) { 1379 endpointList.add(wbd.getContextRoot() + "/" 1380 + wse.getEndpointAddressUri()); 1381 } else { 1382 endpointList.add(wse.getEndpointAddressUri()); 1383 } 1384 } 1385 endpointAddresses = new String [endpointList.size()]; 1386 endpointList.copyInto(endpointAddresses); 1387 1388 ctx.setEndpointAddresses(endpointAddresses); 1389 1390 } else { 1391 ctx.setHasWebServices(false); 1392 } 1393 } 1394 1395 SunWebApp iasBean = null; 1397 1398 if (wbd != null) 1400 iasBean = wbd.getSunDescriptor(); 1401 1402 ctx.setIasWebAppConfigBean(iasBean); 1404 ctx.setID(wmName); 1405 1406 Loader loader = configureLoader(ctx, iasBean, wmInfo); 1408 1409 if (wbd != null && wbd.hasWebServices()) 1411 wbd.addExtraAttribute("WEBLOADER", loader); 1412 1413 if (_reloadingEnabled) { 1415 if (_reloadManager == null) { 1416 _reloadManager = new StandaloneWebModulesManager( 1417 _id, 1418 _modulesRoot, 1419 _pollInterval); 1420 } 1421 _reloadManager.addWebModule(wmInfo.getBean()); 1422 } 1423 1424 configureMiscSettings(ctx, iasBean, vs, displayContextPath); 1426 1427 configureSessionSettings(ctx, iasBean, wbd, wmInfo); 1432 1434 ctx.setI18nInfo(); 1436 1437 if (wbd != null) { 1438 String resourceType = wmInfo.getBean().getObjectType(); 1439 boolean isSystem = (resourceType != null && 1440 resourceType.startsWith("system-")); 1441 ctx.setRealm(new RealmAdapter(wbd, isSystem)); 1442 configureSecurity(wbd, isSystem); 1443 sw.setDescriptorFor(ctx, wbd); 1444 1445 if (wbd.getApplication() != null && 1447 wbd.getApplication().isVirtual()) { 1448 wbd.visit((WebBundleVisitor) new WebValidatorWithoutCL()); 1449 } 1450 1451 sw.getNamingManager().bindObjects(wbd); 1452 } 1453 1454 addMimeMappings(ctx, vs.getMimeMap()); 1456 1457 } catch (Throwable ex){ 1458 exception = ex; 1459 } 1460 1461 if (wbd != null && wbd.getApplication() != null) { 1462 sw.setDescriptorFor(ctx, wbd); 1464 String moduleName; 1465 if (wbd.getApplication().isVirtual()) { 1467 moduleName = wbd.getApplication().getRegistrationName(); 1469 } else { 1470 moduleName = wbd.getModuleDescriptor().getArchiveUri(); 1471 } 1472 ctx.setModuleName(moduleName); 1474 } else { 1475 ctx.setModuleName(Constants.DEFAULT_WEB_MODULE_NAME); 1476 } 1477 1478 try { 1479 vs.addChild(ctx); 1480 } catch (Throwable ex){ 1481 exception = ex; 1482 } 1483 1484 if (exception != null){ 1485 ctx.setAvailable(false); 1486 1487 Object [] objs = {wmName, exception}; 1488 _logger.log(Level.SEVERE, "webcontainer.webModuleDisabled", objs); 1489 1490 } 1491 enableWSMonitoring(wbd, j2eeServer); 1492 return exception; 1493 } 1494 1495 1496 1503 protected void configureSecurity(WebBundleDescriptor wbd, 1504 boolean isSystem) { 1505 try{ 1506 webSecurityManagerFactory.newWebSecurityManager(wbd); 1507 String context = WebSecurityManager.getContextID(wbd); 1508 SecurityUtil.generatePolicyFile(context); 1509 }catch(Exception ce){ 1510 _logger.log(Level.SEVERE, "webcontainer.configureSecurity", ce); 1511 throw new RuntimeException (ce); 1512 } 1513 } 1514 1515 1518 public ServerContext getServerContext() { 1519 return _serverContext; 1520 } 1521 1522 1526 private Loader configureLoader(WebModule ctx, SunWebApp bean, 1527 WebModuleConfig wmInfo) { 1528 1529 com.sun.enterprise.deployment.runtime.web.ClassLoader clBean = null; 1530 1531 Loader loader = _embedded.createLoader(ctx.getParentClassLoader()); 1532 1533 if (bean != null) { 1534 clBean = bean.getClassLoader(); 1535 } 1536 if (clBean != null) { 1537 configureLoaderAttributes(loader, clBean, ctx); 1538 configureLoaderProperties(loader, clBean); 1539 } else { 1540 loader.setDelegate(true); 1541 } 1542 1543 String stubPath = wmInfo.getStubPath(); 1545 if (stubPath != null) { 1546 loader.addRepository("file:" + stubPath + File.separator); 1547 } 1548 1550 addLibs(loader, ctx); 1551 1552 1558 String packagesName = 1559 System.getProperty("com.sun.enterprise.overrideablejavaxpackages"); 1560 1561 if (packagesName != null) { 1562 List overridablePackages = 1563 StringUtils.parseStringList(packagesName, " ,"); 1564 for( int i=0; i < overridablePackages.size(); i++){ 1565 loader.addOverridablePackage((String )overridablePackages.get(i)); 1566 } 1567 } 1568 1570 ctx.setLoader(loader); 1571 return loader; 1572 } 1573 1574 1583 private void configureMiscSettings(WebModule ctx, SunWebApp bean, 1584 VirtualServer vs, String contextPath) { 1585 1586 1591 boolean allowLinking = vs.getAllowLinking(); 1592 1593 if ((bean != null) && (bean.sizeWebProperty() > 0)) { 1594 WebProperty[] props = bean.getWebProperty(); 1595 for (int i = 0; i < props.length; i++) { 1596 1597 String name = props[i].getAttributeValue("name"); 1598 String value = props[i].getAttributeValue("value"); 1599 if (name == null || value == null) { 1600 throw new IllegalArgumentException ( 1601 _rb.getString("webcontainer.nullWebProperty")); 1602 } 1603 1604 if (name.equalsIgnoreCase("singleThreadedServletPoolSize")) { 1605 int poolSize = ctx.getSTMPoolSize(); 1606 try { 1607 poolSize = Integer.parseInt(value); 1608 } catch (NumberFormatException e) { 1609 Object [] params = 1610 { value, contextPath, Integer.toString(poolSize) }; 1611 _logger.log(Level.WARNING, 1612 "webcontainer.invalidServletPoolSize", 1613 params); 1614 } 1615 if (poolSize > 0) { 1616 ctx.setSTMPoolSize(poolSize); 1617 } 1618 1619 } else if (name.equalsIgnoreCase("tempdir")) { 1620 ctx.setWorkDir(value); 1621 } else if (name.equalsIgnoreCase("crossContextAllowed")) { 1622 boolean crossContext = ConfigBean.toBoolean(value); 1623 ctx.setCrossContext(crossContext); 1624 } else if (name.equalsIgnoreCase("allowLinking")) { 1625 allowLinking = ConfigBean.toBoolean(value); 1626 } else if (name.equalsIgnoreCase("reuseSessionID")) { 1628 boolean reuse = ConfigBean.toBoolean(value); 1629 ctx.setReuseSessionID(reuse); 1630 if (reuse) { 1631 Object [] params = { contextPath, 1632 vs.getID() }; 1633 _logger.log(Level.WARNING, 1634 "webcontainer.sessionIDsReused", 1635 params); 1636 } 1637 } else if(name.equalsIgnoreCase("useResponseCTForHeaders")) { 1639 if(value.equalsIgnoreCase("true")) { 1640 ctx.setResponseCTForHeaders(); 1641 } 1642 } else if(name.equalsIgnoreCase("encodeCookies")) { 1643 boolean flag = ConfigBean.toBoolean(value); 1644 ctx.setEncodeCookies(flag); 1645 } else if (name.equalsIgnoreCase("relativeRedirectAllowed")) { 1647 boolean relativeRedirect = ConfigBean.toBoolean(value); 1648 ctx.setAllowRelativeRedirect(relativeRedirect); 1649 } else if (name.equalsIgnoreCase("fileEncoding")) { 1651 ctx.setFileEncoding(value); 1652 } else if (name.equalsIgnoreCase("enableTldValidation") 1653 && ConfigBean.toBoolean(value)) { 1654 ctx.setTldValidation(true); 1655 } else if (name.equalsIgnoreCase("enableTldNamespaceAware") 1656 && ConfigBean.toBoolean(value)) { 1657 ctx.setTldNamespaceAware(true); 1658 } else { 1659 Object [] params = { name, value }; 1660 _logger.log(Level.WARNING, "webcontainer.invalidProperty", 1661 params); 1662 } 1663 } 1664 } 1665 1666 ctx.setAllowLinking(allowLinking); 1667 } 1668 1669 1678 private void configureSessionSettings(WebModule ctx, 1679 SunWebApp bean, 1680 WebBundleDescriptor wbd, 1681 WebModuleConfig wmInfo) { 1682 1683 SessionConfig cfg = null; 1684 SessionManager smBean = null; 1685 SessionProperties sessionBean = null; 1686 CookieProperties cookieBean = null; 1687 1688 if (bean != null) 1689 cfg = bean.getSessionConfig(); 1690 1691 if (cfg != null) 1692 smBean = cfg.getSessionManager(); 1693 1694 if (cfg != null) 1695 sessionBean = cfg.getSessionProperties(); 1696 1697 if (cfg != null) 1698 cookieBean = cfg.getCookieProperties(); 1699 1700 configureSessionManager(ctx, smBean, wbd, wmInfo); 1702 configureSession(ctx, sessionBean, wbd); 1704 configureCookieProperties(ctx, cookieBean); 1706 } 1707 1708 1712 public String getApplicationId(WebModule wm) { 1713 return wm.getID(); 1714 } 1715 1716 1717 1721 public String getModulesRoot() { 1722 return _modulesRoot; 1723 } 1724 1725 1726 1733 private void configureSessionManager(WebModule ctx, 1734 SessionManager smBean, 1735 WebBundleDescriptor wbd, 1736 WebModuleConfig wmInfo) { 1737 1738 PersistenceType persistence = PersistenceType.MEMORY; 1739 String frequency = null; 1740 String scope = null; 1741 1742 SessionManagerConfigurationHelper configHelper = 1743 new SessionManagerConfigurationHelper(ctx, smBean, wbd, wmInfo); 1744 1745 persistence = configHelper.getPersistenceType(); 1746 frequency = configHelper.getPersistenceFrequency(); 1747 scope = configHelper.getPersistenceScope(); 1748 1749 if (_logger.isLoggable(Level.FINEST)) { 1750 _logger.finest("IN WebContainer>>ConfigureSessionManager before builder factory"); 1751 _logger.finest("FINAL_PERSISTENCE-TYPE IS = " 1752 + persistence.getType()); 1753 _logger.finest("FINAL_PERSISTENCE_FREQUENCY IS = " + frequency); 1754 _logger.finest("FINAL_PERSISTENCE_SCOPE IS = " + scope); 1755 } 1756 1757 PersistenceStrategyBuilderFactory factory = 1758 new PersistenceStrategyBuilderFactory(); 1759 PersistenceStrategyBuilder builder = 1760 factory.createPersistenceStrategyBuilder(persistence.getType(), 1761 frequency, scope, ctx); 1762 if (_logger.isLoggable(Level.FINEST)) { 1763 _logger.finest("PersistenceStrategyBuilder class = " 1764 + builder.getClass().getName()); 1765 } 1766 1767 builder.setLogger(_logger); 1768 builder.initializePersistenceStrategy(ctx, smBean); 1769 } 1770 1771 1772 1778 private String getPersistenceFrequency(SessionManager smBean) { 1779 String persistenceFrequency = null; 1780 ManagerProperties mgrBean = smBean.getManagerProperties(); 1781 if ((mgrBean != null) && (mgrBean.sizeWebProperty() > 0)) { 1782 WebProperty[] props = mgrBean.getWebProperty(); 1783 for (int i = 0; i < props.length; i++) { 1784 1785 String name = props[i].getAttributeValue(WebProperty.NAME); 1786 String value = props[i].getAttributeValue(WebProperty.VALUE); 1787 if (name == null || value == null) { 1788 throw new IllegalArgumentException ( 1789 _rb.getString("webcontainer.nullWebProperty")); 1790 } 1791 1792 if (name.equalsIgnoreCase("persistenceFrequency")) { 1793 persistenceFrequency = value; 1794 break; 1795 } 1796 } 1797 } 1798 return persistenceFrequency; 1799 } 1800 1801 1807 private String getPersistenceScope(SessionManager smBean) { 1808 String persistenceScope = null; 1809 StoreProperties storeBean = smBean.getStoreProperties(); 1810 if ((storeBean != null) && (storeBean.sizeWebProperty() > 0)) { 1811 WebProperty[] props = storeBean.getWebProperty(); 1812 for (int i = 0; i < props.length; i++) { 1813 1814 String name = props[i].getAttributeValue(WebProperty.NAME); 1815 String value = props[i].getAttributeValue(WebProperty.VALUE); 1816 if (name == null || value == null) { 1817 throw new IllegalArgumentException ( 1818 _rb.getString("webcontainer.nullWebProperty")); 1819 } 1820 1821 if (name.equalsIgnoreCase("persistenceScope")) { 1822 persistenceScope = value; 1823 break; 1824 } 1825 } 1826 } 1827 return persistenceScope; 1828 } 1829 1830 1831 1836 private void configureSession(WebModule ctx, SessionProperties spBean, 1837 WebBundleDescriptor wbd) { 1838 1839 boolean timeoutConfigured = false; 1840 int timeoutSeconds = 1800; boolean enableCookies = true; 1842 1843 if ((spBean != null) && (spBean.sizeWebProperty() > 0)) { 1844 WebProperty[] props = spBean.getWebProperty(); 1845 for (int i = 0; i < props.length; i++) { 1846 1847 String name = props[i].getAttributeValue(WebProperty.NAME); 1848 String value = props[i].getAttributeValue(WebProperty.VALUE); 1849 if (name == null || value == null) { 1850 throw new IllegalArgumentException ( 1851 _rb.getString("webcontainer.nullWebProperty")); 1852 } 1853 1854 if (name.equalsIgnoreCase("timeoutSeconds")) { 1855 try { 1856 timeoutSeconds = Integer.parseInt(value); 1857 timeoutConfigured = true; 1858 } catch (NumberFormatException e) { 1859 } 1861 } else if (name.equalsIgnoreCase("enableCookies")) { 1862 enableCookies = ConfigBean.toBoolean(value); 1863 } else { 1864 Object [] params = { name }; 1865 _logger.log(Level.INFO, "webcontainer.notYet", params); 1866 } 1867 } 1868 } 1869 1870 int webXmlTimeoutSeconds = -1; 1872 if(wbd != null) { 1873 webXmlTimeoutSeconds = wbd.getSessionTimeout() * 60; 1874 } 1875 1876 if (webXmlTimeoutSeconds != -1 && webXmlTimeoutSeconds != 1800) { 1879 ctx.getManager().setMaxInactiveIntervalSeconds(webXmlTimeoutSeconds); 1880 } else { 1881 1885 if (timeoutConfigured) { 1886 ctx.getManager().setMaxInactiveIntervalSeconds(timeoutSeconds); 1887 } 1888 1889 } 1890 1892 ctx.setCookies(enableCookies); 1893 } 1894 1895 1899 private void configureCookieProperties(WebModule ctx, 1900 CookieProperties bean) { 1901 if (bean != null) { 1902 WebProperty[] props = bean.getWebProperty(); 1903 if (props != null) { 1904 SessionCookieConfig cookieConfig = new SessionCookieConfig(); 1905 for (int i = 0; i < props.length; i++) { 1906 1907 String name = props[i].getAttributeValue(WebProperty.NAME); 1908 String value = props[i].getAttributeValue(WebProperty.VALUE); 1909 if (name == null || value == null) { 1910 throw new IllegalArgumentException ( 1911 _rb.getString("webcontainer.nullWebProperty")); 1912 } 1913 1914 if (name.equalsIgnoreCase("cookieName")) { 1915 cookieConfig.setName(value); 1916 } else if (name.equalsIgnoreCase("cookiePath")) { 1917 cookieConfig.setPath(value); 1918 } else if (name.equalsIgnoreCase("cookieMaxAgeSeconds")) { 1919 try { 1920 cookieConfig.setMaxAge(Integer.parseInt(value)); 1921 } catch (NumberFormatException e) { 1922 } 1924 } else if (name.equalsIgnoreCase("cookieDomain")) { 1925 cookieConfig.setDomain(value); 1926 } else if (name.equalsIgnoreCase("cookieComment")) { 1927 cookieConfig.setComment(value); 1928 } else { 1929 Object [] params = { name, value }; 1930 _logger.log(Level.WARNING, 1931 "webcontainer.invalidProperty", 1932 params); 1933 } 1934 } 1935 if (props.length > 0) { 1936 if (_logger.isLoggable(Level.FINE)) { 1937 _logger.fine("WebModule[" + ctx.getPath() + "]: " 1938 + cookieConfig); 1939 } 1940 ctx.setSessionCookieConfig(cookieConfig); 1941 } 1942 } 1943 } 1944 } 1945 1946 1947 1951 protected void configureVirtualServerState( 1952 VirtualServer host, 1953 com.sun.enterprise.config.serverbeans.VirtualServer vsBean){ 1954 1955 String stateValue = ON; 1956 if (vsBean != null){ 1957 stateValue = vsBean.getState(); 1958 } 1959 1960 if ( ( !stateValue.equalsIgnoreCase(ON) ) 1961 && ( host.getName().equalsIgnoreCase(ADMIN_VS) ) ){ 1962 throw new java.lang.IllegalArgumentException ( 1963 "virtual-server " 1964 + ADMIN_VS + " state property cannot be modified"); 1965 } 1966 1967 if ( stateValue.equalsIgnoreCase(DISABLED) ) { 1968 host.setIsDisabled(true); 1970 } else if ( !ConfigBean.toBoolean( stateValue ) ) { 1971 host.setIsOff(true); 1973 } 1974 } 1975 1976 1977 1981 private void configureSSOValve( 1982 VirtualServer vs, 1983 com.sun.enterprise.config.serverbeans.VirtualServer vsBean) { 1984 1985 if (vsBean == null) { 1986 return; 1987 } 1988 1989 if (!isSSOEnabled(vsBean)) { 1991 Object [] params = { vs.getID() }; 1992 _logger.log(Level.INFO, "webcontainer.ssodisabled", params); 1993 1994 } else { 1995 try { 1997 WebContainerFeatureFactory webContainerFeatureFactory = 1998 _serverContext.getPluggableFeatureFactory().getWebContainerFeatureFactory(); 1999 SSOFactory ssoFactory = webContainerFeatureFactory.getSSOFactory(); 2000 SingleSignOn sso = ssoFactory.createSingleSignOnValve(); 2001 if (_debug > 1) 2002 sso.setDebug(_debug); 2003 2004 ElementProperty idle = 2006 vsBean.getElementPropertyByName(SSO_MAX_IDLE); 2007 if (idle !=null && idle.getValue() != null) { 2008 _logger.fine("SSO entry max idle time set to: " + 2009 idle.getValue()); 2010 int i = Integer.parseInt(idle.getValue()); 2011 sso.setMaxInactive(i); 2012 } 2013 2014 ElementProperty expireTime = 2016 vsBean.getElementPropertyByName(SSO_REAP_INTERVAL); 2017 if (expireTime !=null && expireTime.getValue() != null) { 2018 _logger.fine("SSO expire thread interval set to : " + 2019 expireTime.getValue()); 2020 int i = Integer.parseInt(expireTime.getValue()); 2021 sso.setReapInterval(i); 2022 } 2023 2024 vs.addValve(sso); 2025 2026 } catch (Exception e) { 2027 _logger.log(Level.WARNING, "webcontainer.ssobadconfig", e); 2028 _logger.log(Level.WARNING, "webcontainer.ssodisabled", 2029 vs.getID()); 2030 } 2031 } 2032 } 2033 2034 2035 2042 public void configureRemoteAddressFilterValve( 2043 VirtualServer vs, 2044 com.sun.enterprise.config.serverbeans.VirtualServer vsBean) { 2045 2046 RemoteAddrValve remoteAddrValve = null; 2047 2048 if (vsBean == null) { 2049 return; 2050 } 2051 2052 ElementProperty allow = vsBean.getElementPropertyByName( 2053 "allowRemoteAddress"); 2054 ElementProperty deny = vsBean.getElementPropertyByName( 2055 "denyRemoteAddress"); 2056 if ((allow != null && allow.getValue() != null) 2057 || (deny != null && deny.getValue() != null)) { 2058 remoteAddrValve = new RemoteAddrValve(); 2059 } 2060 2061 if (allow != null && allow.getValue() != null) { 2062 _logger.fine("Allowing access to " + vs.getID()+ " from " + 2063 allow.getValue()); 2064 remoteAddrValve.setAllow(allow.getValue()); 2065 } 2066 2067 if (deny != null && deny.getValue() != null) { 2068 _logger.fine("Denying access to " + vs.getID()+ " from " + 2069 deny.getValue()); 2070 remoteAddrValve.setDeny(deny.getValue()); 2071 } 2072 2073 if (remoteAddrValve != null) { 2074 Valve[] valves = vs.getValves(); 2076 for (int i=0; valves!=null && i<valves.length; i++) { 2077 if (valves[i] instanceof RemoteAddrValve) { 2078 vs.removeValve(valves[i]); 2079 break; 2080 } 2081 } 2082 vs.addValve(remoteAddrValve); 2083 } 2084 } 2085 2086 2087 2094 public void configureRemoteHostFilterValve( 2095 VirtualServer vs, 2096 com.sun.enterprise.config.serverbeans.VirtualServer vsBean, 2097 HttpProtocol httpProtocol) { 2098 2099 RemoteHostValve remoteHostValve = null; 2100 2101 if (vsBean == null) { 2102 return; 2103 } 2104 2105 ElementProperty allow = vsBean.getElementPropertyByName( 2106 "allowRemoteHost"); 2107 ElementProperty deny = vsBean.getElementPropertyByName( 2108 "denyRemoteHost"); 2109 if ((allow != null && allow.getValue() != null) 2110 || (deny != null && deny.getValue() != null)) { 2111 remoteHostValve = new RemoteHostValve(); 2112 } 2113 2114 if (allow != null && allow.getValue() != null) { 2115 _logger.fine("Allowing access to " + vs.getID()+ " from " + 2116 allow.getValue()); 2117 if (httpProtocol == null || !httpProtocol.isDnsLookupEnabled()) { 2118 _logger.log(Level.WARNING, 2119 "webcontainer.allowRemoteHost.dnsLookupDisabled", 2120 vs.getID()); 2121 } 2122 remoteHostValve.setAllow(allow.getValue()); 2123 } 2124 2125 if (deny != null && deny.getValue() != null) { 2126 _logger.fine("Denying access to " + vs.getID()+ " from " + 2127 deny.getValue()); 2128 if (httpProtocol == null || !httpProtocol.isDnsLookupEnabled()) { 2129 _logger.log(Level.WARNING, 2130 "webcontainer.denyRemoteHost.dnsLookupDisabled", 2131 vs.getID()); 2132 } 2133 remoteHostValve.setDeny(deny.getValue()); 2134 } 2135 2136 if (remoteHostValve != null) { 2137 Valve[] valves = vs.getValves(); 2139 for (int i=0; valves!=null && i<valves.length; i++) { 2140 if (valves[i] instanceof RemoteHostValve) { 2141 vs.removeValve(valves[i]); 2142 break; 2143 } 2144 } 2145 vs.addValve(remoteHostValve); 2146 } 2147 } 2148 2149 2150 2159 public void unloadWebModule(String contextRoot, 2160 String appName, 2161 String virtualServers, 2162 WebBundleDescriptor wbd) { 2163 unloadWebModule(contextRoot, appName, virtualServers, wbd, false); 2164 } 2165 2166 2178 public void unloadWebModule(String contextRoot, 2179 String appName, 2180 String virtualServers, 2181 WebBundleDescriptor wbd, 2182 boolean dummy) { 2183 disableWSMonitoring(wbd); 2184 2185 if (_logger.isLoggable(Level.FINEST)) { 2186 _logger.finest("WebContainer.unloadWebModule(): contextRoot: " 2187 + contextRoot + " appName:" + appName); 2188 } 2189 2190 SessionPurgeUtil purgeUtil = new SessionPurgeUtil(_embedded); 2192 2194 cleanSecurityContext(appName); 2195 2196 if (webModulesManager != null) { 2198 webModulesManager.unregisterDescriptor(appName); 2199 } 2200 2201 if (!contextRoot.equals("") && !contextRoot.startsWith("/") ) { 2203 contextRoot = "/" + contextRoot; 2204 } else if ("/".equals(contextRoot)) { 2205 contextRoot = ""; 2207 } 2208 2209 Engine[] engines = _embedded.getEngines(); 2210 List hostList = StringUtils.parseStringList(virtualServers, " ,"); 2211 boolean unloadToAll = (hostList == null) || (hostList.size() == 0); 2212 boolean hasBeenUndeployed = false; 2213 Container[] hostArray = null; 2214 VirtualServer host = null; 2215 WebModule context = null; 2216 2217 for (int j = 0; j < engines.length; j++) { 2218 hostArray = engines[j].findChildren(); 2219 for (int i = 0; i < hostArray.length; i++) { 2220 host = (VirtualServer) hostArray[i]; 2221 2222 2226 if ( unloadToAll && host.getName().equalsIgnoreCase(ADMIN_VS)){ 2227 continue; 2228 } 2229 2230 if (unloadToAll 2231 || hostList.contains(host.getName()) 2232 || verifyAlias(hostList,host)){ 2233 2234 context = (WebModule) host.findChild(contextRoot); 2235 if (context != null) { 2236 if (_logger.isLoggable(Level.FINEST)) { 2238 _logger.finest("about to call SessionPurgeUtil " 2239 + "for " + appName 2240 + " contextRoot: " + contextRoot); 2241 } 2242 purgeUtil.purgeSessionsForContext(context); 2243 disableMonitoring(context, host.getName()); 2245 host.removeChild(context); 2246 try { 2247 ((StandardContext)context).destroy(); 2248 } catch (Exception ex) { 2249 _logger.log(Level.WARNING, 2250 "[WebContainer] Context " + contextRoot 2251 + " threw exception in destroy()", ex); 2252 } 2253 Switch sw = Switch.getSwitch(); 2255 sw.removeDescriptorFor(context); 2256 if (_logger.isLoggable(Level.FINEST)) { 2258 _logger.log(Level.FINEST, 2259 "[WebContainer] Context " + contextRoot 2260 + " undeployed from " + host); 2261 } 2262 hasBeenUndeployed = true; 2263 ((StandardHost)host).fireContainerEvent( 2264 Deployer.REMOVE_EVENT, context); 2265 2271 if (context.hasAdHocPaths() 2272 || context.hasAdHocSubtrees()) { 2273 WebModule wm = createAdHocWebModule( 2274 host, 2275 contextRoot, 2276 context.getJ2EEApplication()); 2277 wm.addAdHocPaths(context.getAdHocPaths()); 2278 wm.addAdHocSubtrees(context.getAdHocSubtrees()); 2279 } 2280 2281 if (!dummy) { 2283 WebModuleConfig wmInfo = 2284 host.createSystemDefaultWebModuleIfNecessary(); 2285 if (wmInfo != null) { 2286 loadStandaloneWebModule(host, wmInfo); 2287 } 2288 } 2289 } 2291 } 2292 } 2293 } 2294 2295 2296 if (!hasBeenUndeployed) { 2297 _logger.log(Level.SEVERE, 2298 "[WebContainer] Undeployment failed for context " 2299 + contextRoot); 2300 } 2301 2302 } 2303 2304 2305 2314 public void enableWebModule(WebModuleConfig wmInfo, 2315 String j2eeApplication){ 2316 String vsIDs = wmInfo.getVirtualServers(); 2317 List vsList = StringUtils.parseStringList(vsIDs, " ,"); 2318 boolean enabledToAll = (vsList == null) || (vsList.size() == 0); 2319 2320 Engine[] engines = _embedded.getEngines(); 2321 2322 for (int j=0; j<engines.length; j++) { 2323 Container[] vsArray = engines[j].findChildren(); 2324 for (int i = 0; i < vsArray.length; i++) { 2325 if (vsArray[i] instanceof VirtualServer) { 2326 VirtualServer vs = (VirtualServer) vsArray[i]; 2327 2328 2333 if (vs.getID().equals(ADMIN_VS) && enabledToAll) { 2334 continue; 2335 } 2336 2337 if ( enabledToAll 2338 || vsList.contains(vs.getID()) 2339 || verifyAlias(vsList,vs)){ 2340 2341 loadWebModule(vs, wmInfo, j2eeApplication); 2342 } 2343 } 2344 } 2345 } 2346 } 2347 2348 2349 2355 public void disableWebModule(String contextRoot, 2356 String appName, 2357 String virtualServers){ 2358 2359 if (!contextRoot.equals("") && !contextRoot.startsWith("/") ) { 2361 contextRoot = "/" + contextRoot; 2362 } 2363 2364 Engine[] engines = _embedded.getEngines(); 2365 List hostList = StringUtils.parseStringList(virtualServers, " ,"); 2366 boolean disableToAll = (hostList == null) || (hostList.size() == 0); 2367 boolean hasBeenDisabled = false; 2368 Container[] hostArray = null; 2369 VirtualServer host = null; 2370 Context context = null; 2371 2372 for (int j = 0; j < engines.length; j++) { 2373 hostArray = engines[j].findChildren(); 2374 for (int i = 0; i < hostArray.length; i++) { 2375 host = (VirtualServer) hostArray[i]; 2376 2377 2381 if ( disableToAll 2382 && host.getName().equalsIgnoreCase(ADMIN_VS)){ 2383 continue; 2384 } 2385 2386 if (disableToAll 2387 || hostList.contains(host.getName()) 2388 || verifyAlias(hostList,host)){ 2389 2390 context = (Context) host.findChild(contextRoot); 2391 if (context != null) { 2392 context.setAvailable(false); 2393 if (_logger.isLoggable(Level.FINEST)) { 2394 _logger.log(Level.FINEST, 2395 "[WebContainer] Context " 2396 + contextRoot + " disabled from " 2397 + host); 2398 } 2399 hasBeenDisabled = true; 2400 } 2401 } 2402 } 2403 } 2404 2405 if (!hasBeenDisabled){ 2406 _logger.log(Level.WARNING, 2407 "[WebContainer] moduleDisabled fail for context " 2408 + contextRoot); 2409 } 2410 2411 } 2412 2413 2414 2418 private void getDynamicReloadingSettings(DasConfig appsBean) { 2419 if (appsBean != null) { 2420 _reloadingEnabled = appsBean.isDynamicReloadEnabled(); 2421 String seconds = appsBean.getDynamicReloadPollIntervalInSeconds(); 2422 if (seconds != null) { 2423 try { 2424 _pollInterval = Integer.parseInt(seconds); 2425 } catch (NumberFormatException e) { 2426 } 2427 } 2428 } 2429 } 2430 2431 2436 private void setLogLevel(Level level) { 2437 _logLevel = level; 2438 _logger.setLevel(_logLevel); 2439 2440 if (level.equals(Level.FINE)) 2442 _debug = 1; 2443 else if (level.equals(Level.FINER)) 2444 _debug = 2; 2445 else if (level.equals(Level.FINEST)) 2446 _debug = 5; 2447 else 2448 _debug = 0; 2449 } 2450 2451 2452 2458 private void initLogLevel(LogService logserviceBean) 2459 throws ConfigException { 2460 2461 Level level = Level.SEVERE; 2462 setLogLevel(level); 2463 2464 if (logserviceBean != null) { 2465 try { 2466 level = Level.parse(logserviceBean.getModuleLogLevels().getRoot()); 2467 setLogLevel(level); 2468 } catch (NullPointerException e) { 2469 } catch (IllegalArgumentException e) { } 2470 } 2471 2472 try { 2475 level = Level.parse(ServerBeansFactory.getWebContainerLogLevel( 2476 _configContext)); 2477 setLogLevel(level); 2478 } catch (NullPointerException e) { 2479 if (_debug > 0) 2480 _logger.finest("Defaulting <web-container> log-level"); 2481 } catch (IllegalArgumentException e) { 2482 } 2483 if (_debug > 0) { 2484 _logger.fine("Web container log level: " + _logLevel); 2485 } 2486 } 2487 2488 2489 2495 private void initMonitoringLevel(MonitoringService monitoringBean) { 2496 2497 monitoringLevel = MonitoringLevel.OFF; 2499 if (monitoringBean != null) { 2500 ModuleMonitoringLevels levels = 2501 monitoringBean.getModuleMonitoringLevels(); 2502 if (levels != null) { 2503 monitoringLevel = MonitoringLevel.instance( 2504 levels.getWebContainer()); 2505 } 2506 } 2507 } 2508 2509 2510 2517 private boolean isSSOEnabled(com.sun.enterprise.config.serverbeans.VirtualServer vsBean) 2518 { 2519 ElementProperty ssoProperty = 2520 vsBean.getElementPropertyByName(SSO_ENABLED); 2521 2522 if (ssoProperty!=null && ssoProperty.getValue()!=null 2523 && !ConfigBean.toBoolean( ssoProperty.getValue())) { 2524 return false; 2525 } 2526 return true; 2527 } 2528 2529 2530 2538 private com.sun.enterprise.config.serverbeans.VirtualServer findVirtualServerBean(String vsID) { 2539 2540 HttpService httpService = null; 2541 try { 2542 httpService = ServerBeansFactory.getHttpServiceBean(_configContext); 2543 } catch (ConfigException e) { 2544 String msg = _rb.getString("webcontainer.httpConfigError"); 2545 _logger.log(Level.SEVERE, msg, e); 2546 } 2547 2548 com.sun.enterprise.config.serverbeans.VirtualServer[] vses 2549 = httpService.getVirtualServer(); 2550 for (int i=0; vses!=null && i<vses.length; i++) { 2551 if (vsID.equals(vses[i].getId())) { 2552 return vses[i]; 2553 } 2554 } 2555 2556 return null; 2557 } 2558 2559 2560 2564 public LifecycleListener[] findLifecycleListeners() { 2565 return new LifecycleListener[0]; 2566 } 2567 2568 2569 2577 private void cleanSecurityContext(String appName) { 2578 String cIDs[] = webSecurityManagerFactory.getContextIdsOfApp(appName); 2579 2580 for (int i=0; cIDs != null && i <cIDs.length; i++) { 2581 WebSecurityManager wsm 2582 = webSecurityManagerFactory.getWebSecurityManager(cIDs[i]); 2583 2584 _logger.log(Level.FINE,"[JACC]: Removing WebSecurityManager: " 2585 + cIDs[i]); 2586 2587 if (wsm != null) { 2588 try { 2589 wsm.destroy(); 2590 } catch (javax.security.jacc.PolicyContextException pce){ 2591 _logger.log(Level.WARNING, 2593 "Unable to destroy WebSecurityManager", 2594 pce); 2595 } 2596 webSecurityManagerFactory.removeWebSecurityManager(cIDs[i]); 2597 } 2598 } 2599 } 2600 2601 2613 private String getVirtualServers(String appName, ConfigContext configCtx) { 2614 if (configCtx == null) { 2615 configCtx = _configContext; 2616 } 2617 String ret = null; 2618 try { 2619 ret = ServerBeansFactory.getVirtualServersByAppName(configCtx, 2620 appName); 2621 } catch (ConfigException ce) { 2622 _logger.log(Level.WARNING, 2623 "No virtual servers defined for " + appName, 2624 ce); 2625 } 2626 return ret; 2627 } 2628 2629 2638 private void addMimeMappings(StandardContext ctx, MimeMap mimeMap) { 2639 if (mimeMap == null) { 2640 return; 2641 } 2642 2643 for (Iterator itr = mimeMap.getExtensions(); itr.hasNext(); ) { 2644 String extension = (String ) itr.next(); 2645 if (ctx.findMimeMapping(extension) == null) { 2646 ctx.addMimeMapping(extension, mimeMap.getType(extension)); 2647 } 2648 } 2649 } 2650 2651 2654 private void enableAllWSEndpoints() { 2655 2656 Applications appsBean = null; 2657 try { 2658 appsBean = ServerBeansFactory.getApplicationsBean(_configContext); 2659 } catch (ConfigException e) { 2660 String msg = _rb.getString("webcontainer.appsConfigError"); 2661 _logger.log(Level.SEVERE, msg, e); 2662 } 2663 2664 if (appsBean != null) { 2665 J2eeApplication[] j2eeAppBeans = appsBean.getJ2eeApplication(); 2666 if (j2eeAppBeans != null) { 2667 for (int i = 0; i < j2eeAppBeans.length; i++) { 2668 if ( isReferenced(j2eeAppBeans[i].getName()) ) { 2670 enableWSMonitoring(j2eeAppBeans[i].getName()); 2671 } 2672 } 2674 } 2675 } 2676 } 2677 2678 2685 private boolean disableWSMonitoring(WebBundleDescriptor wbd) { 2686 2687 boolean result = true; 2688 2689 try { 2690 Switch.getSwitch().getManagementObjectManager(). 2691 deleteWSEndpointMBeans(wbd, instance.getName()); 2692 } catch (Exception e) { 2693 e.printStackTrace(); 2694 return false; 2695 } 2696 return true; 2697 } 2698 2699 2706 private boolean enableWSMonitoring(String id) { 2707 2708 boolean result = true; 2709 2710 ApplicationRegistry registry = ApplicationRegistry.getInstance(); 2711 ClassLoader appLoader = registry.getClassLoaderForApplication(id); 2712 if (appLoader != null) { 2713 Application appDesc = registry.getApplication(appLoader); 2714 2715 if(appDesc == null){ 2717 Object [] params = { id }; 2718 _logger.log(Level.SEVERE, "webcontainer.notLoaded", 2719 params); 2720 } else { 2721 String j2eeApplication = appDesc.getRegistrationName(); 2723 Set wbds = appDesc.getWebBundleDescriptors(); 2724 WebBundleDescriptor wbd = null; 2725 for (Iterator itr = wbds.iterator(); itr.hasNext(); ) { 2726 wbd = (WebBundleDescriptor) itr.next(); 2727 2728 try { 2729 Switch.getSwitch().getManagementObjectManager(). 2730 createWSEndpointMBeans(wbd, instance.getName()); 2731 } catch (Exception e) { 2732 e.printStackTrace(); 2733 return false; 2734 } 2735 } 2736 } 2737 } 2738 return true; 2739 } 2740 2741 void enableWSMonitoring(WebBundleDescriptor wbd, String serverName) { 2742 try { 2743 Switch.getSwitch().getManagementObjectManager(). 2744 createWSEndpointMBeans(wbd, serverName); 2745 } catch (Exception e) { 2746 e.printStackTrace(); 2747 } 2748 } 2749 2750 2756 void enableMonitoring(WebModule ctx, String vsId) { 2757 2758 if (!ctx.hasWebXml()) { 2759 return; 2761 } 2762 2763 String j2eeServer = _serverContext.getInstanceName(); 2764 2765 registerWebModuleStats(ctx.getJ2EEApplication(), j2eeServer, vsId, 2767 ctx, null); 2768 2769 Container[] children = ctx.findChildren(); 2771 if (children != null) { 2772 for (int i = 0; i < children.length; i++) { 2773 registerServletStats(ctx.getJ2EEApplication(), j2eeServer, 2774 ctx.getModuleName(), vsId, ctx.getPath(), 2775 children[i].getName(), null); 2776 } 2777 } 2778 } 2779 2780 2781 2784 protected void disableMonitoring(WebModule ctx, String vsId) { 2785 2786 if (!ctx.hasWebXml()) { 2787 return; 2789 } 2790 2791 2795 String appName = ctx.getJ2EEApplication(); 2796 if ("null".equalsIgnoreCase(appName)) { 2797 appName = null; 2798 } 2799 2800 Container[] children = ctx.findChildren(); 2802 if (children != null) { 2803 for (int k = 0; k < children.length; k++) { 2804 unregisterServletStats(appName, ctx.getModuleName(), 2805 ctx.getPath(), vsId, 2806 children[k].getName()); 2807 } 2808 } 2809 unregisterWebModuleStats(appName, ctx.getModuleName(), 2811 ctx.getPath(), vsId); 2812 2813 } 2814 2815 2820 private void setNoTldScan() { 2821 boolean first = true; 2822 StringBuffer sb = new StringBuffer (); 2823 StringBuffer sbListener = new StringBuffer (); 2824 List tldJars = null; 2825 List tldListeners = null; 2826 2827 String prop = System.getProperty("com.sun.enterprise.taglibs"); 2828 if (prop != null) { 2829 tldJars = StringUtils.parseStringList(prop, ","); 2830 } 2831 2832 prop = System.getProperty("com.sun.enterprise.taglisteners"); 2833 if (prop != null) { 2834 tldListeners = StringUtils.parseStringList(prop, ","); 2835 } 2836 2837 if ( tldListeners != null ){ 2842 int size = tldListeners.size(); 2843 if ( size > 0 ){ 2844 if ( !tldListeners.contains("jsf-impl.jar") || (size > 1)) 2846 TldConfig.setScanParentTldListener(true); 2847 } 2848 } 2849 2850 ClassLoader loader = getClass().getClassLoader(); 2851 while (loader != null) { 2852 if (loader instanceof URLClassLoader ) { 2853 URL [] urls = ((URLClassLoader ) loader).getURLs(); 2854 for (int i=0; i<urls.length; i++) { 2855 String url = urls[i].toString(); 2856 int index = url.lastIndexOf('/'); 2857 if (index != -1) { 2858 url = url.substring(index+1); 2859 } 2860 if (url != null && url.endsWith(".jar") 2861 && (tldJars == null || !tldJars.contains(url)) 2862 2863 ) { 2864 if (first) { 2865 sb.append(url); 2866 first = false; 2867 } else { 2868 sb.append(','); 2869 sb.append(url); 2870 } 2871 } 2872 2873 if (url != null && url.endsWith(".jar") 2874 && (tldListeners == null || !tldListeners.contains(url)) 2875 2876 ) { 2877 if (first) { 2878 sbListener.append(url); 2879 first = false; 2880 } else { 2881 sbListener.append(','); 2882 sbListener.append(url); 2883 } 2884 } 2885 } 2886 } 2887 loader = loader.getParent(); 2888 } 2889 2890 if (sbListener.length() > 0) { 2891 TldConfig.setNoTldListeners(sbListener.toString()); 2892 } 2893 2894 if (sb.length() > 0) { 2895 TldLocationsCache.setNoTldJars(sb.toString()); 2896 } 2897 } 2898 2899 2900 2907 private boolean isReferenced(String appName) { 2908 2909 Servers servers = domain.getServers(); 2910 Server server = servers.getServerByName( 2911 _serverContext.getInstanceName()); 2912 2913 ApplicationRef ref = server.getApplicationRefByRef(appName); 2914 return (ref == null) ? false : true; 2915 } 2916 2918 2919 2934 private void registerServletStats(String j2eeApplication, 2935 String j2eeServer, 2936 String webModuleName, 2937 String vsId, 2938 String contextRoot, 2939 String servletName, 2940 MonitoringLevelListener listener) { 2941 2942 PwcServletStats pwcServletStats = new PwcServletStatsImpl( 2943 _serverContext.getDefaultDomainName(), 2944 vsId, contextRoot, servletName, 2945 j2eeApplication, j2eeServer); 2946 ServletStats servletStats = new ServletStatsImpl(pwcServletStats); 2947 2948 2949 MonitoringRegistry monitoringRegistry = 2950 _serverContext.getMonitoringRegistry(); 2951 2952 2956 String app = ("null".equalsIgnoreCase(j2eeApplication) ? 2957 null : j2eeApplication); 2958 try { 2959 monitoringRegistry.registerServletStats(servletStats, 2960 app, 2961 webModuleName, 2962 contextRoot, 2963 vsId, 2964 servletName, 2965 listener); 2966 } catch(Exception e) { 2967 _logger.log(Level.WARNING, 2968 "Exception during registration of servletstats", 2969 e); 2970 } 2971 } 2972 2973 2974 2987 private void unregisterServletStats(String j2eeApplication, 2988 String webModuleName, 2989 String contextRoot, 2990 String vsId, 2991 String servletName) { 2992 2993 MonitoringRegistry monitoringRegistry = 2994 _serverContext.getMonitoringRegistry(); 2995 2996 try { 2997 monitoringRegistry.unregisterServletStats(j2eeApplication, 2998 webModuleName, 2999 contextRoot, 3000 vsId, 3001 servletName); 3002 } catch (Exception e) { 3003 _logger.log(Level.WARNING, 3004 "Exception during unregistration of servletstats", 3005 e); 3006 } 3007 } 3008 3009 3010 3025 private WebModuleStats registerWebModuleStats( 3026 String j2eeApplication, 3027 String j2eeServer, 3028 String vsId, 3029 WebModule ctx, 3030 MonitoringLevelListener listener) { 3031 3032 WebContainerFeatureFactory webFeatureFac = 3033 _serverContext.getPluggableFeatureFactory().getWebContainerFeatureFactory(); 3034 WebModuleStatsImpl webStats = (WebModuleStatsImpl) 3035 webFeatureFac.getWebModuleStats(); 3036 PwcWebModuleStatsImpl pwcWebStats = new PwcWebModuleStatsImpl( 3037 ctx.getObjectName(), 3038 ctx.getPath(), 3039 _serverContext.getDefaultDomainName(), 3040 vsId, 3041 j2eeApplication, 3042 j2eeServer); 3043 webStats.setPwcWebModuleStats(pwcWebStats); 3044 webStats.setSessionManager(ctx.getManager()); 3045 3046 MonitoringRegistry monitoringRegistry = 3047 _serverContext.getMonitoringRegistry(); 3048 3049 3053 String app = ("null".equalsIgnoreCase(j2eeApplication) ? 3054 null : j2eeApplication); 3055 try { 3056 monitoringRegistry.registerWebModuleStats(webStats, 3057 app, 3058 ctx.getModuleName(), 3059 ctx.getPath(), 3060 vsId, 3061 listener); 3062 } catch (Exception e) { 3063 _logger.log(Level.WARNING, 3064 "Fail to register WebModuleStats for " 3065 + ctx.getModuleName() + " deployed on " + vsId, e); 3066 } 3067 3068 return webStats; 3069 } 3070 3071 3072 3083 private void unregisterWebModuleStats(String j2eeApplication, 3084 String webModuleName, 3085 String contextRoot, 3086 String vsId) { 3087 3088 MonitoringRegistry monitoringRegistry = 3089 _serverContext.getMonitoringRegistry(); 3090 3091 try { 3092 monitoringRegistry.unregisterWebModuleStats(j2eeApplication, 3093 webModuleName, 3094 contextRoot, 3095 vsId); 3096 } catch (Exception e) { 3097 _logger.log(Level.WARNING, 3098 "Fail to unregister WebModuleStats for " 3099 + webModuleName + " deployed on " + vsId, e); 3100 } 3101 } 3102 3103 3110 public void moduleReferenceAdded(ModuleDeployEvent event) 3111 { 3113 } 3114 3115 3122 public void moduleReferenceRemoved(ModuleDeployEvent event) 3123 { 3125 } 3126 3127 3128 3135 public void applicationReferenceAdded(ApplicationDeployEvent event) 3136 { 3138 } 3139 3140 3147 public void applicationReferenceRemoved(ApplicationDeployEvent event) 3148 { } 3150 3151 3154 public static WebContainer getInstance(){ 3155 return webContainer; 3156 } 3157 3158 3162 public Engine[] getEngines() { 3163 return _embedded.getEngines(); 3164 } 3165 3166 3167 3177 public void registerAdHocPath(String path, 3178 String ctxtRoot, 3179 String appName, 3180 AdHocServletInfo servletInfo) { 3181 3182 registerAdHocPathAndSubtree(path, null, ctxtRoot, appName, servletInfo); 3183 } 3184 3185 3186 3197 public void registerAdHocPathAndSubtree(String path, 3198 String subtree, 3199 String ctxtRoot, 3200 String appName, 3201 AdHocServletInfo servletInfo) { 3202 WebModule wm = null; 3203 3204 Engine[] engines = _embedded.getEngines(); 3205 for (int j=0; j<engines.length; j++) { 3206 3207 Container[] vsList = engines[j].findChildren(); 3208 for (int i = 0; i < vsList.length; i++) { 3209 3210 VirtualServer vs = (VirtualServer)vsList[i]; 3211 if (vs.getName().equalsIgnoreCase(ADMIN_VS)) { 3212 continue; 3214 } 3215 3216 wm = (WebModule) vs.findChild(ctxtRoot); 3217 if (wm == null) { 3218 wm = createAdHocWebModule(vs, ctxtRoot, appName); 3219 } 3220 wm.addAdHocPathAndSubtree(path, subtree, servletInfo); 3221 } 3222 } 3223 } 3224 3225 3226 3232 public void unregisterAdHocPath(String path, String ctxtRoot) { 3233 unregisterAdHocPathAndSubtree(path, null, ctxtRoot); 3234 } 3235 3236 3237 3245 public void unregisterAdHocPathAndSubtree(String path, 3246 String subtree, 3247 String ctxtRoot) { 3248 3249 WebModule wm = null; 3250 3251 Engine[] engines = _embedded.getEngines(); 3252 for (int j=0; j<engines.length; j++) { 3253 3254 Container[] vsList = engines[j].findChildren(); 3255 for (int i = 0; i < vsList.length; i++) { 3256 3257 VirtualServer vs = (VirtualServer) vsList[i]; 3258 if (vs.getName().equalsIgnoreCase(ADMIN_VS)) { 3259 continue; 3262 } 3263 3264 wm = (WebModule) vs.findChild(ctxtRoot); 3265 if (wm == null) { 3266 continue; 3267 } 3268 3269 3275 wm.removeAdHocPath(path); 3276 wm.removeAdHocSubtree(subtree); 3277 if ((wm instanceof AdHocWebModule) 3278 && !wm.hasAdHocPaths() 3279 && !wm.hasAdHocSubtrees()) { 3280 vs.removeChild(wm); 3281 try { 3282 wm.destroy(); 3283 } catch (Exception ex) { 3284 _logger.log(Level.WARNING, 3285 "[WebContainer] Context " + wm.getPath() 3286 + " threw exception in destroy()", ex); 3287 } 3288 } 3289 } 3290 } 3291 } 3292 3293 3294 3306 private WebModule createAdHocWebModule(VirtualServer vs, 3307 String ctxtRoot, 3308 String appName) { 3309 3310 AdHocWebModule wm = new AdHocWebModule(this); 3311 3312 wm.restrictedSetPipeline(new WebPipeline(wm)); 3313 3314 if (Boolean.getBoolean(com.sun.enterprise.server.PELaunch.USE_NEW_CLASSLOADER_PROPERTY)) { 3318 wm.setParentClassLoader( 3319 Thread.currentThread().getContextClassLoader()); 3320 } 3321 3322 wm.setContextRoot(ctxtRoot); 3323 wm.setJ2EEApplication(appName); 3324 wm.setName(ctxtRoot); 3325 wm.setDocBase(vs.getAppBase()); 3326 wm.setEngineName(vs.getParent().getName()); 3327 3328 String domain = _serverContext.getDefaultDomainName(); 3329 wm.setDomain(domain); 3330 3331 String j2eeServer = _serverContext.getInstanceName(); 3332 wm.setJ2EEServer(j2eeServer); 3333 3334 String server = domain + ":j2eeType=J2EEServer,name=" + j2eeServer; 3335 wm.setServer(server); 3336 3337 wm.setCrossContext(true); 3338 wm.setJavaVMs(J2EEModuleUtil.getjavaVMs()); 3339 3340 vs.addChild(wm); 3341 3342 return wm; 3343 } 3344 3345 3346 3353 private void addLibs(Loader loader, WebModule ctx) { 3354 3355 String list = ASClassLoaderUtil.getLibrariesForWebModule(ctx.getID()); 3356 if (list == null) { 3357 return; 3358 } 3359 String [] libs = list.split(","); 3360 if (libs == null) { 3361 return; 3362 } 3363 3364 File libDir = new File (instance.getLibPath()); 3365 String libDirPath = libDir.getAbsolutePath(); 3366 String appLibsPrefix = libDirPath + File.separator + "applibs" 3367 + File.separator; 3368 3369 for (int i=0; i<libs.length; i++) { 3370 File file = new File (libs[i]); 3371 if (file.isAbsolute()) { 3372 loader.addRepository("file:" + file.getAbsolutePath()); 3373 } else { 3374 loader.addRepository("file:" + appLibsPrefix + libs[i]); 3375 } 3376 } 3377 } 3378 3379 3380 3388 private void configureLoaderAttributes( 3389 Loader loader, 3390 com.sun.enterprise.deployment.runtime.web.ClassLoader clBean, 3391 WebModule ctx) { 3392 3393 String value = null; 3394 3395 value = clBean.getAttributeValue( 3396 com.sun.enterprise.deployment.runtime.web.ClassLoader.DELEGATE); 3397 3398 3405 boolean delegate = ConfigBean.toBoolean(value); 3406 loader.setDelegate(delegate); 3407 3408 List pathElements = null; 3411 value = clBean.getAttributeValue( 3412 com.sun.enterprise.deployment.runtime.web.ClassLoader.EXTRA_CLASS_PATH); 3413 if (value != null) { 3414 pathElements = StringUtils.parseStringList(value, ";:"); 3415 if (pathElements != null) { 3416 ListIterator iter = pathElements.listIterator(); 3417 while (iter.hasNext()) { 3418 String path = (String ) iter.next(); 3419 if (_logger.isLoggable(Level.FINE)) { 3420 _logger.fine("WebModule[" + ctx.getPath() 3421 + "]: Adding " + path + " to the classpath"); 3422 } 3423 3424 try { 3425 URL url = new File (path).toURI().toURL(); 3426 loader.addRepository(url.toString()); 3427 } catch (MalformedURLException e) { 3428 String msg = _rb.getString("webcontainer.classpathError"); 3429 Object [] params = { path }; 3430 msg = MessageFormat.format(msg, params); 3431 _logger.log(Level.SEVERE, msg, e); 3432 } 3433 } 3434 } 3435 } 3436 3437 value = clBean.getAttributeValue( 3438 com.sun.enterprise.deployment.runtime.web.ClassLoader.DYNAMIC_RELOAD_INTERVAL); 3439 if (value != null) { 3440 _logger.log(Level.WARNING, 3443 "webcontainer.dynamicReloadInterval"); 3444 } 3445 3446 _logger.fine("WebModule[" + ctx.getPath() 3447 + "]: Setting delegate to " + delegate 3448 + ", extra-class-path to " + pathElements); 3449 } 3450 3451 3452 3459 private void configureLoaderProperties( 3460 Loader loader, 3461 com.sun.enterprise.deployment.runtime.web.ClassLoader clBean) { 3462 3463 String name = null; 3464 String value = null; 3465 3466 WebProperty[] props = clBean.getWebProperty(); 3467 if (props == null || props.length == 0) { 3468 return; 3469 } 3470 3471 for (int i = 0; i < props.length; i++) { 3472 3473 name = props[i].getAttributeValue(WebProperty.NAME); 3474 value = props[i].getAttributeValue(WebProperty.VALUE); 3475 3476 if (name == null || value == null) { 3477 throw new IllegalArgumentException ( 3478 _rb.getString("webcontainer.nullWebProperty")); 3479 } 3480 3481 if (name.equalsIgnoreCase("ignoreHiddenJarFiles")) { 3482 loader.setIgnoreHiddenJarFiles(ConfigBean.toBoolean(value)); 3483 } else { 3484 Object [] params = { name, value }; 3485 _logger.log(Level.WARNING, 3486 "webcontainer.invalidProperty", 3487 params); 3488 } 3489 } 3490 } 3491 3492 3493 3499 private void configureRedirect( 3500 VirtualServer vs, 3501 com.sun.enterprise.config.serverbeans.VirtualServer vsBean) { 3502 3503 if (vsBean == null) { 3504 return; 3505 } 3506 3507 ElementProperty[] props = vsBean.getElementProperty(); 3508 if (props == null) { 3509 return; 3510 } 3511 3512 for (int i=0; i<props.length; i++) { 3513 3514 String propName = props[i].getName(); 3515 String propValue = props[i].getValue(); 3516 if (propName == null || propValue == null) { 3517 _logger.log(Level.WARNING, 3518 "webcontainer.nullVirtualServerProperty", 3519 vs.getID()); 3520 } 3521 3522 if (!propName.startsWith("redirect_")) { 3523 continue; 3524 } 3525 3526 3529 String from = null; 3530 String url = null; 3531 String urlPrefix = null; 3532 String escape = null; 3533 3534 String [] redirectParams = propValue.split(" "); 3535 for (int j=0; j<redirectParams.length; j++) { 3536 3537 if (redirectParams[j].startsWith("from=")) { 3538 if (from != null) { 3539 _logger.log(Level.WARNING, 3540 "webcontainer.redirectMultipleElement", 3541 new Object [] { propValue, "from" }); 3542 } 3543 from = redirectParams[j].substring("from=".length()); 3544 } 3545 3546 if (redirectParams[j].startsWith("url=")) { 3547 if (url != null) { 3548 _logger.log(Level.WARNING, 3549 "webcontainer.redirectMultipleElement", 3550 new Object [] { propValue, "url" }); 3551 } 3552 url = redirectParams[j].substring("url=".length()); 3553 } 3554 3555 if (redirectParams[j].startsWith("url-prefix=")) { 3556 if (urlPrefix != null) { 3557 _logger.log(Level.WARNING, 3558 "webcontainer.redirectMultipleElement", 3559 new Object [] { propValue, "url-prefix" }); 3560 } 3561 urlPrefix = redirectParams[j].substring( 3562 "url-prefix=".length()); 3563 } 3564 3565 if (redirectParams[j].startsWith("escape=")) { 3566 if (escape != null) { 3567 _logger.log(Level.WARNING, 3568 "webcontainer.redirectMultipleElement", 3569 new Object [] { propValue, "escape" }); 3570 } 3571 escape = redirectParams[j].substring("escape=".length()); 3572 } 3573 } 3574 3575 if (from == null || from.length() == 0) { 3576 _logger.log(Level.WARNING, 3577 "webcontainer.redirectMissingFrom", 3578 propValue); 3579 } 3580 3581 if ((url == null || url.length() == 0) 3583 && (urlPrefix == null || urlPrefix.length() == 0)) { 3584 _logger.log(Level.WARNING, 3585 "webcontainer.redirectMissingUrlOrUrlPrefix", 3586 propValue); 3587 } 3588 if (url != null && url.length() > 0 3589 && urlPrefix != null && urlPrefix.length() > 0) { 3590 _logger.log(Level.WARNING, 3591 "webcontainer.redirectBothUrlAndUrlPrefix", 3592 propValue); 3593 } 3594 3595 boolean escapeURI = true; 3596 if (escape != null) { 3597 if ("yes".equalsIgnoreCase(escape)) { 3598 escapeURI = true; 3599 } else if ("no".equalsIgnoreCase(escape)) { 3600 escapeURI = false; 3601 } else { 3602 _logger.log(Level.WARNING, 3603 "webcontainer.redirectInvalidEscape", 3604 propValue); 3605 } 3606 } 3607 3608 vs.addRedirect(from, url, urlPrefix, escapeURI); 3609 } 3610 3611 } 3612 3613 3614 3620 private void configureErrorPage( 3621 VirtualServer vs, 3622 com.sun.enterprise.config.serverbeans.VirtualServer vsBean) { 3623 3624 ErrorPage errorPage = null; 3625 3626 if (vsBean == null) { 3627 return; 3628 } 3629 3630 ElementProperty[] props = vsBean.getElementProperty(); 3631 if (props == null) { 3632 return; 3633 } 3634 3635 for (int i=0; i<props.length; i++) { 3636 3637 String propName = props[i].getName(); 3638 String propValue = props[i].getValue(); 3639 if (propName == null || propValue == null) { 3640 _logger.log(Level.WARNING, 3641 "webcontainer.nullVirtualServerProperty", 3642 vs.getID()); 3643 } 3644 3645 if (!propName.startsWith("send-error_")) { 3646 continue; 3647 } 3648 3649 3652 String path = null; 3653 String reason = null; 3654 String status = null; 3655 3656 String [] errorParams = propValue.split(" "); 3657 for (int j=0; j<errorParams.length; j++) { 3658 3659 if (errorParams[j].startsWith("path=")) { 3660 if (path != null) { 3661 _logger.log(Level.WARNING, 3662 "webcontainer.sendErrorMultipleElement", 3663 new Object [] { propValue, "path" }); 3664 } 3665 path = errorParams[j].substring("path=".length()); 3666 } 3667 3668 if (errorParams[j].startsWith("reason=")) { 3669 if (reason != null) { 3670 _logger.log(Level.WARNING, 3671 "webcontainer.sendErrorMultipleElement", 3672 new Object [] { propValue, "reason" }); 3673 } 3674 reason = errorParams[j].substring("reason=".length()); 3675 } 3676 3677 if (errorParams[j].startsWith("code=")) { 3678 if (status != null) { 3679 _logger.log(Level.WARNING, 3680 "webcontainer.sendErrorMultipleElement", 3681 new Object [] { propValue, "code" }); 3682 } 3683 status = errorParams[j].substring("code=".length()); 3684 } 3685 } 3686 3687 if (path == null || path.length() == 0) { 3688 _logger.log(Level.WARNING, 3689 "webcontainer.sendErrorMissingPath", 3690 propValue); 3691 } 3692 3693 errorPage = new ErrorPage(); 3694 errorPage.setLocation(path); 3695 errorPage.setErrorCode(status); 3696 errorPage.setReason(reason); 3697 3698 vs.addErrorPage(errorPage); 3699 } 3700 3701 } 3702 3703 3704 3713 private String getInstanceClassPath(InstanceEnvironment instanceEnv) { 3714 3715 if (instanceEnv == null) { 3716 return null; 3717 } 3718 3719 StringBuffer sb = new StringBuffer (); 3720 3721 File libDir = new File (instanceEnv.getLibPath()); 3722 String libDirPath = libDir.getAbsolutePath(); 3723 3724 sb.append(libDirPath + File.separator + "classes"); 3726 sb.append(File.pathSeparator); 3727 3728 String [] files = libDir.list(); 3730 if (files != null) { 3731 for (int i=0; i<files.length; i++) { 3732 if (files[i].endsWith(".jar") || files[i].endsWith(".zip")) { 3733 sb.append(libDirPath + File.separator + files[i]); 3734 sb.append(File.pathSeparator); 3735 } 3736 } 3737 } 3738 3739 return sb.toString(); 3740 } 3741 3742 3743 3750 String getInstanceClassPath() { 3751 return this.instanceClassPath; 3752 } 3753 3754} 3755 3756 | Popular Tags |