1 23 24 29 30 package com.sun.enterprise.web; 31 32 import java.util.logging.Logger ; 33 import java.util.logging.Level ; 34 import com.sun.logging.LogDomains; 35 import com.sun.enterprise.config.ConfigContext; 36 import com.sun.enterprise.config.ConfigBean; 37 import com.sun.enterprise.config.ConfigException; 38 import com.sun.enterprise.server.ApplicationServer; 39 import com.sun.enterprise.server.ServerContext; 40 import com.sun.enterprise.web.session.PersistenceType; 41 42 import com.sun.enterprise.config.serverbeans.Applications; 43 import com.sun.enterprise.config.serverbeans.AvailabilityService; 44 import com.sun.enterprise.config.serverbeans.Cluster; 45 import com.sun.enterprise.config.serverbeans.ClusterHelper; 46 import com.sun.enterprise.config.serverbeans.Config; 47 import com.sun.enterprise.config.serverbeans.Domain; 48 import com.sun.enterprise.config.serverbeans.ElementProperty; 49 import com.sun.enterprise.config.serverbeans.J2eeApplication; 50 import com.sun.enterprise.config.serverbeans.JdbcResource; 51 import com.sun.enterprise.config.serverbeans.JdbcConnectionPool; 52 import com.sun.enterprise.config.serverbeans.ManagerProperties; 53 import com.sun.enterprise.config.serverbeans.Resources; 54 import com.sun.enterprise.config.serverbeans.Server; 55 import com.sun.enterprise.config.serverbeans.ServerHelper; 56 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 57 import com.sun.enterprise.config.serverbeans.SessionConfig; 58 import com.sun.enterprise.config.serverbeans.SessionManager; 59 import com.sun.enterprise.config.serverbeans.SessionProperties; 60 import com.sun.enterprise.config.serverbeans.StoreProperties; 61 import com.sun.enterprise.config.serverbeans.WebContainerAvailability; 62 63 import com.sun.enterprise.util.uuid.UuidGenerator; 64 import com.sun.enterprise.util.uuid.UuidGeneratorImpl; 65 66 67 public class ServerConfigLookup { 68 69 70 73 protected final String HADB_CONNECTION_URL_PREFIX = "jdbc:sun:hadb:"; 74 75 82 protected final String CLUSTER_ID_PROPERTY_NAME = 83 "cluster-id"; 84 85 89 protected final String STALE_SESSION_CHECKING_ENABLED_PROPERTY_NAME = 90 "stale-session-checking-enabled"; 91 92 99 protected final String DEFAULT_CLUSTER_ID = "cluster1"; 100 101 106 protected final String HADB_STORE_POOL_JNDI_NAME_PROPERTY_NAME = 107 "store-pool-jndi-name"; 108 109 113 protected final String DEFAULT_STORE_POOL_JNDI_NAME = "jdbc/hastore"; 114 115 120 protected final String HADB_MGMT_ENV_PATH_PROPERTY_NAME = 121 "hadb-mgmt-env-path"; 122 123 128 protected final String HADB_DATABASE_NAME_PROPERTY_NAME = 129 "hadb-database-name"; 130 131 135 protected final String UUID_GENERATOR_CLASS_PROPERTY_NAME = 136 "uuid-impl-class"; 137 138 141 protected final String DEFAULT_UUID_GENERATOR_CLASS = "com.sun.enterprise.util.uuid.UuidGeneratorImpl"; 142 143 151 protected final String EE_BUILDER_PATH_PROPERTY_NAME = 152 "ee-builder-path"; 153 154 155 158 protected final String DEFAULT_EE_BUILDER_PATH = "com.sun.enterprise.ee.web.initialization"; 159 160 165 protected final String HADB_HEALTH_CHECK_ENABLED_PROPERTY_NAME = 166 "hadb-health-check-enabled"; 167 168 171 protected final int DEFAULT_HA_STORE_HEALTHCHECK_INTERVAL_IN_SECONDS = 5; 172 173 178 protected final String USER_NAME = "User"; 179 180 185 protected final String PASSWORD = "Password"; 186 187 191 protected final String HADB_AGENT_PASSWORD = "ha-agent-password"; 192 193 198 protected ConfigContext _configContext = null; 199 200 201 public ServerConfigLookup() { 202 if (_logger == null) { 203 _logger = LogDomains.getLogger(LogDomains.WEB_LOGGER); 204 } 205 } 206 207 211 public ServerConfigLookup(ConfigContext configContext) { 212 this(); 213 _configContext = configContext; 214 } 215 216 218 222 protected ServerContext getServerContext() { 223 return ApplicationServer.getServerContext(); 224 } 225 226 230 protected ConfigContext getConfigContextDynamic() { 231 if (_configContext != null) { 232 return _configContext; 233 } else { 234 return getConfigContext(); 235 } 236 } 237 238 242 protected ConfigContext getConfigContext() { 243 ServerContext serverCtx = this.getServerContext(); 244 if(serverCtx == null) { 245 return null; 246 } 247 return serverCtx.getConfigContext(); 248 } 249 250 254 private Server getServerBean() { 255 Server serverBean = null; 256 260 ConfigContext configCtx = this.getConfigContext(); 261 try { 262 serverBean = ServerBeansFactory.getServerBean(configCtx); 263 } catch (ConfigException ex) {} 264 265 return serverBean; 266 } 267 268 272 private String getServerName() { 273 String result = null; 274 Server serverBean = this.getServerBean(); 275 if(serverBean != null) { 276 result = serverBean.getName(); 277 } 278 return result; 279 } 280 281 285 public String getClusterName() { 286 String result = null; 287 291 ConfigContext configCtx = this.getConfigContext(); 292 293 String serverName = this.getServerName(); 294 if(serverName == null) { 295 return result; 296 } 297 boolean isClustered = false; 298 try { 299 isClustered = ServerHelper.isServerClustered(configCtx, serverName); 300 } catch (ConfigException ex) {} 301 if(!isClustered) { 302 result = serverName + "_nc"; return result; 304 } 305 Cluster cluster = null; 306 try { 307 cluster = ClusterHelper.getClusterForInstance(configCtx, serverName); 308 } catch (ConfigException ex) {} 309 if(cluster != null) { 310 result = cluster.getName(); 311 } 312 return result; 313 } 314 315 316 320 private Resources getResourcesBean() { 321 Resources resourcesBean = null; 322 Domain domainBean = null; 323 327 ConfigContext configCtx = this.getConfigContext(); 328 try { 329 domainBean = ServerBeansFactory.getDomainBean(configCtx); 330 if(domainBean != null) { 331 resourcesBean = domainBean.getResources(); 332 } 333 } catch (ConfigException ex) {} 334 335 return resourcesBean; 336 } 337 338 342 private Applications getApplicationsBean() { 343 Applications applicationsBean = null; 344 Domain domainBean = null; 345 349 ConfigContext configCtx = this.getConfigContext(); 350 try { 351 domainBean = ServerBeansFactory.getDomainBean(configCtx); 352 if(domainBean != null) { 353 applicationsBean = domainBean.getApplications(); 354 } 355 } catch (ConfigException ex) {} 356 357 return applicationsBean; 358 } 359 360 364 private Applications getApplicationsBeanDynamic() { 365 Applications applicationsBean = null; 366 Domain domainBean = null; 367 371 ConfigContext configCtx = this.getConfigContextDynamic(); 372 try { 373 domainBean = ServerBeansFactory.getDomainBean(configCtx); 374 if(domainBean != null) { 375 applicationsBean = domainBean.getApplications(); 376 } 377 } catch (ConfigException ex) {} 378 return applicationsBean; 379 } 380 381 385 private Config getConfigBean() { 386 Config configBean = null; 387 391 ConfigContext configCtx = this.getConfigContext(); 392 try { 393 configBean = ServerBeansFactory.getConfigBean(configCtx); 394 } catch (ConfigException ex) {} 395 396 return configBean; 397 } 398 399 403 private Config getConfigBeanDynamic() { 404 Config configBean = null; 405 ConfigContext configCtx = this.getConfigContextDynamic(); 406 try { 407 configBean = ServerBeansFactory.getConfigBean(configCtx); 408 } catch (ConfigException ex) {} 409 410 return configBean; 411 } 412 413 417 protected AvailabilityService getAvailabilityService() { 418 Config configBean = this.getConfigBean(); 419 if(configBean == null) { 420 return null; 421 } 422 return configBean.getAvailabilityService(); 423 } 424 425 429 protected AvailabilityService getAvailabilityServiceDynamic() { 430 Config configBean = this.getConfigBeanDynamic(); 431 if(configBean == null) { 432 return null; 433 } 434 return configBean.getAvailabilityService(); 435 } 436 437 441 private WebContainerAvailability getWebContainerAvailability() { 442 AvailabilityService availabilityServiceBean = this.getAvailabilityService(); 443 if(availabilityServiceBean == null) { 444 return null; 445 } 446 return availabilityServiceBean.getWebContainerAvailability(); 447 } 448 449 454 private ElementProperty[] getWebContainerAvailabilityProperties() { 455 WebContainerAvailability webContainerAvailabilityBean = 456 this.getWebContainerAvailability(); 457 if(webContainerAvailabilityBean == null) { 458 return new ElementProperty[0]; 459 } 460 return webContainerAvailabilityBean.getElementProperty(); 461 } 462 463 469 protected String getWebContainerAvailabilityPropertyString(String propName) { 470 String result = null; 471 WebContainerAvailability wcAvailabilityBean = this.getWebContainerAvailability(); 472 if( (wcAvailabilityBean != null) && (wcAvailabilityBean.sizeElementProperty() > 0) ) { 473 ElementProperty[] props = wcAvailabilityBean.getElementProperty(); 474 for (int i = 0; i < props.length; i++) { 475 String name = props[i].getAttributeValue("name"); 476 String value = props[i].getAttributeValue("value"); 477 if (name.equalsIgnoreCase(propName)) { 478 result = value; 479 } 480 } 481 } 482 return result; 483 } 484 485 491 protected String getWebContainerAvailabilityPropertyString(String propName, String defaultValue) { 492 String result = null; 493 WebContainerAvailability wcAvailabilityBean = this.getWebContainerAvailability(); 494 if( (wcAvailabilityBean != null) && (wcAvailabilityBean.sizeElementProperty() > 0) ) { 495 ElementProperty[] props = wcAvailabilityBean.getElementProperty(); 496 for (int i = 0; i < props.length; i++) { 497 String name = props[i].getAttributeValue("name"); 498 String value = props[i].getAttributeValue("value"); 499 if (name.equalsIgnoreCase(propName)) { 500 result = value; 501 } 502 } 503 } 504 if(result == null) { 505 result = defaultValue; 506 } 507 return result; 508 } 509 510 516 protected int getWebContainerAvailabilityPropertyInt(String propName, int defaultValue) { 517 int returnValue = defaultValue; 518 String returnValueString = null; 519 WebContainerAvailability wcAvailabilityBean = this.getWebContainerAvailability(); 520 if( (wcAvailabilityBean != null) && (wcAvailabilityBean.sizeElementProperty() > 0) ) { 521 ElementProperty[] props = wcAvailabilityBean.getElementProperty(); 522 for (int i = 0; i < props.length; i++) { 523 String name = props[i].getAttributeValue("name"); 524 String value = props[i].getAttributeValue("value"); 525 if (name.equalsIgnoreCase(propName)) { 526 returnValueString = value; 527 } 528 } 529 } 530 if(returnValueString != null) { 531 try 532 { 533 returnValue = (Integer.valueOf(returnValueString)).intValue(); 534 } catch (NumberFormatException ex) { 535 if(_logger.isLoggable(Level.FINEST)) { 536 _logger.finest("Using Default Value = " 537 + defaultValue); 538 } 539 } 540 } 541 return returnValue; 542 } 543 544 private com.sun.enterprise.config.serverbeans.WebModule getWebModuleByContextRoot(String contextRoot) { 545 com.sun.enterprise.config.serverbeans.WebModule result = null; 546 Applications applicationsBean = this.getApplicationsBeanDynamic(); 547 if(applicationsBean == null) { 548 return null; 549 } 550 com.sun.enterprise.config.serverbeans.WebModule[] webModules = 551 applicationsBean.getWebModule(); 552 for(int i=0; i<webModules.length; i++) { 553 com.sun.enterprise.config.serverbeans.WebModule nextWebModule = 554 webModules[i]; 555 String nextContextRoot = nextWebModule.getContextRoot(); 556 if(nextContextRoot != null && nextContextRoot.equalsIgnoreCase(contextRoot)) { 557 result = nextWebModule; 558 } 559 } 560 return result; 561 } 562 563 private boolean getWebModuleAvailability(String contextRoot, boolean inheritedValue) { 564 com.sun.enterprise.config.serverbeans.WebModule webModule = 565 this.getWebModuleByContextRoot(contextRoot); 566 if(webModule == null) { 567 return false; 569 } 571 581 return webModule.isAvailabilityEnabled(); 582 } 583 584 private J2eeApplication getJ2eeApplicationByName(String appName) { 585 J2eeApplication result = null; 586 Applications applicationsBean = this.getApplicationsBeanDynamic(); 587 if(applicationsBean == null) { 588 return null; 589 } 590 return applicationsBean.getJ2eeApplicationByName(appName); 591 } 592 593 private boolean getJ2eeApplicationAvailability(String appName, boolean inheritedValue) { 594 J2eeApplication j2eeApp = 595 this.getJ2eeApplicationByName(appName); 596 if(_logger.isLoggable(Level.FINEST)) { 597 _logger.finest("ServerConfigLookup>>getJ2eeApplicationAvailability j2eeApp = " + j2eeApp); 598 } 599 if(j2eeApp == null) { 601 return false; 604 } 605 614 return j2eeApp.isAvailabilityEnabled(); 615 } 616 617 619 623 public PersistenceType getPersistenceTypeFromConfig() { 624 if(_logger.isLoggable(Level.FINEST)) { 625 _logger.finest("in ServerConfigLookup>>getPersistenceTypeFromConfig"); 626 } 627 String persistenceTypeString = null; 628 PersistenceType persistenceType = null; 629 630 WebContainerAvailability webContainerAvailabilityBean = 631 this.getWebContainerAvailability(); 632 if(webContainerAvailabilityBean == null) { 633 return null; 634 } 635 persistenceTypeString = webContainerAvailabilityBean.getPersistenceType(); 636 637 if(persistenceTypeString != null) { 639 persistenceType = PersistenceType.parseType(persistenceTypeString); 640 } 641 if(persistenceType != null) { 642 if(_logger.isLoggable(Level.FINEST)) { 643 _logger.finest("SERVER.XML persistenceType= " + persistenceType.getType()); 644 } 645 } else { 646 if(_logger.isLoggable(Level.FINEST)) { 647 _logger.finest("SERVER.XML persistenceType missing"); 648 } 649 } 650 return persistenceType; 651 } 652 653 658 public String getPersistenceFrequencyFromConfig() { 659 if(_logger.isLoggable(Level.FINEST)) { 660 _logger.finest("in ServerConfigLookup>>getPersistenceFrequencyFromConfig"); 661 } 662 663 WebContainerAvailability webContainerAvailabilityBean = 664 this.getWebContainerAvailability(); 665 if(webContainerAvailabilityBean == null) { 666 return null; 667 } 668 return webContainerAvailabilityBean.getPersistenceFrequency(); 669 } 670 671 672 677 public String getPersistenceScopeFromConfig() { 678 if(_logger.isLoggable(Level.FINEST)) { 679 _logger.finest("in ServerConfigLookup>>getPersistenceScopeFromConfig"); 680 } 681 WebContainerAvailability webContainerAvailabilityBean = 682 this.getWebContainerAvailability(); 683 if(webContainerAvailabilityBean == null) { 684 return null; 685 } 686 return webContainerAvailabilityBean.getPersistenceScope(); 687 } 688 689 693 public boolean getStaleSessionCheckingFromConfig() { 694 if(_logger.isLoggable(Level.FINEST)) { 695 _logger.finest("in ServerConfigLookup>>getStaleSessionCheckingFromConfig"); 696 } 697 String staleSessionCheckingEnabledString = 698 this.getWebContainerAvailabilityPropertyString(STALE_SESSION_CHECKING_ENABLED_PROPERTY_NAME, "false"); 699 Boolean bool = this.toBoolean(staleSessionCheckingEnabledString); 700 if(bool == null) { 701 return false; 702 } else { 703 return bool.booleanValue(); 704 } 705 } 706 707 711 public String getClusterIdFromConfig() { 712 if(_logger.isLoggable(Level.FINEST)) { 713 _logger.finest("in ServerConfigLookup>>getClusterIdFromConfig"); 714 } 715 return this.getWebContainerAvailabilityPropertyString(CLUSTER_ID_PROPERTY_NAME, DEFAULT_CLUSTER_ID); 716 } 718 719 723 public boolean getAvailabilityEnabledFromConfig() { 724 if(_logger.isLoggable(Level.FINEST)) { 725 _logger.finest("in ServerConfigLookup>>getAvailabilityEnabledFromConfig"); 726 } 727 AvailabilityService as = this.getAvailabilityService(); 728 if(as == null) { 729 if(_logger.isLoggable(Level.FINEST)) { 730 _logger.finest("AvailabilityService was not defined - check domain.xml"); 731 } 732 return false; 733 } 734 return as.isAvailabilityEnabled(); 735 } 736 737 745 public boolean calculateWebAvailabilityEnabledFromConfig(String contextRoot, String j2eeAppName) { 746 if(_logger.isLoggable(Level.FINEST)) { 747 _logger.finest("in ServerConfigLookup>>calculateWebAvailabilityEnabledFromConfig"); 748 } 749 boolean globalAvailability = 751 this.getAvailabilityEnabledFromConfig(); 752 if(_logger.isLoggable(Level.FINEST)) { 753 _logger.finest("globalAvailability = " + globalAvailability); 754 } 755 boolean webContainerAvailability = 758 this.getWebContainerAvailabilityEnabledFromConfig(globalAvailability); 759 if(_logger.isLoggable(Level.FINEST)) { 760 _logger.finest("webContainerAvailability = " + webContainerAvailability); 761 } 762 if(j2eeAppName == null || "null".equals(j2eeAppName)) { 765 boolean webModuleAvailability = 767 this.getWebModuleAvailability(contextRoot, webContainerAvailability); 768 if(_logger.isLoggable(Level.FINEST)) { 769 _logger.finest("webModuleAvailability = " + webModuleAvailability); 770 } 771 return globalAvailability 773 && webContainerAvailability 774 && webModuleAvailability; 775 } else { 776 boolean j2eeApplicationAvailability = 778 this.getJ2eeApplicationAvailability(j2eeAppName, webContainerAvailability); 779 if(_logger.isLoggable(Level.FINEST)) { 780 _logger.finest("j2eeApplicationAvailability = " + j2eeApplicationAvailability); 781 } 782 return globalAvailability 784 && webContainerAvailability 785 && j2eeApplicationAvailability; 786 } 787 } 788 789 793 public boolean getWebContainerAvailabilityEnabledFromConfig() { 794 boolean globalAvailabilityEnabled = this.getAvailabilityEnabledFromConfig(); 795 if(_logger.isLoggable(Level.FINEST)) { 796 _logger.finest("in ServerConfigLookup>>getWebContainerAvailabilityEnabledFromConfig"); 797 } 798 WebContainerAvailability was = this.getWebContainerAvailability(); 799 if(was == null) { 800 if(_logger.isLoggable(Level.FINEST)) { 801 _logger.finest("WebContainerAvailability was not defined - check domain.xml"); 802 } 803 return globalAvailabilityEnabled; 804 } 805 806 String wasString = was.getAvailabilityEnabled(); 807 Boolean bool = this.toBoolean(wasString); 808 if(bool == null) { 809 return globalAvailabilityEnabled; 810 } else { 811 return bool.booleanValue(); 812 } 813 } 814 815 819 public boolean getWebContainerAvailabilityEnabledFromConfig(boolean inheritedValue) { 820 if(_logger.isLoggable(Level.FINEST)) { 822 _logger.finest("in ServerConfigLookup>>getWebContainerAvailabilityEnabledFromConfig"); 823 } 824 WebContainerAvailability was = this.getWebContainerAvailability(); 825 if(was == null) { 826 if(_logger.isLoggable(Level.FINEST)) { 827 _logger.finest("WebContainerAvailability was not defined - check domain.xml"); 828 } 829 return inheritedValue; 830 } 831 832 String wasString = was.getAvailabilityEnabled(); 833 Boolean bool = this.toBoolean(wasString); 834 if(bool == null) { 835 return inheritedValue; 836 } else { 837 return bool.booleanValue(); 838 } 839 } 840 841 845 protected Boolean toBoolean(String value){ 846 if(value == null) return null; 847 848 if (value.equalsIgnoreCase("true")) 849 return Boolean.TRUE; 850 if (value.equalsIgnoreCase("yes")) 851 return Boolean.TRUE; 852 if (value.equalsIgnoreCase("on") ) 853 return Boolean.TRUE; 854 if (value.equalsIgnoreCase("1")) 855 return Boolean.TRUE; 856 857 return Boolean.FALSE; 858 } 859 860 866 public String getStorePoolJndiNameFromConfig() { 867 if(_logger.isLoggable(Level.FINEST)) { 868 _logger.finest("in ServerConfigLookup>>getStorePoolJndiNameFromConfig"); 869 } 870 String result = DEFAULT_STORE_POOL_JNDI_NAME; 871 AvailabilityService as = this.getAvailabilityService(); 872 if(as == null) { 873 return result; 874 } 875 String storePoolJndiName = as.getStorePoolName(); 876 if(storePoolJndiName != null) { 877 result = storePoolJndiName; 878 } 879 return result; 880 } 881 882 886 public String getHaStorePoolJndiNameFromConfig() { 887 if(_logger.isLoggable(Level.FINEST)) { 888 _logger.finest("in ServerConfigLookup>>getHaStorePoolJndiNameFromConfig"); 889 } 890 String result = this.getStorePoolJndiNameFromConfig(); 892 WebContainerAvailability webContainerAvailabilityBean = 893 this.getWebContainerAvailability(); 894 if(webContainerAvailabilityBean == null) { 895 return result; 896 } 897 String result2 = webContainerAvailabilityBean.getHttpSessionStorePoolName(); 898 if(result2 != null) { 899 result = result2; 900 } 901 return result; 902 } 903 904 909 public boolean getHadbHealthCheckFromConfig() { 910 AvailabilityService as = this.getAvailabilityService(); 911 if(as == null) { 912 return false; 913 } 914 return as.isHaStoreHealthcheckEnabled(); 915 } 916 917 922 public boolean getHadbHealthCheckFromConfigDynamic() { 923 AvailabilityService as = this.getAvailabilityServiceDynamic(); 924 if(as == null) { 925 return false; 926 } 927 return as.isHaStoreHealthcheckEnabled(); 928 } 929 930 933 public boolean getSsoFailoverEnabledFromConfig() { 934 WebContainerAvailability webContainerAvailabilityBean = 935 this.getWebContainerAvailability(); 936 if(webContainerAvailabilityBean == null) { 937 return false; 938 } 939 return webContainerAvailabilityBean.isSsoFailoverEnabled(); 940 } 941 942 947 public String getHadbMgmtEnvPathFromConfig() { 948 return this.getWebContainerAvailabilityPropertyString(HADB_MGMT_ENV_PATH_PROPERTY_NAME, null); 949 } 951 952 959 protected String getAvailabilityServicePropertyString(String propName) { 960 String result = null; 961 AvailabilityService availabilityServiceBean = this.getAvailabilityService(); 962 if( (availabilityServiceBean != null) && (availabilityServiceBean.sizeElementProperty() > 0) ) { 963 ElementProperty[] props = availabilityServiceBean.getElementProperty(); 964 for (int i = 0; i < props.length; i++) { 965 String name = props[i].getAttributeValue("name"); 966 String value = props[i].getAttributeValue("value"); 967 if (name.equalsIgnoreCase(propName)) { 968 result = value; 969 } 970 } 971 } 972 return result; 973 } 974 975 980 public String getHadbDatabaseNameFromConfig() { 981 AvailabilityService as = this.getAvailabilityService(); 982 if(as == null) { 983 return null; 984 } 985 return as.getHaStoreName(); 986 } 987 988 993 public String getHadbDatabaseNameFromConfigDynamic() { 994 AvailabilityService as = this.getAvailabilityServiceDynamic(); 995 if(as == null) { 996 return null; 997 } 998 return as.getHaStoreName(); 999 } 1000 1001 1006 public String getHadbAgentPasswordFromConfig() { 1007 AvailabilityService as = this.getAvailabilityService(); 1008 if(as == null) { 1009 return null; 1010 } 1011 return as.getHaAgentPassword(); 1012 } 1013 1014 1019 1024 1025 1030 public String getHaStoreHealthcheckIntervalInSecondsStringFromConfig() { 1031 AvailabilityService as = this.getAvailabilityService(); 1032 if(as == null) { 1033 return null; 1034 } 1035 return as.getHaStoreHealthcheckIntervalInSeconds(); 1036 } 1037 1038 1044 public int getHaStoreHealthcheckIntervalInSecondsFromConfig() { 1045 int candidateReturnValue = -1; 1046 int returnValue 1047 = DEFAULT_HA_STORE_HEALTHCHECK_INTERVAL_IN_SECONDS; 1048 String returnValueString = 1049 this.getHaStoreHealthcheckIntervalInSecondsStringFromConfig(); 1050 if(returnValueString != null) { 1051 try 1052 { 1053 candidateReturnValue = (Integer.valueOf(returnValueString)).intValue(); 1054 } catch (NumberFormatException ex) { 1055 if(_logger.isLoggable(Level.FINEST)) { 1056 _logger.finest("Using Default Value = " + DEFAULT_HA_STORE_HEALTHCHECK_INTERVAL_IN_SECONDS); 1057 } 1058 } 1059 } 1060 if(candidateReturnValue > 0) { 1062 returnValue = candidateReturnValue; 1063 } 1064 return returnValue; 1065 } 1066 1067 1072 public String getHaStoreHealthcheckIntervalInSecondsStringFromConfigDynamic() { 1073 AvailabilityService as = this.getAvailabilityServiceDynamic(); 1074 if(as == null) { 1075 return null; 1076 } 1077 return as.getHaStoreHealthcheckIntervalInSeconds(); 1078 } 1079 1080 1086 public int getHaStoreHealthcheckIntervalInSecondsFromConfigDynamic() { 1087 int candidateReturnValue = -1; 1088 int returnValue 1089 = DEFAULT_HA_STORE_HEALTHCHECK_INTERVAL_IN_SECONDS; 1090 String returnValueString = 1091 this.getHaStoreHealthcheckIntervalInSecondsStringFromConfigDynamic(); 1092 if(returnValueString != null) { 1093 try 1094 { 1095 candidateReturnValue = (Integer.valueOf(returnValueString)).intValue(); 1096 } catch (NumberFormatException ex) { 1097 if(_logger.isLoggable(Level.FINEST)) { 1098 _logger.finest("Using Default Value = " + DEFAULT_HA_STORE_HEALTHCHECK_INTERVAL_IN_SECONDS); 1099 } 1100 } 1101 } 1102 if(candidateReturnValue > 0) { 1104 returnValue = candidateReturnValue; 1105 } 1106 return returnValue; 1107 } 1108 1109 1114 public String getHadbAgentPortFromConfig() { 1115 AvailabilityService as = this.getAvailabilityService(); 1116 if(as == null) { 1117 return null; 1118 } 1119 return as.getHaAgentPort(); 1120 } 1121 1122 1127 public String getHadbAgentPortFromConfigDynamic() { 1128 AvailabilityService as = this.getAvailabilityServiceDynamic(); 1129 if(as == null) { 1130 return null; 1131 } 1132 return as.getHaAgentPort(); 1133 } 1134 1135 1138 public String getHadbAgentConnectionURLFromConfig() { 1139 String url = null; 1140 StringBuffer sb = new StringBuffer (); 1141 String hostsString = this.getHadbAgentHostsFromConfig(); 1142 String portString = this.getHadbAgentPortFromConfig(); 1143 if(hostsString != null && portString != null) { 1144 sb.append(hostsString); 1145 sb.append(":"); 1146 sb.append(portString); 1147 url = sb.toString(); 1148 } else { 1149 url = null; 1150 } 1151 return url; 1152 } 1153 1154 1157 public String getHadbAgentConnectionURLFromConfigDynamic() { 1158 String url = null; 1159 StringBuffer sb = new StringBuffer (); 1160 String hostsString = this.getHadbAgentHostsFromConfigDynamic(); 1161 String portString = this.getHadbAgentPortFromConfigDynamic(); 1162 if(hostsString != null && portString != null) { 1163 sb.append(hostsString); 1164 sb.append(":"); 1165 sb.append(portString); 1166 url = sb.toString(); 1167 } else { 1168 url = null; 1169 } 1170 return url; 1171 } 1172 1173 1178 public String getHadbAgentHostsFromConfig() { 1179 AvailabilityService as = this.getAvailabilityService(); 1180 if(as == null) { 1181 return null; 1182 } 1183 return as.getHaAgentHosts(); 1184 } 1185 1186 1191 public String getHadbAgentHostsFromConfigDynamic() { 1192 AvailabilityService as = this.getAvailabilityServiceDynamic(); 1193 if(as == null) { 1194 return null; 1195 } 1196 return as.getHaAgentHosts(); 1197 } 1198 1199 1201 1207 public String getEEBuilderPathFromConfig() { 1208 return this.getWebContainerAvailabilityPropertyString(EE_BUILDER_PATH_PROPERTY_NAME, DEFAULT_EE_BUILDER_PATH); 1209 } 1211 1212 1216 public String getUuidGeneratorImplClassFromConfig() { 1217 if(_logger.isLoggable(Level.FINEST)) { 1218 _logger.finest("in ServerConfigLookup>>getUuidGeneratorImplClassFromConfig"); 1219 } 1220 return this.getWebContainerAvailabilityPropertyString(UUID_GENERATOR_CLASS_PROPERTY_NAME, DEFAULT_UUID_GENERATOR_CLASS); 1221 } 1223 1224 1228 public UuidGenerator getUuidGeneratorFromConfig() { 1229 UuidGenerator generator = new UuidGeneratorImpl(); 1230 String generatorImplClassName = 1231 this.getUuidGeneratorImplClassFromConfig(); 1232 try { 1233 generator = 1234 (UuidGenerator) (Class.forName(generatorImplClassName)).newInstance(); 1235 } catch (Exception ex) { 1236 } 1237 return generator; 1238 } 1239 1240 1244 public String getServerConfigValue(String xpath, String defaultValue ) { 1245 if(_logger.isLoggable(Level.FINEST)) { 1246 _logger.finest("in ServerConfigLookup>>getServerConfigValue:xpath=" + xpath 1247 + " defaultValue= " + defaultValue); 1248 } 1249 1250 ServerContext serverCtx = ApplicationServer.getServerContext(); 1251 if(serverCtx == null) 1253 return defaultValue; 1254 ConfigContext configCtx = serverCtx.getConfigContext(); 1255 ConfigBean configBean = null; 1256 String returnValueString = null; 1257 1258 String returnValue = defaultValue; 1259 try { 1260 configBean = 1261 configCtx.exactLookup(xpath); 1262 } catch (ConfigException ex) { 1263 } 1264 if(configBean != null) { 1265 returnValueString = configBean.getAttributeValue("value"); 1266 } 1267 if(returnValueString != null) { 1268 returnValue = returnValueString; 1269 } 1270 if(_logger.isLoggable(Level.FINEST)) { 1271 _logger.finest("RETURNED CONFIG VALUE FOR XPATH:" + xpath + 1272 " = " + returnValue); 1273 } 1274 1275 return returnValue; 1276 } 1277 1278 1282 public int getServerConfigValue(String xpath, int defaultValue ) { 1283 if(_logger.isLoggable(Level.FINEST)) { 1284 _logger.finest("in getServerConfigValue:xpath=" + xpath 1285 + " defaultValue= " + defaultValue); 1286 } 1287 1291 ConfigContext configCtx = this.getConfigContext(); 1292 ConfigBean configBean = null; 1293 String returnValueString = null; 1294 1295 int returnValue = defaultValue; 1296 try { 1297 configBean = 1298 configCtx.exactLookup(xpath); 1299 } catch (ConfigException ex) { 1300 } 1301 if(configBean != null) { 1302 returnValueString = configBean.getAttributeValue("value"); 1303 } 1304 if(returnValueString != null) { 1305 try { 1306 returnValue = (Integer.valueOf(returnValueString)).intValue(); 1307 } catch (NumberFormatException ex) { 1308 _logger.finest("Using Default Value = " 1309 + defaultValue); 1310 } 1311 } 1312 if(_logger.isLoggable(Level.FINEST)) { 1313 _logger.finest("RETURNED CONFIG VALUE FOR XPATH:" + xpath + 1314 " = " + returnValue); 1315 } 1316 1317 return returnValue; 1318 } 1319 1320 1325 public SessionManager getInstanceSessionManager() { 1326 Config configBean = this.getConfigBean(); 1327 if(configBean == null) { 1328 return null; 1329 } 1330 1331 com.sun.enterprise.config.serverbeans.WebContainer webContainerBean 1332 = configBean.getWebContainer(); 1333 if(webContainerBean == null) { 1334 return null; 1335 } 1336 1337 SessionConfig sessionConfigBean = webContainerBean.getSessionConfig(); 1338 if(sessionConfigBean == null) { 1339 return null; 1340 } 1341 1342 com.sun.enterprise.config.serverbeans.SessionManager smBean = 1343 sessionConfigBean.getSessionManager(); 1344 return smBean; 1345 } 1346 1347 1352 public ManagerProperties getInstanceSessionManagerManagerProperties() { 1353 1354 SessionManager smBean = this.getInstanceSessionManager(); 1355 if(smBean == null) { 1356 return null; 1357 } 1358 return smBean.getManagerProperties(); 1359 } 1360 1361 1366 public StoreProperties getInstanceSessionManagerStoreProperties() { 1367 1368 SessionManager smBean = this.getInstanceSessionManager(); 1369 if(smBean == null) { 1370 return null; 1371 } 1372 return smBean.getStoreProperties(); 1373 } 1374 1375 1380 public SessionProperties getInstanceSessionProperties() { 1381 Config configBean = this.getConfigBean(); 1382 if(configBean == null) { 1383 return null; 1384 } 1385 1386 com.sun.enterprise.config.serverbeans.WebContainer webContainerBean 1387 = configBean.getWebContainer(); 1388 if(webContainerBean == null) { 1389 return null; 1390 } 1391 1392 SessionConfig sessionConfigBean = webContainerBean.getSessionConfig(); 1393 if(sessionConfigBean == null) { 1394 return null; 1395 } 1396 1397 com.sun.enterprise.config.serverbeans.SessionProperties spBean = 1398 sessionConfigBean.getSessionProperties(); 1399 return spBean; 1400 } 1401 1402 1405 public String getConnectionUserFromConfig() { 1406 1407 String user = null; 1408 JdbcConnectionPool pool = this.getHadbJdbcConnectionPoolFromConfig(); 1409 if(pool == null) { 1410 return null; 1411 } 1412 if (pool.sizeElementProperty() > 0) { 1413 ElementProperty[] props = pool.getElementProperty(); 1414 for (int i = 0; i < props.length; i++) { 1415 String name = props[i].getAttributeValue("name"); 1416 String value = props[i].getAttributeValue("value"); 1417 if (name.equalsIgnoreCase(USER_NAME)) { 1418 user = value; 1420 } 1421 } 1422 } 1423 if(_logger.isLoggable(Level.FINEST)) { 1424 _logger.finest("IN NEW getConnectionUserFromConfig: user=" + user); 1425 } 1426 return user; 1427 } 1428 1429 1432 public String getConnectionPasswordFromConfig() { 1433 1434 String password = null; 1435 JdbcConnectionPool pool = this.getHadbJdbcConnectionPoolFromConfig(); 1436 if(pool == null) 1437 return null; 1438 if (pool.sizeElementProperty() > 0) { 1439 ElementProperty[] props = pool.getElementProperty(); 1440 for (int i = 0; i < props.length; i++) { 1441 String name = props[i].getAttributeValue("name"); 1442 String value = props[i].getAttributeValue("value"); 1443 if (name.equalsIgnoreCase(PASSWORD)) { 1444 password = value; 1446 } 1447 } 1448 } 1449 if(_logger.isLoggable(Level.FINEST)) { 1450 _logger.finest("IN NEW getConnectionPasswordFromConfig: password=" + password); 1451 } 1452 return password; 1453 } 1454 1455 1458 public String getConnectionURLFromConfig() { 1459 String url = null; 1460 StringBuffer sb = new StringBuffer (); 1461 JdbcConnectionPool pool = this.getHadbJdbcConnectionPoolFromConfig(); 1462 if(pool == null) 1463 return null; 1464 if (pool.sizeElementProperty() > 0) { 1465 ElementProperty[] props = pool.getElementProperty(); 1466 for (int i = 0; i < props.length; i++) { 1467 String name = props[i].getAttributeValue("name"); 1468 String value = props[i].getAttributeValue("value"); 1469 if (name.equalsIgnoreCase("serverList")) { 1470 sb.append(HADB_CONNECTION_URL_PREFIX); 1471 sb.append(value); 1472 url = sb.toString(); 1473 } 1474 } 1475 } 1476 if(_logger.isLoggable(Level.FINEST)) { 1477 _logger.finest("IN NEW getConnectionURLFromConfig: url=" + url); 1478 } 1479 return url; 1480 } 1481 1482 1486 public JdbcConnectionPool getHadbJdbcConnectionPoolFromConfig() { 1487 String storePoolJndiName = this.getHaStorePoolJndiNameFromConfig(); 1488 if(storePoolJndiName == null) 1489 return null; 1490 1491 Resources resources = this.getResourcesBean(); 1492 JdbcResource jdbcResource = 1493 resources.getJdbcResourceByJndiName(storePoolJndiName); 1494 if(jdbcResource == null) { 1495 return null; 1496 } 1497 1498 String poolName = jdbcResource.getPoolName(); 1499 JdbcConnectionPool pool = 1500 resources.getJdbcConnectionPoolByName(poolName); 1501 return pool; 1502 } 1503 1504 1505 1508 public String getHadbJdbcConnectionPoolNameFromConfig() { 1509 1510 String storePoolJndiName = this.getHaStorePoolJndiNameFromConfig(); 1511 if(storePoolJndiName == null) 1512 return null; 1513 1514 Resources resources = this.getResourcesBean(); 1515 JdbcResource jdbcResource = 1516 resources.getJdbcResourceByJndiName(storePoolJndiName); 1517 if(jdbcResource == null) 1518 return null; 1519 String poolName = jdbcResource.getPoolName(); 1520 return poolName; 1521 } 1522 1523 1526 private static Logger _logger = null; 1527 1528} 1529 | Popular Tags |