1 23 28 29 package com.sun.enterprise.config.serverbeans; 30 31 import com.sun.enterprise.config.ConfigContext; 32 import com.sun.enterprise.config.ConfigException; 33 34 import com.sun.enterprise.security.store.IdentityManager; 35 36 import com.sun.enterprise.admin.util.JMXConnectorConfig; 37 38 import java.util.ArrayList ; 39 import java.util.Map ; 40 import java.util.HashMap ; 41 import java.io.IOException ; 42 43 import javax.management.MBeanServerConnection ; 44 import javax.management.remote.JMXConnector ; 45 import javax.management.remote.JMXConnectorFactory ; 46 import javax.management.remote.JMXServiceURL ; 47 import com.sun.enterprise.admin.jmx.remote.server.rmi.JmxServiceUrlFactory; 48 import com.sun.enterprise.util.SystemPropertyConstants; 49 import java.net.InetAddress ; 50 51 52 60 public class ServerHelper extends ConfigAPIHelper { 61 62 public static final String ADMIN_HTTP_LISTNER_ID = "admin-listener"; 63 64 67 public static String getServersAsString(Server[] servers) 68 { 69 String result = ""; 70 for (int i = 0; i < servers.length; i++) { 71 result += servers[i].getName(); 72 if (i < servers.length - 1) { 73 result += ","; 74 } 75 } 76 return result; 77 } 78 79 83 public static Server[] getServersInDomain(ConfigContext configContext) 84 throws ConfigException 85 { 86 final Domain domain = getDomainConfigBean(configContext); 87 return domain.getServers().getServer(); 88 } 89 90 93 public static boolean isAServer(ConfigContext configContext, String instanceName) 94 throws ConfigException 95 { 96 final Domain domain = getDomainConfigBean(configContext); 97 final Server server = domain.getServers().getServerByName(instanceName); 98 return (server != null ? true : false); 99 } 100 101 106 public static Server getServerByName(ConfigContext configContext, String instanceName) 107 throws ConfigException 108 { 109 final Domain domain = getDomainConfigBean(configContext); 110 final Server server = domain.getServers().getServerByName(instanceName); 111 if (server == null) { 112 throw new ConfigException(_strMgr.getString("noSuchInstance", 113 instanceName)); 114 } 115 return server; 116 } 117 118 public static Server getDAS(ConfigContext configContext) 119 throws ConfigException 120 { 121 Server[] servers = getServersInDomain(configContext); 123 Server das = null; 124 for (int i = 0; i < servers.length; i++) { 125 if (isDAS(configContext, servers[i])) { 126 if (das == null) { 127 das = servers[i]; 128 } else { 129 throw new ConfigException(_strMgr.getString("tooManyDASFound", das.getName(), 133 servers[i].getName())); 134 } 135 } 136 } 137 if (das == null) { 138 throw new ConfigException(_strMgr.getString("noDASFound")); 140 } 141 return das; 142 } 143 144 147 public static Server[] getServersReferencingConfig(ConfigContext configContext, String configName) 148 throws ConfigException 149 { 150 Config config = getConfigByName(configContext, configName); 152 153 Server[] servers = getServersInDomain(configContext); 155 ArrayList result = new ArrayList (); 156 for (int i = 0; i < servers.length; i++) { 157 if (servers[i].getConfigRef().equals(configName)) { 158 result.add(servers[i]); 159 } 160 } 161 return (Server[])result.toArray(new Server[result.size()]); 162 } 163 164 165 170 public static Server[] getStandAloneServers( 171 ConfigContext configContext, boolean excludeDASInstance) 172 throws ConfigException 173 { 174 Server[] servers = getServersInDomain(configContext); 175 ArrayList result = new ArrayList (); 176 for (int i = 0; i < servers.length; i++) { 177 if (isDAS(configContext, servers[i]) && excludeDASInstance) { 178 continue; 179 } 180 if (isServerStandAlone(configContext, servers[i].getName())) { 181 result.add(servers[i]); 182 } 183 } 184 return (Server[])result.toArray(new Server[result.size()]); 185 } 186 187 193 public static Server[] getUnclusteredServers( 194 ConfigContext configContext, boolean excludeDASInstance) 195 throws ConfigException 196 { 197 Server[] servers = getServersInDomain(configContext); 198 ArrayList result = new ArrayList (); 199 for (int i = 0; i < servers.length; i++) { 200 if (isDAS(configContext, servers[i]) && excludeDASInstance) { 201 continue; 202 } 203 if (!isServerClustered(configContext, servers[i])) { 204 result.add(servers[i]); 205 } 206 } 207 return (Server[])result.toArray(new Server[result.size()]); 208 } 209 210 214 public static Server[] getServersInCluster(ConfigContext configContext, 215 String clusterName) throws ConfigException 216 { 217 Cluster cluster = ClusterHelper.getClusterByName(configContext, clusterName); 219 220 ServerRef[] serverRefs = cluster.getServerRef(); 222 223 Server[] result = new Server[serverRefs.length]; 224 for (int i = 0; i < serverRefs.length; i++) { 225 try { 226 result[i] = getServerByName(configContext, serverRefs[i].getRef()); 227 } catch (ConfigException ex) { 228 throw new ConfigException(_strMgr.getString("noSuchClusterInstance", 229 clusterName, serverRefs[i].getRef())); 230 } 231 } 232 return result; 233 } 234 235 247 public static boolean isDAS(ConfigContext configContext, Server server) 248 throws ConfigException 249 { 250 if (server.getNodeAgentRef() == null) { 251 return true; 252 } 253 return false; 254 } 255 256 259 public static boolean isDAS(ConfigContext configContext, String instanceName) 260 throws ConfigException 261 { 262 final Domain domain = getDomainConfigBean(configContext); 263 final Server server = domain.getServers().getServerByName(instanceName); 264 return isDAS(configContext, server); 265 } 266 267 271 public static Server[] getServersOfANodeAgent(ConfigContext configContext, String agentName) 272 throws ConfigException 273 { 274 NodeAgent controller = NodeAgentHelper.getNodeAgentByName(configContext, agentName); 276 277 Server[] servers = getServersInDomain(configContext); 279 ArrayList result = new ArrayList (); 280 for (int i = 0; i < servers.length; i++) { 281 if (!isDAS(configContext, servers[i]) && 282 servers[i].getNodeAgentRef().equals(agentName)) 283 { 284 result.add(servers[i]); 285 } 286 } 287 return (Server[])result.toArray(new Server[result.size()]); 288 } 289 290 294 public static JmxConnector getServerSystemConnector(ConfigContext configContext, String instanceName) 295 throws ConfigException 296 { 297 final AdminService adminService = getAdminServiceForServer(configContext, instanceName); 299 300 final String systemConnectorName = adminService.getSystemJmxConnectorName(); 301 final JmxConnector connector = adminService.getJmxConnectorByName( 302 systemConnectorName); 303 if (connector == null) { 304 throw new ConfigException(_strMgr.getString("noInstanceSystemConnector", instanceName, 305 systemConnectorName)); 306 } 307 return connector; 308 } 309 310 314 public static JMXConnectorConfig getJMXConnectorInfo(ConfigContext configContext, String instanceName) 315 throws ConfigException 316 { 317 JmxConnector connector = ServerHelper.getServerSystemConnector( 319 configContext, instanceName); 320 321 326 String portAttribute = connector.getRawAttributeValue(ServerTags.PORT); 329 String port = new PropertyResolver(configContext, instanceName).resolve( 330 portAttribute); 331 332 333 Server server = ServerHelper.getServerByName(configContext, instanceName); 335 ElementProperty hostProp = null; 336 AdminService adminService = ServerHelper.getAdminServiceForServer( 337 configContext, instanceName); 338 339 if (ServerHelper.isDAS(configContext, server)) { hostProp = connector.getElementPropertyByName(HOST_PROPERTY_NAME); 344 } else { 345 final JmxConnector agentConnector = NodeAgentHelper.getNodeAgentSystemConnector( 350 configContext, server.getNodeAgentRef()); 351 hostProp = agentConnector.getElementPropertyByName(HOST_PROPERTY_NAME); 352 } 353 354 String adminUser = IdentityManager.getUser(); 355 String adminPassword = IdentityManager.getPassword(); 356 357 if (adminUser == null || adminPassword == null || hostProp == null) { 358 throw new ConfigException(_strMgr.getString("missingInstanceConnectorAuth", 359 instanceName)); 360 } 361 362 return new JMXConnectorConfig(hostProp.getValue(), port, 363 adminUser, adminPassword, connector.getProtocol()); 364 } 365 366 370 public static AdminService getAdminServiceForServer(ConfigContext configContext, String instanceName) 371 throws ConfigException 372 { 373 final Config config = getConfigForServer(configContext, instanceName); 374 375 final AdminService adminService = config.getAdminService(); 377 if (adminService == null) { 378 throw new ConfigException(_strMgr.getString("noAdminService", 379 config.getName(), instanceName)); 380 } 381 return adminService; 382 } 383 384 388 public static Config getConfigForServer(ConfigContext configContext, String instanceName) 389 throws ConfigException 390 { 391 final Server server = getServerByName(configContext, instanceName); 392 return getConfigByName(configContext, server.getConfigRef()); 393 } 394 395 398 public static boolean isServerClustered(ConfigContext configContext, Server server) 399 throws ConfigException 400 { 401 final String instanceName = server.getName(); 404 final Cluster[] clusters = ClusterHelper.getClustersInDomain(configContext); 405 for (int i = 0; i < clusters.length; i++) { 406 final ServerRef[] servers = clusters[i].getServerRef(); 407 for (int j = 0; j < servers.length; j++) { 408 if (servers[j].getRef().equals(instanceName)) { 409 return true; 412 } 413 } 414 } 415 return false; 416 } 417 418 421 public static boolean isServerClustered(ConfigContext configContext, String instanceName) 422 throws ConfigException 423 { 424 return isServerClustered(configContext, 425 getServerByName(configContext, instanceName)); 426 } 427 428 433 public static boolean isServerStandAlone(ConfigContext configContext, String instanceName) 434 throws ConfigException 435 { 436 final Server server = getServerByName(configContext, instanceName); 437 final String configName = server.getConfigRef(); 438 if (isConfigurationNameStandAlone(configName, instanceName)) { 439 if (!isServerClustered(configContext, server)) { 440 if (isConfigurationReferencedByServerOnly(configContext, configName, instanceName)) { 441 return true; 442 } 443 } 444 } 445 return false; 446 } 447 448 451 public static boolean serverReferencesApplication(ConfigContext configContext, 452 String instanceName, String appName) throws ConfigException 453 { 454 final Server server = getServerByName(configContext, instanceName); 455 return serverReferencesApplication(server, appName); 456 } 457 458 public static boolean serverReferencesApplication(Server server, String appName) 459 throws ConfigException 460 { 461 final ApplicationRef ref = server.getApplicationRefByRef(appName); 462 return (ref == null) ? false : true; 463 } 464 465 468 public static Server[] getServersReferencingApplication(ConfigContext configContext, String appName) 469 throws ConfigException 470 { 471 Server[] servers = getServersInDomain(configContext); 473 ArrayList result = new ArrayList (); 474 for (int i = 0; i < servers.length; i++) { 475 if (serverReferencesApplication(servers[i], appName)) { 476 result.add(servers[i]); 477 } 478 } 479 return (Server[])result.toArray(new Server[result.size()]); 480 } 481 482 public static boolean serverReferencesJdbcConPool(ConfigContext ctx, 483 String instanceName, String poolName) throws ConfigException 484 { 485 final Server server = getServerByName(ctx, instanceName); 486 return serverReferencesJdbcConPool(server, poolName); 487 } 488 489 public static boolean serverReferencesJdbcConPool(Server server, 490 String poolName) throws ConfigException 491 { 492 final ResourceRef ref = server.getResourceRefByRef(poolName); 493 return (ref == null) ? false : true; 494 } 495 496 497 500 public static boolean serverReferencesResource(ConfigContext configContext, 501 String instanceName, String resourceName) throws ConfigException 502 { 503 final Server server = getServerByName(configContext, instanceName); 504 return serverReferencesResource(server, resourceName); 505 } 506 507 public static boolean serverReferencesResource(Server server, 508 String resourceName) throws ConfigException 509 { 510 final ResourceRef ref = server.getResourceRefByRef(resourceName); 511 return (ref == null) ? false : true; 512 } 513 514 517 public static Server[] getServersReferencingResource(ConfigContext configContext, String resName) 518 throws ConfigException 519 { 520 Server[] servers = getServersInDomain(configContext); 522 ArrayList result = new ArrayList (); 523 for (int i = 0; i < servers.length; i++) { 524 if (serverReferencesResource(servers[i], resName)) { 525 result.add(servers[i]); 526 } 527 } 528 return (Server[])result.toArray(new Server[result.size()]); 529 } 530 531 542 public static Server[] getServersReferencingJdbcPool(ConfigContext ctx, 543 String poolName) throws ConfigException { 544 545 Server[] servers = getServersInDomain(ctx); 546 ArrayList result = new ArrayList (); 547 for (int i = 0; i < servers.length; i++) { 548 if (ResourceHelper.isJdbcPoolReferenced(ctx, poolName, 549 servers[i].getName())) { 550 result.add(servers[i]); 551 } 552 } 553 return (Server[])result.toArray(new Server[result.size()]); 554 } 555 556 569 public static Server[] getServersReferencingConnectorPool(ConfigContext ctx, 570 String poolName) throws ConfigException { 571 572 Server[] servers = getServersInDomain(ctx); 573 ArrayList result = new ArrayList (); 574 for (int i = 0; i < servers.length; i++) { 575 if (ResourceHelper.isConnectorPoolReferenced(ctx, poolName, 576 servers[i].getName())) { 577 result.add(servers[i]); 578 } 579 } 580 return (Server[])result.toArray(new Server[result.size()]); 581 } 582 583 586 public static ApplicationRef[] getApplicationReferences(ConfigContext configContext, 587 String serverName) throws ConfigException 588 { 589 final Server server = getServerByName(configContext, serverName); 590 if (server.getApplicationRef() == null) { 591 return new ApplicationRef[0]; 592 } else { 593 return server.getApplicationRef(); 594 } 595 } 596 597 600 public static ResourceRef[] getResourceReferences(ConfigContext configContext, 601 String serverName) throws ConfigException 602 { 603 final Server server = getServerByName(configContext, serverName); 604 if (server.getResourceRef() == null) { 605 return new ResourceRef[0]; 606 } else { 607 return server.getResourceRef(); 608 } 609 } 610 611 615 public static J2eeApplication[] getAssociatedJ2eeApplications( 616 ConfigContext ctx, String serverName) throws ConfigException { 617 618 ArrayList list = new ArrayList (); 619 Domain domain = (Domain) ctx.getRootConfigBean(); 620 Applications applications = domain.getApplications(); 621 622 Servers servers = domain.getServers(); 623 Server s = servers.getServerByName(serverName); 624 if (s != null) { 625 J2eeApplication[] j2eeApps = applications.getJ2eeApplication(); 626 for (int i=0; i<j2eeApps.length; i++) { 627 if (serverReferencesApplication(ctx, serverName, 628 j2eeApps[i].getName()) ) { 629 list.add(j2eeApps[i]); 630 } 631 } 632 } 633 634 J2eeApplication[] associatedApps = new J2eeApplication[list.size()]; 635 return ((J2eeApplication[]) list.toArray(associatedApps)); 636 } 637 638 public static J2eeApplication[] getUnAssociatedJ2eeApplications( 639 ConfigContext ctx, String serverName) throws ConfigException { 640 641 ArrayList list = new ArrayList (); 642 Domain domain = (Domain) ctx.getRootConfigBean(); 643 Applications applications = domain.getApplications(); 644 645 Servers servers = domain.getServers(); 646 Server s = servers.getServerByName(serverName); 647 if (s != null) { 648 J2eeApplication[] j2eeApps = applications.getJ2eeApplication(); 649 for (int i=0; i<j2eeApps.length; i++) { 650 if (!serverReferencesApplication(ctx, serverName, 651 j2eeApps[i].getName()) ) { 652 list.add(j2eeApps[i]); 653 } 654 } 655 } 656 657 J2eeApplication[] unassociatedApps = new J2eeApplication[list.size()]; 658 return ((J2eeApplication[]) list.toArray(unassociatedApps)); 659 } 660 661 665 public static EjbModule[] getAssociatedEjbModules( 666 ConfigContext ctx, String serverName) throws ConfigException { 667 668 ArrayList list = new ArrayList (); 669 Domain domain = (Domain) ctx.getRootConfigBean(); 670 Applications applications = domain.getApplications(); 671 672 Servers servers = domain.getServers(); 673 Server s = servers.getServerByName(serverName); 674 if (s != null) { 675 EjbModule[] ejbMods = applications.getEjbModule(); 676 for (int i=0; i<ejbMods.length; i++) { 677 if (serverReferencesApplication(ctx, serverName, 678 ejbMods[i].getName()) ) { 679 list.add(ejbMods[i]); 680 } 681 } 682 } 683 684 EjbModule[] associatedApps = new EjbModule[list.size()]; 685 return ((EjbModule[]) list.toArray(associatedApps)); 686 } 687 688 public static EjbModule[] getUnAssociatedEjbModules( 689 ConfigContext ctx, String serverName) throws ConfigException { 690 691 ArrayList list = new ArrayList (); 692 Domain domain = (Domain) ctx.getRootConfigBean(); 693 Applications applications = domain.getApplications(); 694 695 Servers servers = domain.getServers(); 696 Server s = servers.getServerByName(serverName); 697 if (s != null) { 698 EjbModule[] ejbMods = applications.getEjbModule(); 699 for (int i=0; i<ejbMods.length; i++) { 700 if (!serverReferencesApplication(ctx, serverName, 701 ejbMods[i].getName()) ) { 702 list.add(ejbMods[i]); 703 } 704 } 705 } 706 707 EjbModule[] unassociatedApps = new EjbModule[list.size()]; 708 return ((EjbModule[]) list.toArray(unassociatedApps)); 709 } 710 711 715 public static WebModule[] getAssociatedWebModules( 716 ConfigContext ctx, String serverName) throws ConfigException { 717 718 ArrayList list = new ArrayList (); 719 Domain domain = (Domain) ctx.getRootConfigBean(); 720 Applications applications = domain.getApplications(); 721 722 Servers servers = domain.getServers(); 723 Server s = servers.getServerByName(serverName); 724 if (s != null) { 725 WebModule[] webMods = applications.getWebModule(); 726 for (int i=0; i<webMods.length; i++) { 727 if (serverReferencesApplication(ctx, serverName, 728 webMods[i].getName()) ) { 729 list.add(webMods[i]); 730 } 731 } 732 } 733 734 WebModule[] associatedApps = new WebModule[list.size()]; 735 return ((WebModule[]) list.toArray(associatedApps)); 736 } 737 738 public static WebModule[] getUnAssociatedWebModules( 739 ConfigContext ctx, String serverName) throws ConfigException { 740 741 ArrayList list = new ArrayList (); 742 Domain domain = (Domain) ctx.getRootConfigBean(); 743 Applications applications = domain.getApplications(); 744 745 Servers servers = domain.getServers(); 746 Server s = servers.getServerByName(serverName); 747 if (s != null) { 748 WebModule[] webMods = applications.getWebModule(); 749 for (int i=0; i<webMods.length; i++) { 750 if (!serverReferencesApplication(ctx, serverName, 751 webMods[i].getName()) ) { 752 list.add(webMods[i]); 753 } 754 } 755 } 756 757 WebModule[] unassociatedApps = new WebModule[list.size()]; 758 return ((WebModule[]) list.toArray(unassociatedApps)); 759 } 760 761 public static ConnectorModule[] getUnAssociatedConnectorModules( 762 ConfigContext ctx, String serverName) throws ConfigException { 763 764 ArrayList list = new ArrayList (); 765 Domain domain = (Domain) ctx.getRootConfigBean(); 766 Applications applications = domain.getApplications(); 767 768 Servers servers = domain.getServers(); 769 Server s = servers.getServerByName(serverName); 770 if (s != null) { 771 ConnectorModule[] connMods = applications.getConnectorModule(); 772 for (int i=0; i<connMods.length; i++) { 773 if (!serverReferencesApplication(ctx, serverName, 774 connMods[i].getName()) ) { 775 list.add(connMods[i]); 776 } 777 } 778 } 779 780 ConnectorModule[] unassociatedApps = new ConnectorModule[list.size()]; 781 return ((ConnectorModule[]) list.toArray(unassociatedApps)); 782 } 783 784 788 public static ConnectorModule[] getAssociatedConnectorModules( 789 ConfigContext ctx, String serverName) throws ConfigException { 790 791 ArrayList list = new ArrayList (); 792 Domain domain = (Domain) ctx.getRootConfigBean(); 793 Applications applications = domain.getApplications(); 794 795 Servers servers = domain.getServers(); 796 Server s = servers.getServerByName(serverName); 797 if (s != null) { 798 ConnectorModule[] connMods = applications.getConnectorModule(); 799 for (int i=0; i<connMods.length; i++) { 800 if (serverReferencesApplication(ctx, serverName, 801 connMods[i].getName()) ) { 802 list.add(connMods[i]); 803 } 804 } 805 } 806 807 ConnectorModule[] associatedApps = new ConnectorModule[list.size()]; 808 return ((ConnectorModule[]) list.toArray(associatedApps)); 809 } 810 811 public static LifecycleModule[] getUnAssociatedLifecycleModules( 812 ConfigContext ctx, String serverName) throws ConfigException { 813 814 ArrayList list = new ArrayList (); 815 Domain domain = (Domain) ctx.getRootConfigBean(); 816 Applications applications = domain.getApplications(); 817 818 Servers servers = domain.getServers(); 819 Server s = servers.getServerByName(serverName); 820 if (s != null) { 821 LifecycleModule[] lcMods = applications.getLifecycleModule(); 822 for (int i=0; i<lcMods.length; i++) { 823 if (!serverReferencesApplication(ctx, serverName, 824 lcMods[i].getName()) ) { 825 list.add(lcMods[i]); 826 } 827 } 828 } 829 830 LifecycleModule[] unassociatedApps = new LifecycleModule[list.size()]; 831 return ((LifecycleModule[]) list.toArray(unassociatedApps)); 832 } 833 834 838 public static LifecycleModule[] getAssociatedLifecycleModules( 839 ConfigContext ctx, String serverName) throws ConfigException { 840 841 ArrayList list = new ArrayList (); 842 Domain domain = (Domain) ctx.getRootConfigBean(); 843 Applications applications = domain.getApplications(); 844 845 Servers servers = domain.getServers(); 846 Server s = servers.getServerByName(serverName); 847 if (s != null) { 848 LifecycleModule[] lcMods = applications.getLifecycleModule(); 849 for (int i=0; i<lcMods.length; i++) { 850 if (serverReferencesApplication(ctx, serverName, 851 lcMods[i].getName()) ) { 852 list.add(lcMods[i]); 853 } 854 } 855 } 856 857 LifecycleModule[] associatedApps = new LifecycleModule[list.size()]; 858 return ((LifecycleModule[]) list.toArray(associatedApps)); 859 } 860 861 public static AppclientModule[] getUnAssociatedAppclientModules( 862 ConfigContext ctx, String serverName) throws ConfigException { 863 864 ArrayList list = new ArrayList (); 865 Domain domain = (Domain) ctx.getRootConfigBean(); 866 Applications applications = domain.getApplications(); 867 868 Servers servers = domain.getServers(); 869 Server s = servers.getServerByName(serverName); 870 if (s != null) { 871 AppclientModule[] appclntMods = applications.getAppclientModule(); 872 for (int i=0; i<appclntMods.length; i++) { 873 if (!serverReferencesApplication(ctx, serverName, 874 appclntMods[i].getName()) ) { 875 list.add(appclntMods[i]); 876 } 877 } 878 } 879 880 AppclientModule[] unassociatedApps = new AppclientModule[list.size()]; 881 return ((AppclientModule[]) list.toArray(unassociatedApps)); 882 } 883 884 888 public static AppclientModule[] getAssociatedAppclientModules( 889 ConfigContext ctx, String serverName) throws ConfigException { 890 891 ArrayList list = new ArrayList (); 892 Domain domain = (Domain) ctx.getRootConfigBean(); 893 Applications applications = domain.getApplications(); 894 895 Servers servers = domain.getServers(); 896 Server s = servers.getServerByName(serverName); 897 if (s != null) { 898 AppclientModule[] appclntMods = applications.getAppclientModule(); 899 for (int i=0; i<appclntMods.length; i++) { 900 if (serverReferencesApplication(ctx, serverName, 901 appclntMods[i].getName()) ) { 902 list.add(appclntMods[i]); 903 } 904 } 905 } 906 907 AppclientModule[] associatedApps = new AppclientModule[list.size()]; 908 return ((AppclientModule[]) list.toArray(associatedApps)); 909 } 910 911 924 public static String getAdministrativeDomainName(ConfigContext ctx, 925 String serverName) throws ConfigException { 926 927 final String ADMIN_DOMAIN_PROP = "administrative.domain.name"; 929 930 String aDomainName = null; 932 933 final Domain domain = getDomainConfigBean(ctx); 934 935 if (domain != null) { 936 ElementProperty aDomainNameProp = 938 domain.getElementPropertyByName(ADMIN_DOMAIN_PROP); 939 940 if (aDomainNameProp != null) { 941 aDomainName = aDomainNameProp.getValue(); 942 } 943 } 944 945 return aDomainName; 946 } 947 948 952 public static MBeanServerConnection connect( 953 ConfigContext configContext, String instanceName) 954 throws ConfigException, IOException { 955 956 959 JMXConnector conn = getJMXConnector(configContext, instanceName); 961 962 return conn.getMBeanServerConnection(); 963 } 964 965 966 970 public static JMXConnector getJMXConnector( 971 ConfigContext configContext, String instanceName) 972 throws ConfigException, IOException { 973 974 977 JMXConnectorConfig jcc = getJMXConnectorInfo(configContext, instanceName); 979 980 JMXServiceURL url = null; 982 986 try { 987 url = JmxServiceUrlFactory.forRmiWithJndiInAppserver 988 (jcc.getHost(), Integer.parseInt(jcc.getPort())); 989 } 990 catch(final Exception e) { 991 throw new RuntimeException (e); 992 } 993 994 final Map env = new HashMap (); 995 env.put(JMXConnector.CREDENTIALS, new String [] {jcc.getUser(), jcc.getPassword()}); 997 JMXConnector conn = JMXConnectorFactory.connect(url, env); 999 1000 return conn; 1001 } 1002 1003 public static HttpListener getHttpListener(final ConfigContext cc, final String sn, final String ln) throws ConfigException { 1004 final Config cfg = getConfigForServer(cc, sn); 1005 final HttpService hs = cfg.getHttpService(); 1006 final HttpListener hl = hs.getHttpListenerById(ln); 1007 return ( hl ); 1008 } 1009 1010 public static HttpListener[] getHttpListeners(final ConfigContext cc, final String sn) throws ConfigException { 1011 final Config cfg = getConfigForServer(cc, sn); 1012 final HttpService hs = cfg.getHttpService(); 1013 return ( hs.getHttpListener() ); 1014 } 1015 public static String getUrlString(final HttpListener ls) { 1016 String url = ls.isSecurityEnabled() ? "https://" : "http://"; 1017 final String address = SystemPropertyConstants.DEFAULT_SERVER_SOCKET_ADDRESS.equals(ls.getAddress()) ? "localhost" : ls.getAddress(); 1018 url = url + address + ":" + ls.getPort(); 1019 return ( url ); 1020 } 1021 1022 public static JMXServiceURL getJmxServiceUrl(final JmxConnector conn) { 1023 final String sport = conn.getPort(); 1024 int port; 1025 String local = null; 1027 try { 1028 port = Integer.parseInt(sport); 1029 local = InetAddress.getLocalHost().getHostName(); } catch (final Exception e) { 1031 throw new RuntimeException (e); 1032 } 1033 final String address = SystemPropertyConstants.DEFAULT_SERVER_SOCKET_ADDRESS.equals(conn.getAddress()) ? local : conn.getAddress(); 1034 final JMXServiceURL url = JmxServiceUrlFactory.forJconsoleOverRmiWithJndiInAppserver(address, port); 1035 return ( url ); 1036 } 1037} 1038 | Popular Tags |