1 23 24 package com.sun.enterprise.admin.server.core.mbean.config; 25 26 import java.io.BufferedReader ; 27 import java.io.File ; 28 import java.io.FileNotFoundException ; 29 import java.io.InputStream ; 30 import java.io.InputStreamReader ; 31 import java.io.IOException ; 32 import java.net.InetAddress ; 33 import java.util.ArrayList ; 34 import java.util.Collection ; 35 import java.util.HashMap ; 36 import java.util.Enumeration ; 37 import java.util.Iterator ; 38 import java.util.logging.Level ; 39 import java.util.logging.Logger ; 40 import java.util.Properties ; 41 import java.util.StringTokenizer ; 42 import java.util.Vector ; 43 44 import javax.enterprise.deploy.shared.ModuleType ; 45 import javax.management.MBeanException ; 46 import javax.management.MBeanInfo ; 47 import javax.management.MBeanRegistration ; 48 import javax.management.MBeanServer ; 49 import javax.management.ObjectName ; 50 51 import com.sun.enterprise.admin.AdminContext; 52 import com.sun.enterprise.admin.common.constant.AdminConstants; 53 import com.sun.enterprise.admin.common.constant.ConfigAttributeName; 54 import com.sun.enterprise.admin.common.constant.DeploymentConstants; 55 import com.sun.enterprise.admin.common.exception.AFException; 56 import com.sun.enterprise.admin.common.exception.AFJDBCResourceException; 57 import com.sun.enterprise.admin.common.exception.AFResourceException; 58 import com.sun.enterprise.admin.common.exception.AFRuntimeStoreException; 59 import com.sun.enterprise.admin.common.exception.ControlException; 60 import com.sun.enterprise.admin.common.exception.DeploymentException; 61 import com.sun.enterprise.admin.common.exception.IllegalStateException; 62 import com.sun.enterprise.admin.common.exception.MBeanConfigException; 63 import com.sun.enterprise.admin.common.exception.PortInUseException; 64 import com.sun.enterprise.admin.common.exception.ServerInstanceException; 65 import com.sun.enterprise.admin.common.InitConfFileBean; 66 import com.sun.enterprise.admin.common.MBeanServerFactory; 67 import com.sun.enterprise.admin.common.ObjectNameHelper; 68 import com.sun.enterprise.admin.common.ObjectNames; 69 import com.sun.enterprise.admin.common.RequestID; 70 import com.sun.enterprise.admin.common.ServerInstanceStatus; 71 import com.sun.enterprise.admin.common.Status; 72 import com.sun.enterprise.admin.event.AdminEvent; 73 import com.sun.enterprise.admin.event.AdminEventCache; 74 import com.sun.enterprise.admin.event.AdminEventListenerException; 75 import com.sun.enterprise.admin.event.AdminEventMulticaster; 76 import com.sun.enterprise.admin.event.AdminEventResult; 77 import com.sun.enterprise.admin.event.ApplicationDeployEvent; 78 import com.sun.enterprise.admin.event.BaseDeployEvent; 79 import com.sun.enterprise.admin.event.ConfigChangeEvent; 80 import com.sun.enterprise.admin.event.EventBuilder; 81 import com.sun.enterprise.admin.event.EventContext; 82 import com.sun.enterprise.admin.event.EventStack; 83 import com.sun.enterprise.admin.event.ModuleDeployEvent; 84 import com.sun.enterprise.admin.event.ResourceDeployEvent; 85 import com.sun.enterprise.admin.server.core.AdminService; 86 import com.sun.enterprise.admin.server.core.channel.AdminChannel; 87 import com.sun.enterprise.admin.server.core.channel.RMIClient; 88 import com.sun.enterprise.admin.server.core.ManualChangeManager; 89 import com.sun.enterprise.admin.server.core.mbean.config.Domain2ServerTransformer; 90 import com.sun.enterprise.admin.util.ArgChecker; 91 import com.sun.enterprise.admin.util.Assert; 92 import com.sun.enterprise.admin.util.ExceptionUtil; 93 import com.sun.enterprise.admin.util.HostAndPort; 94 import com.sun.enterprise.admin.util.StringValidator; 95 import com.sun.enterprise.config.ConfigBean; 96 import com.sun.enterprise.config.ConfigBeansFactory; 97 import com.sun.enterprise.config.ConfigContext; 98 import com.sun.enterprise.config.ConfigContext; 99 import com.sun.enterprise.config.ConfigException; 100 import com.sun.enterprise.config.ConfigFactory; 101 import com.sun.enterprise.config.ConfigFactory; 102 import com.sun.enterprise.config.serverbeans.*; 103 import com.sun.enterprise.config.serverbeans.Applications; 104 import com.sun.enterprise.config.serverbeans.J2eeApplication; 105 import com.sun.enterprise.config.serverbeans.JavaConfig; 106 import com.sun.enterprise.config.serverbeans.ServerTags; 107 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 108 import com.sun.enterprise.connectors.ConnectorRuntime; 109 import com.sun.enterprise.connectors.util.JmsRaMapping; 110 import com.sun.enterprise.deployment.archivist.Archivist; 111 import com.sun.enterprise.deployment.archivist.ArchivistFactory; 112 import com.sun.enterprise.deployment.backend.*; 113 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 114 import com.sun.enterprise.deployment.deploy.shared.AbstractArchiveFactory; 115 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 116 import com.sun.enterprise.deployment.deploy.shared.FileArchiveFactory; 117 import com.sun.enterprise.deployment.deploy.shared.JarArchiveFactory; 118 import com.sun.enterprise.instance.AppsManager; 119 import com.sun.enterprise.instance.EjbModulesManager; 120 import com.sun.enterprise.instance.InstanceDefinition; 121 import com.sun.enterprise.instance.InstanceEnvironment; 122 import com.sun.enterprise.instance.InstanceEnvironment; 123 import com.sun.enterprise.instance.ServerManager; 124 import com.sun.enterprise.instance.WebModulesManager; 125 import com.sun.enterprise.security.auth.realm.BadRealmException; 126 import com.sun.enterprise.security.auth.realm.file.FileRealm; 127 import com.sun.enterprise.security.auth.realm.NoSuchRealmException; 128 import com.sun.enterprise.security.auth.realm.NoSuchUserException; 129 import com.sun.enterprise.security.util.IASSecurityException; 130 import com.sun.enterprise.server.Constants; 131 import com.sun.enterprise.util.i18n.StringManager; 132 import com.sun.enterprise.util.io.FileUtils; 133 import com.sun.enterprise.util.net.NetUtils; 134 135 136 150 151 public class ManagedServerInstance extends ConfigMBeanBase implements ConfigAttributeName.Server 152 { 153 private HostAndPort mHostAndPort = null; 154 private int mStartMode = AdminConstants.kNonDebugMode; 155 private String mInstanceName = null; 156 private boolean mAutoStart = false; 157 158 public static final Logger sLogger = 159 Logger.getLogger(AdminConstants.kLoggerName); 160 161 private static final int CONFIG_CHANGED = 7; 162 163 164 167 static final boolean PORT_DOMAIN_TO_SERVER = false; 168 169 170 173 private static final String [][] MAPLIST = 174 { 175 193 }; 194 197 private static final String [] ATTRIBUTES = 198 { 199 209 }; 210 211 214 private static final String [] OPERATIONS = 215 { 216 "start(), ACTION, ManagedServerInstance.start1.operation", "start(String[] passwords), ACTION, ManagedServerInstance.start1.operation", 218 "start(boolean debug, String[] passwords), ACTION, ManagedServerInstance.start2.operation", 219 "startInDebugMode(), ACTION", 220 "startInDebugMode(String[] passwords), ACTION", 221 "restart(), ACTION", 222 "stop(int timeoutSeconds), ACTION", 223 "getDeployedJ2EEApplications(), INFO ", 224 "getDeployedJ2EEModules(), INFO ", 225 "getEnabledJ2EEApplications(), INFO ", 226 "getDisabledJ2EEApplications(), INFO ", 227 "getEnabledJ2EEModules(), INFO ", 228 "getDisabledJ2EEModules(), INFO ", 229 "setHttpPort(int port ), ACTION ", 233 "getHostAndPort(), INFO ", 234 "getHttpPort(), INFO ", 235 "getStatus(), INFO ", 236 "reconfigure(), ACTION ", 237 "startMonitor(), ACTION ", 238 "getMonitorableComponentNames(), INFO ", 239 "stopMonitor(), ACTION ", 240 "postRegister(Boolean registrationDone), ACTION ", 241 "preRegister(javax.management.MBeanServer server, javax.management.ObjectName name), ACTION ", 242 "postDeregister(), ACTION ", 243 "preDeregister(), ACTION ", 244 "getInstanceRoot(), INFO ", 246 "getSecurityPasswordTokens(), INFO ", 247 "isRestartNeeded(), INFO", 248 "getUserNames(), INFO", 249 "getGroupNames(), INFO", 250 "getUserGroupNames(String userName), INFO", 251 "addUser(String userName, String password, String[] groupList), INFO ", 252 "removeUser(String userName), INFO ", 253 "updateUser(String userName, String password, String[] groupList), INFO ", 254 }; 255 256 259 public ManagedServerInstance() throws MBeanConfigException 260 { 261 this.setDescriptions(MAPLIST, ATTRIBUTES, OPERATIONS); 262 } 263 264 public ManagedServerInstance(String instanceName, HostAndPort hostPort, 265 boolean autoStart) throws PortInUseException,MBeanConfigException 266 { 267 this(instanceName, hostPort, autoStart, null); 268 } 269 270 public ManagedServerInstance(String instanceName, HostAndPort hostPort, 271 boolean autoStart, AdminContext adminContext) 272 throws PortInUseException,MBeanConfigException 273 { 274 this(); setAdminContext(adminContext); 276 initialize(ObjectNames.kServerInstance, new String []{instanceName}); 277 278 279 if (instanceName == null || hostPort == null) 280 { 281 throw new IllegalArgumentException (); 282 } 283 289 mInstanceName = instanceName; 290 mHostAndPort = hostPort; 291 mAutoStart = autoStart; 292 } 293 294 304 public RequestID start() throws ControlException 305 { 306 return ( this.start(false, null) ); 307 } 308 309 public RequestID start(String [] passwords) throws ControlException 310 { 311 return ( this.start(false, passwords) ); 312 } 313 314 public RequestID start(boolean debug, String [] passwords) throws ControlException 315 { 316 try 317 { 318 if (getInstanceStatusCode() == Status.kInstanceRunningCode) 319 { 320 String msg = localStrings.getString( "admin.server.core.mbean.config.cannot_start_already_running" ); 321 throw new IllegalStateException ( msg ); 322 } 323 if ( debug ) 324 { 325 mStartMode = AdminConstants.kDebugMode; 326 } 327 else 328 { 329 if (isDebug()) 330 { 331 setDebug(false); 332 setDebugOptions(null); 334 super.getConfigContext().flush(); 335 applyConfigChanges(); 336 } 337 } 338 339 if(debug) 340 { 341 String strPort = "?"; 342 try{ 343 strPort = String.valueOf(getDebugPort()); 344 } 345 catch (Exception e) 346 { 347 } 348 sLogger.log(Level.INFO, "mbean.start_instance_debug", 349 new Object []{mInstanceName, strPort}); 350 } 351 else 352 { 353 sLogger.log(Level.INFO, "mbean.start_instance", mInstanceName); 354 } 355 356 InstanceDefinition instance = new InstanceDefinition(mInstanceName, 357 mHostAndPort.getPort()); 358 ServerManager.instance().startServerInstance(instance,passwords); 359 360 361 sLogger.log(Level.INFO, "mbean.check_start_instance", mInstanceName); 364 long timeoutMillis = 240000; 365 long sleepTime = 2000; 366 long timeBefore = java.lang.System.currentTimeMillis(); 367 long timeAfter = java.lang.System.currentTimeMillis(); 368 boolean timeoutReached = false; 369 while ((! timeoutReached) && 370 (! (getInstanceStatusCode() == Status.kInstanceRunningCode))) { 371 Thread.sleep(sleepTime); 372 timeAfter = java.lang.System.currentTimeMillis(); 373 timeoutReached = (timeAfter - timeBefore) >= timeoutMillis; 374 } 375 if (timeoutReached) { 376 sLogger.log(Level.INFO, "mbean.start_instance_timeout", mInstanceName); 377 try { 378 Long tLong = new Long (timeoutMillis/1000); 379 stop(tLong.intValue()); 380 } catch (ControlException cex) { 381 String msg = localStrings.getString( "admin.server.core.mbean.config.timeout_reached_server_stopping_exception", mInstanceName ); 382 } 384 String msg = localStrings.getString( "admin.server.core.mbean.config.timeout_reached_server_starting_exception", mInstanceName ); 385 throw new ControlException( msg ); 386 } else { 387 sLogger.log(Level.INFO, "mbean.start_instance_success", mInstanceName); 388 } 389 } 391 catch (Exception e) 392 { 393 sLogger.log(Level.SEVERE, 394 "mbean.start_instance_failed", mInstanceName); 395 sLogger.log(Level.SEVERE, 396 "mbean.start_instance_failed_details", e); 397 throw new ControlException(e.getMessage()); 398 } 399 return ( null ); 400 } 401 402 404 public int startInDebugMode(String [] passwords) throws ControlException 405 { 406 int port = -1; 407 try 408 { 409 boolean isChanged = false; 410 if (!isDebug()) 411 { 412 setDebug(true); 413 isChanged = true; 414 } 415 port = getDebugPort(); 416 if (port == -1) 417 { 418 port = NetUtils.getFreePort(); 419 if (port == 0) 420 { 421 sLogger.log(Level.SEVERE, "general.free_port_failed"); 422 String msg = localStrings.getString( "admin.server.core.mbean.config.no_free_port" ); 423 throw new Exception ( msg ); 424 } 425 setDebugPort(port); 426 isChanged = true; 427 } 428 if (isChanged) 429 { 430 super.getConfigContext().flush(); 431 applyConfigChanges(); 432 } 433 } 434 catch (Exception e) 435 { 436 sLogger.log(Level.WARNING, "mbean.set_debug_failed", e); 437 throw new ControlException(e.getLocalizedMessage()); 438 } 439 start(true, passwords); 440 return port; 441 } 442 public int startInDebugMode() throws ControlException 443 { 444 return this.startInDebugMode(null); 445 } 446 447 450 public String [] getSecurityPasswordTokens() throws ControlException 451 { 452 try 453 { 454 InstanceEnvironment env = new InstanceEnvironment(mInstanceName); 456 String pwdFileName = env.getSecurityPasswordsFilePath(); 457 File pwdFile = new File (pwdFileName); 458 if(pwdFile.exists()) 459 return null; 460 InitConfFileBean conf = new InitConfFileBean(); 462 conf.initialise(mInstanceName, false); 463 String security = conf.get_mag_var(InitConfFileBean.INITCONF_SECURITY_ATTRIBUTE); 464 if(security.equalsIgnoreCase(InitConfFileBean.INITCONF_VALUE_ON)) 465 { 466 InstanceDefinition instance = new InstanceDefinition(mInstanceName, 467 mHostAndPort.getPort()); 468 return ServerManager.instance().getSecurityTokensForInstance(instance); 469 } 473 return null; 474 } 475 catch(Exception e) 476 { 477 sLogger.log(Level.WARNING, "mbean.security_check_failed", e); 478 throw new ControlException(e.getMessage()); 479 } 480 } 481 482 private static final int TIME_OUT_SECONDS = 120; 483 484 private static StringManager localStrings = 486 StringManager.getManager( ManagedServerInstance.class ); 487 488 491 public RequestID restart() throws ControlException 492 { 493 RequestID reqId = null; 494 495 String adminId = AdminService.getAdminService().getInstanceName(); 496 502 final RMIClient rmiClient = AdminChannel.getRMIClient(mInstanceName); 503 504 if (rmiClient.getInstanceStatusCode() != Status.kInstanceRunningCode) 505 { 506 String msg = localStrings.getString( "admin.server.core.mbean.config.instance_not_running_cannot_restart" ); 507 throw new IllegalStateException ( msg ); 508 } 509 510 try 511 { 512 513 sLogger.log(Level.INFO, "mbean.restart_instance", mInstanceName); 514 InstanceDefinition instance = new InstanceDefinition( 515 mInstanceName, 516 getHostAndPort().getPort()); 517 ServerManager.instance().restartServerInstance(instance); 518 525 int i = 0; int MAX_TIMES = 3; 526 while ((rmiClient.getInstanceStatusCode() != 527 Status.kInstanceNotRunningCode) && (i < MAX_TIMES)) 528 { 529 Thread.currentThread().sleep(5000); 530 i++; 531 } 532 } 533 catch (Exception e) 534 { 535 throw new ControlException(e.getMessage()); 536 } 537 ManagedInstanceTimer tt = new ManagedInstanceTimer( 538 TIME_OUT_SECONDS, 0, 539 new TimerCallback() 540 { 541 public boolean check() throws Exception 542 { 543 return (rmiClient.getInstanceStatusCode() == 544 Status.kInstanceRunningCode); 545 } 546 } ); 547 tt.run(); 549 if (rmiClient.getInstanceStatusCode() != Status.kInstanceRunningCode) 550 { 551 String msg = localStrings.getString( "admin.server.core.mbean.config.timeout_while_restarting_server" ); 552 try 553 { 554 stop(TIME_OUT_SECONDS); 555 } 556 catch (ControlException ce) 557 { 558 msg += localStrings.getString( "admin.server.core.mbean.config.server_stop_exception" ); 559 } 560 throw new ControlException(msg + mInstanceName); 561 } 562 563 return reqId; 564 } 565 566 private static final class ManagedInstanceTimer implements Runnable 567 { 568 private final int timeOutSeconds; 569 private final TimerCallback callBack; 570 private final int startAfterSeconds; 571 private boolean timeOutReached; 572 private long startTime; 573 574 ManagedInstanceTimer(int timeOutSeconds, 575 int startAfterSeconds, 576 TimerCallback callBack) 577 { 578 this.timeOutSeconds = timeOutSeconds; 579 this.startAfterSeconds = startAfterSeconds; 580 this.callBack = callBack; 581 this.timeOutReached = false; 582 } 583 584 public void run() 585 { 586 startTime = java.lang.System.currentTimeMillis(); 587 try 588 { 589 Thread.currentThread().sleep(startAfterSeconds * 1000); 590 while (!timeOutReached() && !callBack.check()) 591 { 592 try 593 { 594 Thread.currentThread().sleep(1000); 595 computeTimeOut(); 596 } 597 catch (InterruptedException ie) 598 { 599 sLogger.warning(ie.toString()); 600 timeOutReached = true; 601 } 602 } 603 } 604 catch (Exception e) 605 { 606 sLogger.warning(e.toString()); 607 timeOutReached = true; 608 } 609 } 610 611 private boolean timeOutReached() 612 { 613 return timeOutReached; 614 } 615 616 private void computeTimeOut() 617 { 618 long currentTime = java.lang.System.currentTimeMillis(); 619 timeOutReached = 620 ((currentTime - startTime) >= (timeOutSeconds * 1000)); 621 } 622 } 623 624 interface TimerCallback 625 { 626 boolean check() throws Exception ; 627 } 628 629 public void stop(int timeoutSeconds) throws ControlException 630 { 631 String adminId = AdminService.getAdminService().getInstanceName(); 632 if (mInstanceName.equals(adminId)) 633 { 634 sLogger.log(Level.INFO, "mbean.shutdown_started"); 635 new Thread (new ShutdownThread(adminId)).start(); 636 return; 637 } 638 if (getInstanceStatusCode() == Status.kInstanceNotRunningCode) 639 { 640 String msg = localStrings.getString( "admin.server.core.mbean.config.not_running_cannot_stop" ); 641 throw new IllegalStateException ( msg ); 642 } 643 644 645 try 646 { 647 sLogger.log(Level.INFO, "mbean.stop_instance", mInstanceName); 648 InstanceDefinition instance = new InstanceDefinition(mInstanceName, 649 mHostAndPort.getPort()); 650 ServerManager.instance().stopServerInstance(instance); 651 652 sLogger.log(Level.INFO, "mbean.check_stop_instance", mInstanceName); 655 long timeoutMillis = (timeoutSeconds * 1000); 656 long sleepTime = 2000; 657 long timeBefore = java.lang.System.currentTimeMillis(); 658 long timeAfter = java.lang.System.currentTimeMillis(); 659 boolean timeoutReached = false; 660 while ((! timeoutReached) && 661 (! (getInstanceStatusCode() == Status.kInstanceNotRunningCode))) { 662 Thread.sleep(sleepTime); 663 timeAfter = java.lang.System.currentTimeMillis(); 664 timeoutReached = (timeAfter - timeBefore) >= timeoutMillis; 665 } 666 if (timeoutReached) { 667 sLogger.log(Level.INFO, "mbean.stop_instance_timeout", mInstanceName); 668 String msg = localStrings.getString( "admin.server.core.mbean.config.timeout_while_stopping_server", mInstanceName ); 669 throw new ControlException( msg ); 670 } else { 671 sLogger.log(Level.INFO, "mbean.stop_instance_success", mInstanceName); 672 } 673 } 675 catch (Exception e) 676 { 677 sLogger.log(Level.SEVERE, 678 "mbean.stop_instance_failed", mInstanceName); 679 throw new ControlException(e.getMessage()); 680 } 681 682 } 683 684 687 public String [] getDeployedJ2EEApplications() throws ServerInstanceException 688 { 689 String [] apps = new String [0]; 690 try 691 { 692 sLogger.log(Level.FINE, "mbean.list_components"); 693 ConfigContext serverContext = getConfigContext(mInstanceName); 694 Applications appsConfigBean = 695 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 696 serverContext, ServerXPathHelper.XPATH_APPLICATIONS); 697 J2eeApplication[] j2eeApps = appsConfigBean.getJ2eeApplication(); 698 if (j2eeApps != null) 699 { 700 apps = new String [j2eeApps.length]; 701 for(int i=0; i<j2eeApps.length; i++) 702 { 703 apps[i] = j2eeApps[i].getName(); 704 } 705 } 706 } 707 catch (Exception e) 708 { 709 sLogger.log(Level.WARNING, "mbean.list_failed", e); 710 throw new ServerInstanceException(e.getLocalizedMessage()); 711 } 712 return ( apps ); 713 } 714 715 717 public String [] getDeployedJ2EEModules() throws ServerInstanceException 718 { 719 String msg = localStrings.getString( "admin.server.core.mbean.config.not_supported_yet" ); 720 throw new UnsupportedOperationException ( msg ); 721 } 722 723 730 public String [] getDeployedEJBModules() throws ServerInstanceException 731 { 732 String [] ejbModules = new String [0]; 733 try 734 { 735 sLogger.log(Level.FINE, "mbean.list_components"); 736 ConfigContext serverContext = getConfigContext(mInstanceName); 737 Applications appsConfigBean = 738 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 739 serverContext, ServerXPathHelper.XPATH_APPLICATIONS); 740 EjbModule[] modules = appsConfigBean.getEjbModule(); 741 if (modules != null) 742 { 743 ejbModules = new String [modules.length]; 744 for(int i=0; i<modules.length; i++) 745 { 746 ejbModules[i] = modules[i].getName(); 747 } 748 } 749 } 750 catch (Exception e) 751 { 752 sLogger.log(Level.WARNING, "mbean.list_failed", e); 753 throw new ServerInstanceException(e.getLocalizedMessage()); 754 } 755 return ejbModules; 756 } 757 758 765 public String [] getDeployedWebModules() throws ServerInstanceException 766 { 767 String [] webModules = new String [0]; 768 try 769 { 770 sLogger.log(Level.FINE, "mbean.list_components"); 771 ConfigContext serverContext = getConfigContext(mInstanceName); 772 Applications appsConfigBean = 773 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 774 serverContext, ServerXPathHelper.XPATH_APPLICATIONS); 775 WebModule[] modules = appsConfigBean.getWebModule(); 776 if (modules != null) 777 { 778 webModules = new String [modules.length]; 779 for(int i=0; i<modules.length; i++) 780 { 781 webModules[i] = modules[i].getName(); 782 } 783 } 784 } 785 catch (Exception e) 786 { 787 sLogger.log(Level.WARNING, "mbean.list_failed", e); 788 throw new ServerInstanceException(e.getLocalizedMessage()); 789 } 790 return webModules; 791 } 792 793 799 public String [] getDeployedConnectors() throws ServerInstanceException 800 { 801 String [] connectors = new String [0]; 802 try 803 { 804 sLogger.log(Level.FINE, "mbean.list_components"); 805 ConfigContext serverContext = getConfigContext(mInstanceName); 806 Applications appsConfigBean = 807 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 808 serverContext, ServerXPathHelper.XPATH_APPLICATIONS); 809 ConnectorModule[] connectorConfigBeans = 810 appsConfigBean.getConnectorModule(); 811 if (connectorConfigBeans != null) 812 { 813 connectors = new String [connectorConfigBeans.length]; 814 for(int i = 0; i < connectors.length; i++) 815 { 816 connectors[i] = connectorConfigBeans[i].getName(); 817 } 818 } 819 } 820 catch (Exception e) 821 { 822 sLogger.log(Level.WARNING, "mbean.list_failed", e); 823 throw new ServerInstanceException(e.getLocalizedMessage()); 824 } 825 return connectors; 826 } 827 828 830 public String [] getEnabledJ2EEApplications() throws ServerInstanceException 831 { 832 return ( null ); 833 } 834 835 837 public String [] getDisabledJ2EEApplications() throws ServerInstanceException 838 { 839 return ( null ); 840 } 841 842 844 public String [] getEnabledJ2EEModules() throws ServerInstanceException 845 { 846 return ( null ); 847 } 848 849 851 public String [] getDisabledJ2EEModules() throws ServerInstanceException 852 { 853 return ( null ); 854 } 855 856 857 859 public void createResource(String resourceXMLFile) 860 throws AFResourceException 861 { 862 try 863 { 864 ResourcesXMLParser allResources = 865 new ResourcesXMLParser(resourceXMLFile); 866 Iterator resourceIter = allResources.getResources(); 867 while (resourceIter.hasNext()) 868 { 869 Resource resource = (Resource) resourceIter.next(); 870 if (resource.getType() == Resource.JDBC_RESOURCE) 871 { 872 Properties attributes = resource.getAttributes(); 873 String jndiName = 874 attributes.getProperty( ResourcesXMLParser.JNDI_NAME); 875 String poolName = 876 attributes.getProperty( ResourcesXMLParser.POOL_NAME); 877 createJDBCResource(jndiName, poolName); 878 addJDBCResourceAttribute(resource, attributes, jndiName); 879 } 880 else if (resource.getType() == Resource.JMS_RESOURCE) 881 { 882 Properties attributes = resource.getAttributes(); 883 String jndiName = 884 attributes.getProperty( ResourcesXMLParser.JNDI_NAME); 885 String resType = 886 attributes.getProperty(ResourcesXMLParser.RES_TYPE); 887 890 createJMSResource(jndiName, resType, new Properties ()); 891 addJMSResourceAttribute(resource, attributes, jndiName); 892 893 } 894 else if (resource.getType() == Resource.EXT_JNDI_RESOURCE) 895 { 896 Properties attributes = resource.getAttributes(); 897 String jndiName = 898 attributes.getProperty(ResourcesXMLParser.JNDI_NAME); 899 String jndiLookupName = 900 attributes.getProperty(ResourcesXMLParser.JNDI_LOOKUP); 901 String resType = 902 attributes.getProperty(ResourcesXMLParser.RES_TYPE); 903 String factoryClass = 904 attributes.getProperty(ResourcesXMLParser.FACTORY_CLASS); 905 906 createJNDIResource(jndiName, jndiLookupName, resType, 907 factoryClass); 908 addJNDIResourceAttribute(resource, attributes, jndiName); 909 } 910 else if (resource.getType() == Resource.PERSISTENCE_RESOURCE) 911 { 912 Properties attributes = resource.getAttributes(); 913 String jndiName = 914 attributes.getProperty(ResourcesXMLParser.JNDI_NAME); 915 916 createPersistenceManagerFactoryResource(jndiName); 918 addPersistenceManagerFactoryAttribute(resource, 919 attributes, 920 jndiName); 921 } 922 else if (resource.getType() == Resource.MAIL_RESOURCE) 923 { 924 Properties attributes = resource.getAttributes(); 925 String jndiName = 926 attributes.getProperty(ResourcesXMLParser.JNDI_NAME); 927 String host = 928 attributes.getProperty(ResourcesXMLParser.MAIL_HOST); 929 String user = 930 attributes.getProperty(ResourcesXMLParser.MAIL_USER); 931 String fromAddress = attributes.getProperty( 932 ResourcesXMLParser.MAIL_FROM_ADDRESS); 933 createJavaMailResource(jndiName, host, user, fromAddress); 934 addJavaMailAttribute(resource, attributes, jndiName); 935 } 936 else if (resource.getType() == Resource.CUSTOM_RESOURCE) 937 { 938 Properties attributes = resource.getAttributes(); 939 String jndiName = 940 attributes.getProperty(ResourcesXMLParser.JNDI_NAME); 941 String resType = 942 attributes.getProperty(ResourcesXMLParser.RES_TYPE); 943 String factoryClass = 944 attributes.getProperty(ResourcesXMLParser.FACTORY_CLASS); 945 946 createCustomResource(jndiName, resType, factoryClass); 947 addCustomResourceAttribute(resource, attributes, jndiName); 948 } 949 else if (resource.getType() == Resource.JDBC_CONN_POOL) 950 { 951 Properties attributes = resource.getAttributes(); 952 String name = attributes.getProperty( 953 ResourcesXMLParser.CONNECTION_POOL_NAME); 954 String datasourceClass = 955 attributes.getProperty(ResourcesXMLParser.DATASOURCE_CLASS); 956 957 createJDBCConnectionPool(name, datasourceClass); 958 addJDBCConnectionPoolAttribute(resource, attributes, name); 959 } 960 } 961 } 962 catch (Exception e) 963 { 964 throw new AFResourceException(e.getMessage()); 965 } 966 } 967 968 969 public void createJDBCConnectionPool(String id, 970 String datasourceClassName) 971 throws AFResourceException 972 { 973 ArgChecker.checkValid(id, "id", 974 StringValidator.getInstance()); ArgChecker.checkValid(datasourceClassName, "datasourceClassName", 976 StringValidator.getInstance()); 978 try 979 { 980 sLogger.log(Level.FINE, "mbean.create_resource", id); 981 ConfigContext serverContext = getConfigContext(mInstanceName); 982 Resources resourcesBean = 983 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 984 ServerXPathHelper.XPATH_RESOURCES); 985 JdbcConnectionPool resource = new JdbcConnectionPool(); 986 resource.setName(id); 987 resource.setDatasourceClassname(datasourceClassName); 988 resourcesBean.addJdbcConnectionPool(resource); 989 serverContext.flush(); 990 991 } 992 catch (Exception e) 993 { 994 sLogger.log(Level.WARNING, "mbean.create_resource_failed", e); 995 throw new AFResourceException(e.getLocalizedMessage()); 996 } 997 } 998 999 private void addJDBCConnectionPoolAttribute(Resource resource, 1000 Properties attributes, 1001 String name) 1002 throws AFResourceException 1003 { 1004 try 1005 { 1006 ConfigContext serverContext = getConfigContext(mInstanceName); 1007 Resources resourcesBean = 1008 (Resources)ConfigBeansFactory.getConfigBeanByXPath( 1009 serverContext, 1010 ServerXPathHelper.XPATH_RESOURCES); 1011 JdbcConnectionPool jdbc_pool_resource = 1012 resourcesBean.getJdbcConnectionPoolByName(name); 1013 String sSteadyPoolSize = 1014 attributes.getProperty(ResourcesXMLParser.STEADY_POOL_SIZE); 1015 String sMaxPoolSize = 1016 attributes.getProperty(ResourcesXMLParser.MAX_POOL_SIZE); 1017 String sMaxWaitTimeInMillis = 1018 attributes.getProperty( 1019 ResourcesXMLParser.MAX_WAIT_TIME_IN_MILLIS); 1020 String sPoolSizeQuantity = 1021 attributes.getProperty(ResourcesXMLParser.POOL_SIZE_QUANTITY); 1022 String sIdleTimeoutInSec = 1023 attributes.getProperty( 1024 ResourcesXMLParser.IDLE_TIME_OUT_IN_SECONDS); 1025 String sIsConnectionValidationRequired = 1026 attributes.getProperty( 1027 ResourcesXMLParser.IS_CONNECTION_VALIDATION_REQUIRED); 1028 String sConnectionValidationMethod = 1029 attributes.getProperty( 1030 ResourcesXMLParser.CONNECTION_VALIDATION_METHOD); 1031 String sFailAllConnection = 1032 attributes.getProperty( 1033 ResourcesXMLParser.FAIL_ALL_CONNECTIONS); 1034 String sValidationTableName = 1035 attributes.getProperty( 1036 ResourcesXMLParser.VALIDATION_TABLE_NAME); 1037 String sResType = 1038 attributes.getProperty( 1039 ResourcesXMLParser.RES_TYPE); 1040 String sTransIsolationLevel = 1041 attributes.getProperty( 1042 ResourcesXMLParser.TRANS_ISOLATION_LEVEL); 1043 String sIsIsolationLevelQuaranteed = 1044 attributes.getProperty( 1045 ResourcesXMLParser.IS_ISOLATION_LEVEL_GUARANTEED); 1046 1047 if (sSteadyPoolSize != null) { 1048 jdbc_pool_resource.setSteadyPoolSize(sSteadyPoolSize); 1049 } 1050 if (sMaxPoolSize != null) { 1051 jdbc_pool_resource.setMaxPoolSize(sMaxPoolSize); 1052 } 1053 if (sMaxWaitTimeInMillis != null) { 1054 jdbc_pool_resource.setMaxWaitTimeInMillis(sMaxWaitTimeInMillis); 1055 } 1056 if (sPoolSizeQuantity != null) { 1057 jdbc_pool_resource.setPoolResizeQuantity(sPoolSizeQuantity); 1058 } 1059 if (sIdleTimeoutInSec != null) { 1060 jdbc_pool_resource.setIdleTimeoutInSeconds(sIdleTimeoutInSec); 1061 } 1062 if (sIsConnectionValidationRequired != null) { 1063 jdbc_pool_resource.setIsConnectionValidationRequired( 1064 Boolean.valueOf(sIsConnectionValidationRequired).booleanValue()); 1065 } 1066 if (sConnectionValidationMethod != null) { 1067 jdbc_pool_resource.setConnectionValidationMethod( 1068 sConnectionValidationMethod); 1069 } 1070 if (sFailAllConnection != null) { 1071 jdbc_pool_resource.setFailAllConnections(Boolean.valueOf( 1072 sFailAllConnection).booleanValue()); 1073 } 1074 if (sValidationTableName != null) { 1075 jdbc_pool_resource.setValidationTableName(sValidationTableName); 1076 } 1077 if (sResType != null) { 1078 jdbc_pool_resource.setResType(sResType); 1079 } 1080 if (sTransIsolationLevel != null) { 1081 jdbc_pool_resource.setTransactionIsolationLevel( 1082 sTransIsolationLevel); 1083 } 1084 if (sIsIsolationLevelQuaranteed != null) { 1085 jdbc_pool_resource.setIsIsolationLevelGuaranteed( 1086 Boolean.valueOf(sIsIsolationLevelQuaranteed).booleanValue()); 1087 } 1088 1089 String sDescription = resource.getDescription(); 1091 if (sDescription != null) { 1092 jdbc_pool_resource.setDescription(sDescription); 1093 } 1094 ElementProperty[] epArray = resource.getElementProperty(); 1096 if (epArray != null) { 1097 for (int ii=0; ii<epArray.length; ii++) 1098 jdbc_pool_resource.addElementProperty(epArray[ii]); 1099 } 1100 serverContext.flush(); 1101 } 1102 catch (Exception e) 1103 { 1104 throw new AFResourceException(e.getLocalizedMessage()); 1105 } 1106 } 1107 1108 public void deleteJDBCConnectionPool(String poolName) 1109 throws AFResourceException 1110 { 1111 ArgChecker.checkValid(poolName, "poolName", 1112 StringValidator.getInstance()); sLogger.log(Level.FINE, "mbean.delele_jdbc_pool", poolName); 1114 try 1115 { 1116 ConfigContext serverContext = getConfigContext(mInstanceName); 1117 Resources resourcesBean = 1118 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1119 ServerXPathHelper.XPATH_RESOURCES); 1120 JdbcConnectionPool resource = 1121 resourcesBean.getJdbcConnectionPoolByName(poolName); 1122 if (resource == null) 1124 { 1125 String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource", poolName ); 1126 throw new Exception ( msg ); 1127 } 1128 resourcesBean.removeJdbcConnectionPool(resource); 1129 serverContext.flush(); 1130 } 1131 catch (Exception e) 1132 { 1133 sLogger.log(Level.WARNING, "mbean.delete_jdbc_pool_failed", e); 1134 throw new AFResourceException(e.getLocalizedMessage()); 1135 } 1136 } 1137 1138 public String [] listJDBCConnectionPools() throws AFException 1139 { 1140 String [] sa = null; 1141 try 1142 { 1143 sLogger.log(Level.FINE, "mbean.list_components"); 1144 ConfigContext serverContext = getConfigContext(mInstanceName); 1145 Resources resourcesBean = 1146 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1147 ServerXPathHelper.XPATH_RESOURCES); 1148 JdbcConnectionPool[] connectionPools = resourcesBean.getJdbcConnectionPool(); 1149 if (connectionPools != null) 1150 { 1151 sa = new String [connectionPools.length]; 1152 for(int i=0; i<connectionPools.length; i++) 1153 { 1154 sa[i] = connectionPools[i].getName(); 1155 } 1156 } 1157 } 1158 catch (Exception e) 1159 { 1160 sLogger.log(Level.WARNING, "mbean.list_failed", e); 1161 throw new AFException(e.getLocalizedMessage()); 1162 } 1163 return sa; 1164 } 1165 1166 1169 public void createJDBCResource(String jndiName, 1170 String poolName) 1171 throws AFResourceException 1172 { 1173 ArgChecker.checkValid(jndiName, "jndiName", 1174 StringValidator.getInstance()); ArgChecker.checkValid(poolName, "poolName", 1176 StringValidator.getInstance()); try 1178 { 1179 sLogger.log(Level.FINE, "mbean.create_resource", jndiName); 1180 ConfigContext serverContext = getConfigContext(mInstanceName); 1181 Resources resourcesBean = 1182 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1183 ServerXPathHelper.XPATH_RESOURCES); 1184 JdbcResource resource = new JdbcResource(); 1185 resource.setJndiName(jndiName); 1186 resource.setPoolName(poolName); 1187 resourcesBean.addJdbcResource(resource); 1189 createResourceRef(jndiName); 1190 serverContext.flush(); 1191 1192 } 1193 catch (Exception e) 1194 { 1195 sLogger.log(Level.WARNING, "mbean.create_resource_failed", e); 1196 throw new AFResourceException(e.getLocalizedMessage()); 1197 } 1198 } 1199 1200 private void createResourceRef(String name) throws Exception { 1201 ConfigContext serverContext = getConfigContext(mInstanceName); 1202 Server server = ServerBeansFactory.getServerBean(serverContext); 1204 ResourceRef rr = new ResourceRef(); 1205 rr.setRef(name); 1206 server.addResourceRef(rr); 1207 1209 } 1210 1211 private void deleteResourceRef(String name) throws Exception { 1212 ConfigContext serverContext = getConfigContext(mInstanceName); 1213 Server server = ServerBeansFactory.getServerBean(serverContext); 1215 ResourceRef rr = server.getResourceRefByRef(name); 1216 if(rr != null) { 1217 server.removeResourceRef(rr); 1218 } 1219 } 1220 1221 private void addJDBCResourceAttribute(Resource resource, 1222 Properties attributes, 1223 String jndiName) 1224 throws AFResourceException 1225 { 1226 try 1228 { 1229 ConfigContext serverContext = getConfigContext(mInstanceName); 1230 Resources resourcesBean = 1231 (Resources)ConfigBeansFactory.getConfigBeanByXPath( 1232 serverContext, ServerXPathHelper.XPATH_RESOURCES); 1233 JdbcResource jdbc_resource = 1234 resourcesBean.getJdbcResourceByJndiName(jndiName); 1235 String sDescription = resource.getDescription(); 1242 if (sDescription != null) { 1243 jdbc_resource.setDescription(sDescription); 1244 } 1245 1253 1254 serverContext.flush(); 1255 } 1256 catch (Exception e) 1257 { 1258 throw new AFResourceException(e.getLocalizedMessage()); 1259 } 1260 } 1261 1262 public void deleteJDBCResource(String jndiName) throws AFResourceException 1263 { 1264 ArgChecker.checkValid(jndiName, "jndiName", 1265 StringValidator.getInstance()); try 1267 { 1268 sLogger.log(Level.FINE, "mbean.delete_resource", jndiName); 1269 ConfigContext serverContext = getConfigContext(mInstanceName); 1270 Resources resourcesBean = 1271 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1272 ServerXPathHelper.XPATH_RESOURCES); 1273 JdbcResource resource = 1274 resourcesBean.getJdbcResourceByJndiName(jndiName); 1275 if (resource == null) 1277 { 1278 String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource", jndiName ); 1279 throw new Exception ( msg ); 1280 } 1281 resourcesBean.removeJdbcResource(resource); 1282 deleteResourceRef(jndiName); 1283 serverContext.flush(); 1284 } 1285 catch (Exception e) 1286 { 1287 sLogger.log(Level.WARNING, "mbean.delete_resource_failed", e); 1288 throw new AFResourceException(e.getLocalizedMessage()); 1289 } 1290 } 1291 1292 public String [] listJDBCResources() throws AFException 1293 { 1294 String [] sa = null; 1295 try 1296 { 1297 sLogger.log(Level.FINE, "mbean.list_components"); 1298 ConfigContext serverContext = getConfigContext(mInstanceName); 1299 Resources resourcesBean = 1300 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1301 ServerXPathHelper.XPATH_RESOURCES); 1302 JdbcResource[] jdbcResources = resourcesBean.getJdbcResource(); 1303 if (jdbcResources != null) 1304 { 1305 sa = new String [jdbcResources.length]; 1306 for(int i=0; i<jdbcResources.length; i++) 1307 { 1308 sa[i] = jdbcResources[i].getJndiName(); 1309 } 1310 } 1311 } 1312 catch (Exception e) 1313 { 1314 sLogger.log(Level.WARNING, "mbean.list_failed", e); 1315 throw new AFException(e.getLocalizedMessage()); 1316 } 1317 return sa; 1318 } 1319 1320 1323 public void createJavaMailResource(String jndiName, 1324 String host, 1325 String user, 1326 String fromAddress) 1327 throws AFResourceException 1328 { 1329 ArgChecker.checkValid(jndiName, "jndiName", 1330 StringValidator.getInstance()); ArgChecker.checkValid(host, "host", 1332 StringValidator.getInstance()); ArgChecker.checkValid(user, "user", 1334 StringValidator.getInstance()); ArgChecker.checkValid(fromAddress, "fromAddress", 1336 StringValidator.getInstance()); try 1338 { 1339 sLogger.log(Level.FINE, "mbean.create_resource", jndiName); 1340 ConfigContext serverContext = getConfigContext(mInstanceName); 1341 Resources resourcesBean = 1342 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1343 ServerXPathHelper.XPATH_RESOURCES); 1344 MailResource resource = new MailResource(); 1345 resource.setJndiName(jndiName); 1346 resource.setHost(host); 1347 resource.setUser(user); 1348 resource.setFrom(fromAddress); 1349 resourcesBean.addMailResource(resource); 1351 createResourceRef(jndiName); 1352 serverContext.flush(); 1353 1354 } 1355 catch (Exception e) 1356 { 1357 sLogger.log(Level.FINE, "mbean.create_resource_failed", e); 1358 throw new AFResourceException(e.getLocalizedMessage()); 1359 } 1360 } 1361 1362 private void addJavaMailAttribute(Resource resource, 1363 Properties attributes, 1364 String jndiName) 1365 throws AFResourceException 1366 { 1367 try 1369 { 1370 ConfigContext serverContext = getConfigContext(mInstanceName); 1371 Resources resourcesBean = 1372 (Resources)ConfigBeansFactory.getConfigBeanByXPath( 1373 serverContext, 1374 ServerXPathHelper.XPATH_RESOURCES); 1375 MailResource mail_resource = resourcesBean.getMailResourceByJndiName(jndiName); 1376 String sStoreProto = 1377 attributes.getProperty(ResourcesXMLParser.MAIL_STORE_PROTO); 1378 String sStoreProtoClass = 1379 attributes.getProperty(ResourcesXMLParser.MAIL_STORE_PROTO_CLASS); 1380 String sTransProto = 1381 attributes.getProperty(ResourcesXMLParser.MAIL_TRANS_PROTO); 1382 String sTransProtoClass = 1383 attributes.getProperty(ResourcesXMLParser.MAIL_TRANS_PROTO_CLASS); 1384 String sDebug = 1385 attributes.getProperty(ResourcesXMLParser.MAIL_DEBUG); 1386 1389 if (sStoreProto != null) { 1390 mail_resource.setStoreProtocol(sStoreProto); 1391 } 1392 if (sStoreProtoClass != null) { 1393 mail_resource.setStoreProtocolClass(sStoreProtoClass); 1394 } 1395 if (sTransProto != null ) { 1396 mail_resource.setTransportProtocol(sTransProto); 1397 } 1398 if (sTransProtoClass != null) { 1399 mail_resource.setTransportProtocolClass(sTransProtoClass); 1400 } 1401 if (sDebug != null) { 1402 mail_resource.setDebug(Boolean.valueOf(sDebug).booleanValue()); 1403 } 1404 String sDescription = resource.getDescription(); 1409 if (sDescription != null) { 1410 mail_resource.setDescription(sDescription); 1411 } 1412 ElementProperty[] epArray = resource.getElementProperty(); 1414 if (epArray != null) { 1415 for (int ii=0; ii<epArray.length; ii++) 1416 mail_resource.addElementProperty(epArray[ii]); 1417 } 1418 serverContext.flush(); 1419 } 1420 catch (Exception e) 1421 { 1422 throw new AFResourceException(e.getLocalizedMessage()); 1423 } 1424 } 1425 1426 public void deleteJavaMailResource(String jndiName) 1427 throws AFResourceException 1428 { 1429 ArgChecker.checkValid(jndiName, "jndiName", 1430 StringValidator.getInstance()); try 1432 { 1433 sLogger.log(Level.FINE, "mbean.delete_resource", jndiName); 1434 ConfigContext serverContext = getConfigContext(mInstanceName); 1435 Resources resourcesBean = 1436 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1437 ServerXPathHelper.XPATH_RESOURCES); 1438 MailResource resource = 1439 resourcesBean.getMailResourceByJndiName(jndiName); 1440 if (resource == null) 1442 { 1443 String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource", jndiName ); 1444 throw new Exception ( msg ); 1445 } 1446 resourcesBean.removeMailResource(resource); 1447 deleteResourceRef(jndiName); 1448 serverContext.flush(); 1449 } 1450 catch (Exception e) 1451 { 1452 sLogger.log(Level.WARNING, "mbean.delete_resource_failed", e); 1453 throw new AFResourceException(e.getLocalizedMessage()); 1454 } 1455 } 1456 1457 public String [] listJavaMailResources() throws AFException 1458 { 1459 String [] sa = null; 1460 try 1461 { 1462 sLogger.log(Level.FINE, "mbean.list_components"); 1463 ConfigContext serverContext = getConfigContext(mInstanceName); 1464 Resources resourcesBean = 1465 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1466 ServerXPathHelper.XPATH_RESOURCES); 1467 MailResource[] mailResources = resourcesBean.getMailResource(); 1468 if (mailResources != null) 1469 { 1470 sa = new String [mailResources.length]; 1471 for(int i=0; i<mailResources.length; i++) 1472 { 1473 sa[i] = mailResources[i].getJndiName(); 1474 } 1475 } 1476 } 1477 catch (Exception e) 1478 { 1479 sLogger.log(Level.WARNING, "mbean.list_failed", e); 1480 throw new AFException(e.getLocalizedMessage()); 1481 } 1482 return sa; 1483 } 1484 1485 1486 public void createJMSResource(String jndiName, 1487 String resourceType 1488 ) 1489 throws AFResourceException 1490 { 1491 createJMSResource(jndiName, resourceType, new Properties ()); 1492 } 1493 1494 1495 public void createJMSResource(String jndiName, 1496 String resourceType, 1497 Properties props) 1499 throws AFResourceException 1500 { 1501 ArgChecker.checkValid(jndiName, "jndiName", 1502 StringValidator.getInstance()); 1505 ArgChecker.checkValid(resourceType, "resourceType", 1506 StringValidator.getInstance()); 1508 try 1509 { 1510 sLogger.log(Level.FINE, "mbean.create_resource", jndiName); 1511 ConfigContext serverContext = getConfigContext(mInstanceName); 1512 Resources resourcesBean = 1513 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1514 ServerXPathHelper.XPATH_RESOURCES); 1515 JmsRaMapping ramap = ConnectorRuntime.getRuntime().getJmsRaMapping(); 1516 1517 1518 Enumeration en = props.keys(); 1519 Properties properties = new Properties (); 1520 while (en.hasMoreElements()) { 1521 String key = (String ) en.nextElement(); 1522 String raKey = ramap.getMappedName(key); 1523 if (raKey == null) raKey = key; 1524 properties.put(raKey, (String ) props.get(key)); 1525 } 1526 1527 String raName = ConnectorRuntime.getRuntime().DEFAULT_JMS_ADAPTER; 1529 1530 if (resourceType.equalsIgnoreCase("javax.jms.TopicConnectionFactory") || 1531 resourceType.equalsIgnoreCase("javax.jms.QueueConnectionFactory")) 1532 { 1533 String defPoolName = ConnectorRuntime.getRuntime().getDefaultPoolName(jndiName); 1534 com.sun.enterprise.config.serverbeans.ConnectorConnectionPool conPool = 1535 new com.sun.enterprise.config.serverbeans.ConnectorConnectionPool(); 1536 conPool.setResourceAdapterName(raName); 1537 conPool.setConnectionDefinitionName(resourceType); 1538 conPool.setName(defPoolName); 1539 conPool.setMaxPoolSize("250"); 1540 conPool.setSteadyPoolSize("1"); 1541 resourcesBean.addConnectorConnectionPool(conPool); 1542 1543 com.sun.enterprise.config.serverbeans.ConnectorResource resource = 1545 new com.sun.enterprise.config.serverbeans.ConnectorResource(); 1546 resource.setJndiName(jndiName); 1547 resource.setPoolName(defPoolName); 1548 if (properties != null) { 1552 Enumeration e = properties.keys(); 1553 String n,v; 1554 ElementProperty el = null; 1555 while (e.hasMoreElements()) { 1556 n = (String ) e.nextElement(); 1557 v = (String ) properties.get(n); 1558 el = new ElementProperty(); 1559 el.setName(n); 1560 el.setValue(v); 1561 conPool.addElementProperty(el); 1562 } 1563 } 1564 resourcesBean.addConnectorResource(resource); 1565 createResourceRef(jndiName); 1566 } 1567 else { 1568 addAdminObject(resourceType, properties, raName, jndiName); 1570 } 1571 1572 serverContext.flush(); 1573 1574 } 1575 catch (Exception e) 1576 { 1577 sLogger.log(Level.WARNING, "mbean.create_resource_failed", e); 1578 throw new AFResourceException(e.getLocalizedMessage()); 1579 } 1580 } 1581 1582 1583 private void addJMSResourceAttribute(Resource resource, 1584 Properties attributes, 1585 String jndiName) 1586 throws AFResourceException 1587 { 1588 1622 } 1623 1624 1625 public void deleteJMSResource(String jndiName) 1626 throws AFResourceException 1627 { 1628 ArgChecker.checkValid(jndiName, "jndiName", 1629 StringValidator.getInstance()); try 1631 { 1632 ConfigContext serverContext = getConfigContext(mInstanceName); 1635 Resources resourcesBean = 1636 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1637 ServerXPathHelper.XPATH_RESOURCES); 1638 com.sun.enterprise.config.serverbeans.ConnectorResource resource = 1639 resourcesBean.getConnectorResourceByJndiName(jndiName); 1640 1641 if (resource == null) 1642 { 1643 deleteAdminObject(jndiName); 1645 1649 } else { 1650 String defPoolName = ConnectorRuntime.getRuntime().getDefaultPoolName(jndiName); 1651 if (resource.getPoolName().equals(defPoolName)) { 1652 resourcesBean.removeConnectorResource(resource); 1653 deleteConnectorConnectionPool(defPoolName); 1654 } 1655 } 1656 1657 serverContext.flush(); 1658 } 1659 catch (Exception e) 1660 { 1661 sLogger.log(Level.WARNING, "mbean.delete_resource_failed", e); 1662 throw new AFResourceException(e.getLocalizedMessage()); 1663 } 1664 } 1665 1666 1667 public String [] listJMSResources() throws AFException 1668 { 1669 String [] sa = null; 1670 1695 return null; 1696 } 1697 1698 public void createJNDIResource(String jndiName, 1699 String jndiLookupName, 1700 String resourceType, 1701 String factoryClass) 1702 throws AFResourceException 1703 { 1704 ArgChecker.checkValid(jndiName, "jndiName", 1705 StringValidator.getInstance()); ArgChecker.checkValid(jndiLookupName, "jndiLookupName", 1707 StringValidator.getInstance()); ArgChecker.checkValid(resourceType, "resourceType", 1709 StringValidator.getInstance()); ArgChecker.checkValid(factoryClass, "factoryClass", 1711 StringValidator.getInstance()); 1713 try 1714 { 1715 sLogger.log(Level.FINE, "mbean.create_resource", jndiName); 1716 ConfigContext serverContext = getConfigContext(mInstanceName); 1717 Resources resourcesBean = 1718 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1719 ServerXPathHelper.XPATH_RESOURCES); 1720 ExternalJndiResource resource = 1721 new ExternalJndiResource(); 1722 resource.setJndiName(jndiName); 1723 resource.setJndiLookupName(jndiLookupName); 1724 resource.setResType(resourceType); 1725 resource.setFactoryClass(factoryClass); 1726 resourcesBean.addExternalJndiResource(resource); 1728 createResourceRef(jndiName); 1729 serverContext.flush(); 1730 1731 } 1732 catch (Exception e) 1733 { 1734 sLogger.log(Level.WARNING, "mbean.create_resource_failed", e); 1735 throw new AFResourceException(e.getLocalizedMessage()); 1736 } 1737 } 1738 1739 private void addJNDIResourceAttribute(Resource resource, 1740 Properties attributes, 1741 String jndiName) 1742 throws AFResourceException 1743 { 1744 try 1745 { 1746 ConfigContext serverContext = getConfigContext(mInstanceName); 1747 Resources resourcesBean = 1748 (Resources)ConfigBeansFactory.getConfigBeanByXPath( 1749 serverContext, 1750 ServerXPathHelper.XPATH_RESOURCES); 1751 ExternalJndiResource jndi_resource = 1752 resourcesBean.getExternalJndiResourceByJndiName(jndiName); 1753 String sDescription = resource.getDescription(); 1760 if (sDescription != null) { 1761 jndi_resource.setDescription(sDescription); 1762 } 1763 ElementProperty[] epArray = resource.getElementProperty(); 1765 if (epArray != null) { 1766 for (int ii=0; ii<epArray.length; ii++) 1767 jndi_resource.addElementProperty(epArray[ii]); 1768 } 1769 serverContext.flush(); 1770 } 1771 catch (Exception e) 1772 { 1773 throw new AFResourceException(e.getLocalizedMessage()); 1774 } 1775 } 1776 1777 public void deleteJNDIResource(String jndiName) throws AFResourceException 1778 { 1779 ArgChecker.checkValid(jndiName, "jndiName", 1780 StringValidator.getInstance()); try 1782 { 1783 sLogger.log(Level.FINE, "mbean.delete_resource", jndiName); 1784 ConfigContext serverContext = getConfigContext(mInstanceName); 1785 Resources resourcesBean = 1786 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1787 ServerXPathHelper.XPATH_RESOURCES); 1788 ExternalJndiResource resource = 1789 resourcesBean.getExternalJndiResourceByJndiName(jndiName); 1790 if (resource == null) 1792 { 1793 String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource", jndiName ); 1794 throw new Exception ( msg ); 1795 } 1796 resourcesBean.removeExternalJndiResource(resource); 1797 deleteResourceRef(jndiName); 1798 serverContext.flush(); 1799 } 1800 catch (Exception e) 1801 { 1802 sLogger.log(Level.WARNING, "mbean.delete_resource_failed", e); 1803 throw new AFResourceException(e.getLocalizedMessage()); 1804 } 1805 } 1806 1807 public String [] listJNDIResources() throws AFException 1808 { 1809 String [] sa = null; 1810 try 1811 { 1812 sLogger.log(Level.FINE, "mbean.list_components"); 1813 ConfigContext serverContext = getConfigContext(mInstanceName); 1814 Resources resourcesBean = 1815 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1816 ServerXPathHelper.XPATH_RESOURCES); 1817 ExternalJndiResource[] jndiResources = resourcesBean.getExternalJndiResource(); 1818 if (jndiResources != null) 1819 { 1820 sa = new String [jndiResources.length]; 1821 for(int i=0; i<jndiResources.length; i++) 1822 { 1823 sa[i] = jndiResources[i].getJndiName(); 1824 } 1825 } 1826 } 1827 catch (Exception e) 1828 { 1829 sLogger.log(Level.WARNING, "mbean.list_failed", e); 1830 throw new AFException(e.getLocalizedMessage()); 1831 } 1832 return sa; 1833 } 1834 1835 1837 public void createPersistenceManagerFactoryResource(String jndiName) 1838 throws AFResourceException 1839 { 1840 ArgChecker.checkValid(jndiName, "jndiName", 1841 StringValidator.getInstance()); 1843 try 1844 { 1845 sLogger.log(Level.FINE, "mbean.create_resource", jndiName); 1846 ConfigContext serverContext = getConfigContext(mInstanceName); 1847 Resources resourcesBean = 1848 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1849 ServerXPathHelper.XPATH_RESOURCES); 1850 PersistenceManagerFactoryResource resource = 1851 new PersistenceManagerFactoryResource(); 1852 resource.setJndiName(jndiName); 1853 resourcesBean.addPersistenceManagerFactoryResource(resource); 1857 createResourceRef(jndiName); 1858 serverContext.flush(); 1859 1860 } 1861 catch (Exception e) 1862 { 1863 sLogger.log(Level.WARNING, "mbean.create_resource_failed", e); 1864 throw new AFResourceException(e.getLocalizedMessage()); 1865 } 1866 } 1867 1868 private void addPersistenceManagerFactoryAttribute(Resource resource, 1869 Properties attributes, 1870 String jndiName) 1871 throws AFResourceException 1872 { 1873 try 1874 { 1875 ConfigContext serverContext = getConfigContext(mInstanceName); 1876 Resources resourcesBean = 1877 (Resources)ConfigBeansFactory.getConfigBeanByXPath( 1878 serverContext, 1879 ServerXPathHelper.XPATH_RESOURCES); 1880 PersistenceManagerFactoryResource pmf_resource = 1881 resourcesBean.getPersistenceManagerFactoryResourceByJndiName(jndiName); 1882 String factoryClass = 1883 attributes.getProperty(ResourcesXMLParser.FACTORY_CLASS); 1884 String resName = 1885 attributes.getProperty(ResourcesXMLParser.JDBC_RESOURCE_JNDI_NAME); 1886 String sEnabled = 1887 attributes.getProperty(ResourcesXMLParser.ENABLED); 1888 if (factoryClass != null) { 1889 pmf_resource.setFactoryClass(factoryClass); 1890 } 1891 if (resName != null) { 1892 pmf_resource.setJdbcResourceJndiName(resName); 1893 } 1894 String sDescription = resource.getDescription(); 1899 if (sDescription != null) { 1900 pmf_resource.setDescription(sDescription); 1901 } 1902 ElementProperty[] epArray = resource.getElementProperty(); 1904 if (epArray != null) { 1905 for (int ii=0; ii<epArray.length; ii++) 1906 pmf_resource.addElementProperty(epArray[ii]); 1907 } 1908 serverContext.flush(); 1909 } 1910 catch (Exception e) 1911 { 1912 throw new AFResourceException(e.getLocalizedMessage()); 1913 } 1914 } 1915 1916 public void deletePersistenceManagerFactoryResource(String jndiName) 1917 throws AFResourceException 1918 { 1919 ArgChecker.checkValid(jndiName, "jndiName", 1920 StringValidator.getInstance()); try 1922 { 1923 sLogger.log(Level.FINE, "mbean.delete_resource", jndiName); 1924 ConfigContext serverContext = getConfigContext(mInstanceName); 1925 Resources resourcesBean = 1926 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1927 ServerXPathHelper.XPATH_RESOURCES); 1928 PersistenceManagerFactoryResource resource = resourcesBean. 1929 getPersistenceManagerFactoryResourceByJndiName(jndiName); 1930 if (resource == null) 1932 { 1933 String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource" ); 1934 throw new Exception ( msg ); 1935 } 1936 resourcesBean.removePersistenceManagerFactoryResource(resource); 1937 deleteResourceRef(jndiName); 1938 serverContext.flush(); 1939 } 1940 catch (Exception e) 1941 { 1942 sLogger.log(Level.WARNING, "mbean.delete_resource_failed", e); 1943 throw new AFResourceException(e.getLocalizedMessage()); 1944 } 1945 } 1946 1947 public String [] listPersistenceManagerFactoryResources() 1948 throws AFException 1949 { 1950 String [] sa = null; 1951 try 1952 { 1953 sLogger.log(Level.FINE, "mbean.list_components"); 1954 ConfigContext serverContext = getConfigContext(mInstanceName); 1955 Resources resourcesBean = 1956 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1957 ServerXPathHelper.XPATH_RESOURCES); 1958 PersistenceManagerFactoryResource[] pmFactoryResources = 1959 resourcesBean.getPersistenceManagerFactoryResource(); 1960 if (pmFactoryResources != null) 1961 { 1962 sa = new String [pmFactoryResources.length]; 1963 for(int i=0; i<pmFactoryResources.length; i++) 1964 { 1965 sa[i] = pmFactoryResources[i].getJndiName(); 1966 } 1967 } 1968 } 1969 catch (Exception e) 1970 { 1971 sLogger.log(Level.WARNING, "mbean.list_failed", e); 1972 throw new AFException(e.getLocalizedMessage()); 1973 } 1974 return sa; 1975 } 1976 1977 public void createCustomResource(String jndiName, 1978 String resourceType, 1979 String factoryClass) 1980 throws AFResourceException 1981 { 1982 ArgChecker.checkValid(jndiName, "jndiName", 1983 StringValidator.getInstance()); ArgChecker.checkValid(factoryClass, "factoryClass", 1985 StringValidator.getInstance()); ArgChecker.checkValid(resourceType, "resourceType", 1987 StringValidator.getInstance()); 1989 try 1990 { 1991 sLogger.log(Level.FINE, "mbean.create_resource", jndiName); 1992 ConfigContext serverContext = getConfigContext(mInstanceName); 1993 Resources resourcesBean = 1994 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 1995 ServerXPathHelper.XPATH_RESOURCES); 1996 CustomResource resource = new CustomResource(); 1997 resource.setJndiName(jndiName); 1998 resource.setResType(resourceType); 1999 resource.setFactoryClass(factoryClass); 2000 resourcesBean.addCustomResource(resource); 2002 createResourceRef(jndiName); 2003 serverContext.flush(); 2004 } 2005 catch (Exception e) 2006 { 2007 sLogger.log(Level.WARNING, "mbean.create_resource_failed", e); 2008 throw new AFResourceException(e.getLocalizedMessage()); 2009 } 2010 } 2011 2012 private void addCustomResourceAttribute(Resource resource, 2013 Properties attributes, 2014 String jndiName) 2015 throws AFResourceException 2016 { 2017 try 2018 { 2019 ConfigContext serverContext = getConfigContext(mInstanceName); 2020 Resources resourcesBean = 2021 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 2022 ServerXPathHelper.XPATH_RESOURCES); 2023 CustomResource custom_resource = 2024 resourcesBean.getCustomResourceByJndiName(jndiName); 2025 String sEnabled = 2026 attributes.getProperty(ResourcesXMLParser.ENABLED); 2027 String sDescription = resource.getDescription(); 2032 if (sDescription != null) { 2033 custom_resource.setDescription(sDescription); 2034 } 2035 ElementProperty[] epArray = resource.getElementProperty(); 2037 if (epArray != null) { 2038 for (int ii=0; ii<epArray.length; ii++) 2039 custom_resource.addElementProperty(epArray[ii]); 2040 } 2041 serverContext.flush(); 2042 } 2043 catch (Exception e) 2044 { 2045 throw new AFResourceException(e.getLocalizedMessage()); 2046 } 2047 } 2048 2049 public void deleteCustomResource(String jndiName) 2050 throws AFResourceException 2051 { 2052 ArgChecker.checkValid(jndiName, "jndiName", 2053 StringValidator.getInstance()); try 2055 { 2056 sLogger.log(Level.FINE, "mbean.delete_resource", jndiName); 2057 ConfigContext serverContext = getConfigContext(mInstanceName); 2058 Resources resourcesBean = 2059 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 2060 ServerXPathHelper.XPATH_RESOURCES); 2061 CustomResource resource = 2062 resourcesBean.getCustomResourceByJndiName(jndiName); 2063 if (resource == null) 2065 { 2066 String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource", jndiName ); 2067 throw new Exception ( msg ); 2068 } 2069 resourcesBean.removeCustomResource(resource); 2070 deleteResourceRef(jndiName); 2071 serverContext.flush(); 2072 } 2073 catch (Exception e) 2074 { 2075 sLogger.log(Level.WARNING, "mbean.delete_resource_failed", e); 2076 throw new AFResourceException(e.getLocalizedMessage()); 2077 } 2078 } 2079 2080 public String [] listCustomResources() throws AFException 2081 { 2082 String [] sa = null; 2083 try 2084 { 2085 sLogger.log(Level.FINE, "mbean.list_components"); 2086 ConfigContext serverContext = getConfigContext(mInstanceName); 2087 Resources resourcesBean = 2088 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 2089 ServerXPathHelper.XPATH_RESOURCES); 2090 CustomResource[] customResources = resourcesBean.getCustomResource(); 2091 if (customResources != null) 2092 { 2093 sa = new String [customResources.length]; 2094 for(int i=0; i<customResources.length; i++) 2095 { 2096 sa[i] = customResources[i].getJndiName(); 2097 } 2098 } 2099 } 2100 catch (Exception e) 2101 { 2102 sLogger.log(Level.WARNING, "mbean.list_failed", e); 2103 throw new AFException(e.getLocalizedMessage()); 2104 } 2105 return sa; 2106 } 2107 2108 2110 public void setHttpPort(int port) 2111 { 2112 } 2113 2114 public HostAndPort getHostAndPort() throws ServerInstanceException 2115 { 2116 return getHostAndPort(false); 2117 } 2118 2119 public HostAndPort getHostAndPort(boolean securityEnabled) throws ServerInstanceException 2120 { 2121 HostAndPort hAndp = null; 2122 try 2123 { 2124 Config config = (Config) super.getConfigBeanByXPath(ServerXPathHelper.XPATH_CONFIG); 2126 HttpService https = config.getHttpService(); 2127 2128 HttpListener[] hlArray = https.getHttpListener(); 2129 HttpListener ls = hlArray[0]; 2132 for(int i = 0;i<hlArray.length;i++) { 2134 if(hlArray[i].isEnabled() && (hlArray[i].isSecurityEnabled()==securityEnabled)) { 2135 ls = hlArray[i]; 2136 break; 2137 } 2138 } 2139 2140 String port = ls.getPort(); 2141 int intPort = Integer.parseInt (port); 2142 hAndp = new HostAndPort(ls.getServerName(), intPort); 2143 } 2144 catch (Exception e) 2145 { 2146 throw new ServerInstanceException(e.getLocalizedMessage()); 2147 } 2148 return hAndp; 2149 } 2150 2151 public int getHttpPort() 2152 { 2153 return 9000; 2154 } 2155 2156 public ServerInstanceStatus getStatus() throws ControlException 2157 { 2158 int statusCode = getInstanceStatusCode(); 2159 ServerInstanceStatus status = new ServerInstanceStatus(statusCode); 2160 if (isDebug()) 2162 { 2163 status.setDebug(true); 2164 try 2165 { 2166 status.setDebugPort(getDebugPort()); 2167 } 2168 catch (Exception e) 2169 { 2170 sLogger.finest 2171 ("Problem with getting port:ManagedServerInstance:getStatus"); 2172 throw new ControlException(e.getLocalizedMessage()); 2173 } 2174 } 2175 sLogger.exiting(getClass().getName(), "getStatus", 2176 status.getStatusString()); return ( status ); 2178 } 2179 2180 2185 public boolean isRestartNeeded() 2186 { 2187 AdminEventCache cache = AdminEventCache.getInstance(mInstanceName); 2188 boolean restartRequired = cache.isInstanceRestartNeeded(); 2189 if(restartRequired) 2190 { 2191 RMIClient rc = AdminChannel.getRMIClient(mInstanceName); 2192 if(!rc.isAlive()) 2193 restartRequired = false; 2194 } 2195 return restartRequired; 2196 } 2197 2198 private boolean isAlive() 2199 { 2200 boolean alive = false; 2201 RMIClient serverInstancePinger = AdminChannel. 2202 getRMIClient(mInstanceName); 2203 2204 alive = serverInstancePinger.isAlive(); 2205 return ( alive ); 2206 } 2207 2208 private int getInstanceStatusCode() { 2209 int statusCode = Status.kInstanceNotRunningCode; 2210 RMIClient serverInstancePinger = AdminChannel.getRMIClient(mInstanceName); 2211 statusCode = serverInstancePinger.getInstanceStatusCode(); 2212 return statusCode; 2213 } 2214 2215 2223 public void reconfigure() 2224 { 2225 } 2226 2227 2232 2233 public boolean isApplyNeeded() throws ServerInstanceException 2234 { 2235 return isApplyNeeded(true); 2236 } 2237 2238 2239 2243 public boolean isApplyNeeded(boolean checkAllFiles) throws ServerInstanceException 2244 { 2245 boolean applyNeeded = false; 2246 try 2247 { 2248 ConfigContext serverContext = getConfigContext(mInstanceName); 2249 applyNeeded = serverContext.isChanged(); 2250 } 2251 catch (ConfigException e) 2252 { 2253 throw new ServerInstanceException(e.getMessage()); 2254 } 2255 if (!applyNeeded && checkAllFiles) { 2256 InstanceEnvironment ie = new InstanceEnvironment(mInstanceName); 2257 applyNeeded = ie.hasRealmsKeyConfFileChanged(); 2258 } 2259 return applyNeeded; 2260 } 2261 2262 2268 public boolean overwriteConfigChanges() throws ServerInstanceException 2269 { 2270 try { 2271 return applyChanges(true); 2272 } catch (AFRuntimeStoreException e) { 2273 InstanceEnvironment ie = new InstanceEnvironment(mInstanceName); 2274 2275 if(ie.canReloadManualXmlChanges()) { 2276 try { 2277 ie.useManualServerXmlChanges(); 2278 reloadAfterChange(ie); 2279 } catch(ConfigException ce) { 2280 } 2282 return true; 2283 } else { 2284 throw e; 2285 } 2286 } 2287 2288 } 2289 2295 public boolean applyConfigChanges() throws ServerInstanceException 2296 { 2297 return applyChanges(false); 2298 } 2299 2300 private boolean applyChanges(boolean force) throws ServerInstanceException 2301 { 2302 boolean requiresRestart = false; 2303 try 2304 { 2305 InstanceEnvironment instanceEnv = new InstanceEnvironment(mInstanceName); 2306 2307 boolean hasConfChanges = false; 2308 boolean hasMimeChanges = false; 2309 hasConfChanges = instanceEnv.hasRealmsKeyConfFileChanged(); 2310 2311 2312 instanceEnv.applyChangesFromBackup(force); 2313 2315 2316 this.transform(instanceEnv); 2317 2318 2319 2320 requiresRestart = sendNotificationOnApply(hasConfChanges, hasMimeChanges); 2321 2322 } 2323 catch (ConfigException e) 2324 { 2325 throw new ServerInstanceException(e.getMessage()); 2326 } 2327 return requiresRestart; 2328 } 2329 2330 public boolean canApplyConfigChanges() throws ConfigException { 2331 boolean b = false; 2332 InstanceEnvironment ie = new InstanceEnvironment(mInstanceName); 2333 if(AdminService.ENABLE_PERFORMANCE_THREAD) { 2334 b = (!ManualChangeManager.hasHotChanged(mInstanceName)); 2335 } else { 2336 b = (!ie.hasHotChanged()); 2337 } 2338 if((!b) && ie.canReloadManualXmlChanges()) { 2339 ie.useManualServerXmlChanges(); 2340 reloadAfterChange(ie); 2341 boolean requiresRestart = ie.restartRequired(); 2342 if (requiresRestart) { 2343 AdminEventCache cache = 2346 AdminEventCache.getInstance(mInstanceName); 2347 cache.setRestartNeeded(true); 2348 } 2349 return true; 2350 } 2351 return b; 2352 } 2353 2354 void reloadAfterChange(InstanceEnvironment instanceEnv) throws ConfigException 2355 { 2356 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 2358 ObjectName [] objectNames = ObjectNameHelper.getInstanceRelatedMBeans(mbs, mInstanceName); 2359 for(int i=0; i<objectNames.length; i++) 2360 { 2361 try 2362 { 2363 mbs.unregisterMBean(objectNames[i]); 2364 } 2365 catch(Exception e) 2366 { 2367 sLogger.log(Level.WARNING, "Exception: ", e); 2368 } 2369 } 2370 String fileUrl = instanceEnv.getBackupConfigFilePath(); 2372 ConfigFactory.removeConfigContext(fileUrl); 2373 2374 2379 } 2380 2381 public boolean useManualConfigChanges() throws ServerInstanceException 2382 { 2383 boolean requiresRestart = false; 2384 try 2385 { 2386 InstanceEnvironment instanceEnv = new InstanceEnvironment(mInstanceName); 2387 2388 instanceEnv.useManualConfigChanges(); 2390 2391 reloadAfterChange(instanceEnv); 2392 2393 2395 this.transform(instanceEnv); 2396 2397 requiresRestart = instanceEnv.restartRequired(); 2398 if (requiresRestart) { 2399 AdminEventCache cache = 2402 AdminEventCache.getInstance(mInstanceName); 2403 cache.setRestartNeeded(true); 2404 } 2405 } 2406 catch (ConfigException e) 2407 { 2408 throw new ServerInstanceException(e.getMessage()); 2409 } 2410 return requiresRestart; 2411 } 2412 2429 public void startMonitor() 2430 { 2431 } 2432 2433 2439 public String [] getMonitorableComponentNames() 2440 { 2441 return ( null ); 2442 } 2443 2444 2453 public void stopMonitor() 2454 { 2455 } 2456 2457 2459 public void createLifeCycleModule(String moduleName, String className) 2460 throws AFException 2461 { 2462 ArgChecker.checkValid(moduleName, "moduleName", 2463 StringValidator.getInstance()); ArgChecker.checkValid(className, "className", 2465 StringValidator.getInstance()); 2467 try 2468 { 2469 sLogger.log(Level.FINEST, "mbean.create_lifecycle", moduleName); 2470 ConfigContext serverContext = getConfigContext(mInstanceName); 2471 Applications applicationsConfigBean = 2472 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 2473 serverContext, 2474 ServerXPathHelper.XPATH_APPLICATIONS); 2475 LifecycleModule module = new LifecycleModule(); 2476 module.setName(moduleName); 2477 module.setClassName(className); 2478 applicationsConfigBean.addLifecycleModule(module); 2480 createResourceRef(moduleName); 2481 serverContext.flush(); 2482 } 2483 catch (Exception e) 2484 { 2485 sLogger.log(Level.WARNING, "mbean.create_lifecycle_failed", e); 2486 throw new AFException(e.getMessage()); 2487 } 2488 } 2489 2490 2492 public void deleteLifeCycleModule(String moduleName) throws AFException 2493 { 2494 ArgChecker.checkValid(moduleName, "moduleName", 2495 StringValidator.getInstance()); try 2497 { 2498 sLogger.log(Level.FINEST, "mbean.delete_lifecycle", moduleName); 2499 ConfigContext serverContext = getConfigContext(mInstanceName); 2500 Applications applicationsConfigBean = 2501 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 2502 serverContext, 2503 ServerXPathHelper.XPATH_APPLICATIONS); 2504 LifecycleModule module = 2505 applicationsConfigBean.getLifecycleModuleByName(moduleName); 2506 applicationsConfigBean.removeLifecycleModule(module); 2507 deleteResourceRef(moduleName); 2508 serverContext.flush(); 2509 } 2510 catch (Exception e) 2511 { 2512 sLogger.log(Level.WARNING, "mbean.delete_lifecycle_failed", e); 2513 throw new AFException(e.getMessage()); 2514 } 2515 } 2516 2517 2519 public String [] listLifeCycleModules() throws AFException 2520 { 2521 String [] modules = new String [0]; 2522 try 2523 { 2524 sLogger.log(Level.FINEST, "mbean.list_components"); 2525 ConfigContext serverContext = getConfigContext(mInstanceName); 2526 Applications applicationsConfigBean = 2527 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 2528 serverContext, 2529 ServerXPathHelper.XPATH_APPLICATIONS); 2530 LifecycleModule[] lifecycleConfigBeans = 2531 applicationsConfigBean.getLifecycleModule(); 2532 if ((lifecycleConfigBeans != null) && 2533 (lifecycleConfigBeans.length > 0)) 2534 { 2535 modules = new String [lifecycleConfigBeans.length]; 2536 for (int i = 0; i < lifecycleConfigBeans.length; i++) 2537 { 2538 modules[i] = lifecycleConfigBeans[i].getName(); 2539 } 2540 } 2541 } 2542 catch (Exception e) 2543 { 2544 sLogger.log(Level.WARNING, "mbean.list_failed", e); 2545 throw new AFException(e.getMessage()); 2546 } 2547 return modules; 2548 } 2549 2550 2560 public String getClientStubJarLocation(String appName, int appType) 2561 throws AFException 2562 { 2563 ArgChecker.checkValid(appName, "appName", StringValidator.getInstance()); 2565 if ((appType != DeploymentConstants.EAR) && 2566 (appType != DeploymentConstants.EJB)) 2567 { 2568 String msg = localStrings.getString( "admin.server.core.mbean.config.expected_application_type" ); 2569 throw new AFException( msg ); 2570 } 2571 String clientJarLocation = null; 2572 try 2573 { 2574 ConfigContext serverContext = getConfigContext(mInstanceName); 2575 InstanceEnvironment iEnv = new InstanceEnvironment(mInstanceName); 2576 Applications applicationsConfigBean = 2577 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 2578 serverContext, ServerXPathHelper.XPATH_APPLICATIONS); 2579 String appLocation = null; 2580 switch (appType) 2581 { 2582 case DeploymentConstants.EAR : 2583 J2eeApplication app = applicationsConfigBean. 2584 getJ2eeApplicationByName(appName); 2585 AppsManager appsManager = new AppsManager(iEnv); 2586 appLocation = appsManager.getGeneratedXMLLocation(appName); 2587 2588 if (appLocation == null || 2591 !FileUtils.safeIsDirectory(appLocation)) { 2592 appLocation = app.getLocation(); 2593 } 2594 break; 2595 case DeploymentConstants.EJB : 2596 EjbModule module = applicationsConfigBean. 2597 getEjbModuleByName(appName); 2598 EjbModulesManager ejbManager = new EjbModulesManager(iEnv); 2599 appLocation = ejbManager.getGeneratedXMLLocation(appName); 2600 2601 if (appLocation == null || 2604 !FileUtils.safeIsDirectory(appLocation)) { 2605 appLocation = module.getLocation(); 2606 } 2607 break; 2608 } 2609 clientJarLocation = appLocation + java.io.File.separator + 2610 appName + AdminConstants.CLIENT_JAR; 2611 sLogger.log(Level.INFO, "mbean.cl_jar_loc", clientJarLocation); 2612 } 2613 catch (Exception e) 2614 { 2615 throw new AFException(e.getLocalizedMessage()); 2616 } 2617 return clientJarLocation; 2618 } 2619 2620 2630 public String getWsdlFileLocation(String appName, String moduleName, int appType, String wsdlFileUri) 2631 throws AFException 2632 { 2633 ArgChecker.checkValid(appName, "appName", StringValidator.getInstance()); 2635 if ((appType != DeploymentConstants.EAR) && 2636 (appType != DeploymentConstants.EJB) && 2637 (appType != DeploymentConstants.WAR)) 2638 { 2639 String msg = localStrings.getString( "admin.server.core.mbean.config.expected_application_type" ); 2640 throw new AFException( msg ); 2641 } 2642 String wsdlFileLocation = null; 2643 try 2644 { 2645 ConfigContext serverContext = getConfigContext(mInstanceName); 2646 InstanceEnvironment iEnv = new InstanceEnvironment(mInstanceName); 2647 Applications applicationsConfigBean = 2648 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 2649 serverContext, ServerXPathHelper.XPATH_APPLICATIONS); 2650 String appLocation = null; 2651 AbstractArchive moduleArchive = null; 2652 switch (appType) 2653 { 2654 case DeploymentConstants.EAR : 2655 AppsManager appsManager = new AppsManager(iEnv); 2656 appLocation = appsManager.getGeneratedXMLLocation(appName); 2657 if (appLocation == null || !FileUtils.safeIsDirectory(appLocation)) { 2658 J2eeApplication app = applicationsConfigBean. 2659 getJ2eeApplicationByName(appName); 2660 appLocation = app.getLocation(); 2661 } 2662 break; 2663 case DeploymentConstants.EJB : 2664 EjbModulesManager ejbManager = new EjbModulesManager(iEnv); 2665 appLocation = ejbManager.getGeneratedXMLLocation(appName); 2666 if (appLocation == null || !FileUtils.safeIsDirectory(appLocation)) { 2667 EjbModule module = applicationsConfigBean. 2668 getEjbModuleByName(appName); 2669 appLocation = module.getLocation(); 2670 } 2671 break; 2672 case DeploymentConstants.WAR: 2673 WebModulesManager webManager = new WebModulesManager(iEnv); 2674 appLocation = webManager.getGeneratedXMLLocation(appName); 2675 if (appLocation == null || !FileUtils.safeIsDirectory(appLocation)) { 2676 WebModule webModule = applicationsConfigBean. 2677 getWebModuleByName(appName); 2678 appLocation = webModule.getLocation(); 2679 } 2680 break; 2681 } 2682 2683 FileArchive appArchive = new FileArchive(); 2684 appArchive.open(appLocation); 2685 if (moduleName!=null) { 2686 moduleArchive = appArchive.getEmbeddedArchive(moduleName); 2687 } else { 2688 moduleArchive = appArchive; 2689 } 2690 wsdlFileLocation = moduleArchive.getArchiveUri() + java.io.File.separator + 2691 wsdlFileUri.replace('/', java.io.File.separatorChar); 2692 } 2693 catch (Exception e) 2694 { 2695 throw new AFException(e.getLocalizedMessage()); 2696 } 2697 return wsdlFileLocation; 2698 } 2699 2700 2701 2702 2709 public void postRegister(Boolean registrationDone) 2710 { 2711 } 2712 2713 2727 public ObjectName preRegister(MBeanServer server, ObjectName name) throws 2728 Exception 2729 { 2730 ObjectName serverInstanceMBeanObjectName = null; 2731 serverInstanceMBeanObjectName = new ObjectName ("ias:type=serverinstance, name="); 2732 return ( serverInstanceMBeanObjectName ); 2733 } 2734 2735 2739 public void postDeregister() 2740 { 2741 } 2742 2743 2750 public void preDeregister() throws Exception 2751 { 2752 } 2753 2754 2755 2756 2760 2761 private void registerApplicationMBean(String archiveName) 2762 throws MBeanException 2763 { 2764 ObjectName appObjectName = 2765 ObjectNames.getApplicationObjectName(mInstanceName, archiveName); 2766 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 2767 if (!mbs.isRegistered(appObjectName)) 2768 { 2769 try 2770 { 2771 ManagedJ2EEApplication app = 2772 new ManagedJ2EEApplication(mInstanceName, archiveName, 2773 this.getAdminContext()); 2774 2775 mbs.registerMBean(app, appObjectName); 2776 } 2777 catch (javax.management.InstanceAlreadyExistsException iae) 2778 { 2779 ExceptionUtil.ignoreException(iae); 2780 } 2781 catch (Exception e) 2782 { 2783 throw new MBeanException (e); 2784 } 2785 } 2786 } 2787 2788 private void registerEJBModuleMBean(String archiveName) 2789 throws MBeanException 2790 { 2791 ObjectName moduleObjectName = 2792 ObjectNames.getEjbModuleObjectName(mInstanceName, archiveName); 2793 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 2794 if (!mbs.isRegistered(moduleObjectName)) 2795 { 2796 try 2797 { 2798 ManagedStandaloneJ2EEEjbJarModule module = 2799 new ManagedStandaloneJ2EEEjbJarModule(mInstanceName, 2800 archiveName, this.getAdminContext()); 2801 mbs.registerMBean(module, moduleObjectName); 2802 } 2803 catch (javax.management.InstanceAlreadyExistsException iae) 2804 { 2805 ExceptionUtil.ignoreException(iae); 2806 } 2807 catch (Exception e) 2808 { 2809 throw new MBeanException (e); 2810 } 2811 } 2812 } 2813 2814 private void registerWebModuleMBean(String archiveName) 2815 { 2816 ObjectName moduleObjectName = 2817 ObjectNames.getWebModuleObjectName(mInstanceName, archiveName); 2818 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 2819 if (!mbs.isRegistered(moduleObjectName)) 2820 { 2821 2824 } 2825 } 2826 2827 private void registerConnectorModuleMBean(String archiveName) 2828 { 2829 ObjectName moduleObjectName = ObjectNames.getConnectorModuleObjectName( 2830 mInstanceName, archiveName); 2831 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 2832 if (!mbs.isRegistered(moduleObjectName)) 2833 { 2834 2837 } 2838 } 2839 2840 2874 2875 ConfigContext getConfigContext(String instanceName) 2876 throws ConfigException 2877 { 2878 2882 2883 2889 return getConfigContext(); 2890 } 2891 2892 2896 2897 private String getModuleTypeString(int moduleType) 2898 { 2899 String moduleTypeString = null; 2900 switch (moduleType) 2901 { 2902 case DeploymentConstants.EJB : 2903 moduleTypeString = ModuleDeployEvent.TYPE_EJBMODULE; 2904 break; 2905 case DeploymentConstants.WAR : 2906 moduleTypeString = ModuleDeployEvent.TYPE_WEBMODULE; 2907 break; 2908 case DeploymentConstants.RAR : 2909 moduleTypeString = ModuleDeployEvent.TYPE_CONNECTOR; 2910 break; 2911 } 2912 return moduleTypeString; 2913 } 2914 2915 2919 2920 private boolean multicastEvent(int eventType, String entityName) 2921 throws DeploymentException 2922 { 2923 return multicastEvent(eventType, entityName, null); 2924 } 2925 2926 public boolean multicastEvent(int eventType, String entityName, 2927 String moduleType) throws DeploymentException { 2928 return multicastEvent(eventType, entityName, moduleType, false); 2929 } 2930 2931 2938 public boolean multicastEvent(int eventType, String entityName, 2939 String moduleType , boolean cascade) throws DeploymentException { 2940 return multicastEvent(eventType, entityName, moduleType, cascade, false, null); 2941 } 2942 2943 2944 2951 public boolean multicastEvent(int eventType, String entityName, 2952 String moduleType , boolean cascade, boolean forceDeploy, String targetName) throws DeploymentException 2953 { 2954 String name = getInstanceName(); 2955 AdminEvent event = null; 2956 EventBuilder builder = new EventBuilder(); 2957 2958 EventStack stack = EventContext.getEventStackFromThreadLocal(); 2960 ConfigContext ctx = stack.getConfigContext(); 2961 stack.setTarget(targetName); 2962 stack.setConfigChangeList(ctx.getConfigChangeList()); 2963 2964 try{ 2965 if (eventType == BaseDeployEvent.APPLICATION_DEPLOYED) 2966 { 2967 event = builder.createApplicationDeployEvent( 2968 BaseDeployEvent.DEPLOY, entityName, false, forceDeploy); 2969 } 2970 else if (eventType == BaseDeployEvent.APPLICATION_UNDEPLOYED) 2971 { 2972 event = builder.createApplicationDeployEvent( 2973 BaseDeployEvent.UNDEPLOY, entityName, cascade, forceDeploy); 2974 } 2975 else if (eventType == BaseDeployEvent.APPLICATION_REDEPLOYED) 2976 { 2977 event = builder.createApplicationDeployEvent( 2978 BaseDeployEvent.REDEPLOY, entityName, false, forceDeploy); 2979 } 2980 else if (eventType == BaseDeployEvent.MODULE_DEPLOYED) 2981 { 2982 event = builder.createModuleDeployEvent( 2983 BaseDeployEvent.DEPLOY, entityName, moduleType, cascade, forceDeploy); 2984 } 2985 else if (eventType == BaseDeployEvent.MODULE_UNDEPLOYED) 2986 { 2987 event = builder.createModuleDeployEvent( 2988 BaseDeployEvent.UNDEPLOY, entityName, moduleType, cascade, forceDeploy); 2989 } 2990 else if (eventType == BaseDeployEvent.MODULE_REDEPLOYED) 2991 { 2992 event = builder.createModuleDeployEvent( 2993 BaseDeployEvent.REDEPLOY, entityName, moduleType); 2994 } 2995 else if (eventType == BaseDeployEvent.APPLICATION_ENABLE) 2996 { 2997 event = builder.createApplicationDeployEvent( 2998 BaseDeployEvent.ENABLE, entityName, false, forceDeploy); 2999 } 3000 else if (eventType == BaseDeployEvent.APPLICATION_DISABLE) 3001 { 3002 event = builder.createApplicationDeployEvent( 3003 BaseDeployEvent.DISABLE, entityName, false, forceDeploy); 3004 } 3005 else if(eventType == BaseDeployEvent.MODULE_ENABLE) 3006 { 3007 event = builder.createModuleDeployEvent( 3008 BaseDeployEvent.ENABLE, entityName, moduleType, false, forceDeploy); 3009 } 3010 else if(eventType == BaseDeployEvent.MODULE_DISABLE) 3011 { 3012 event = builder.createModuleDeployEvent( 3013 BaseDeployEvent.DISABLE, entityName, moduleType, false, forceDeploy); 3014 } 3015 else if(eventType == BaseDeployEvent.APPLICATION_REFERENCED) 3016 { 3017 event = builder.createApplicationDeployEvent( 3018 BaseDeployEvent.ADD_REFERENCE, entityName, false, forceDeploy); 3019 } 3020 else if(eventType == BaseDeployEvent.APPLICATION_UNREFERENCED) 3021 { 3022 event = builder.createApplicationDeployEvent( 3023 BaseDeployEvent.REMOVE_REFERENCE, entityName, false, forceDeploy); 3024 } 3025 else if (eventType == CONFIG_CHANGED) 3026 { 3027 event = builder.createConfigChangeEvent(targetName, null); 3028 } 3029 else 3030 { 3031 String msg = 3032 localStrings.getString( "admin.server.core.mbean.config.no_such_event", 3033 new Integer (eventType) ); 3034 throw new RuntimeException ( msg ); 3035 } 3036 } catch (ConfigException ex) { 3037 DeploymentException de = new DeploymentException(ex.getMessage()); 3038 de.initCause(ex); 3039 throw de; 3040 } 3041 3042 if (targetName != null) { 3044 event.setTargetDestination(targetName); 3045 } 3046 3047 3048 this.transform(new InstanceEnvironment(name)); 3049 3050 3051 if (event instanceof ApplicationDeployEvent 3052 || event instanceof ModuleDeployEvent) { 3053 AdminEventCache.populateConfigChange(getConfigContext(), event); 3054 } 3055 int statusCode = getInstanceStatusCode(); 3056 if (statusCode == Status.kInstanceStoppingCode || statusCode == Status.kInstanceNotRunningCode) { 3057 sLogger.log(Level.INFO, "mbean.inst_down_skip_event", mInstanceName); 3058 return true; 3059 } 3060 if (sLogger.isLoggable(Level.FINEST)) { 3061 sLogger.log(Level.FINEST, "mbean.event_sent", event.getEventInfo()); 3062 } else { 3063 sLogger.log(Level.INFO, "mbean.send_event", event.toString()); 3064 } 3065 3066 AdminEventResult multicastResult = 3067 AdminEventMulticaster.multicastEvent(event); 3068 sLogger.log(Level.FINE, "mbean.event_res", 3069 multicastResult.getResultCode()); 3070 sLogger.log(Level.INFO, "mbean.event_reply", 3071 multicastResult.getAllMessagesAsString()); 3072 boolean eventSuccess = true; 3073 if (!AdminEventResult.SUCCESS.equals(multicastResult.getResultCode())) { 3074 AdminEventCache cache = 3075 AdminEventCache.getInstance(mInstanceName); 3076 cache.setRestartNeeded(true); 3077 3078 AdminEventListenerException ale = null; 3081 ale = multicastResult.getFirstAdminEventListenerException(); 3082 if (ale != null) { 3083 sLogger.log(Level.WARNING, "mbean.event_failed", 3084 ale.getMessage()); 3085 DeploymentException de = 3086 new DeploymentException(ale.getMessage()); 3087 de.initCause(ale); 3088 throw de; 3089 } 3090 } 3091 return eventSuccess; 3092 } 3093 3094 public String getInstanceName() { 3095 return mInstanceName; 3096 } 3097 3098 3108 private boolean sendNotificationOnApply(boolean confFilesChanged, 3109 boolean mimeFilesChanged) throws ConfigException { 3110 ConfigContext context = getConfigContext(mInstanceName); 3111 AdminEventCache cache = 3112 AdminEventCache.getInstance(mInstanceName); 3113 ArrayList changeList = context.getConfigChangeList(); 3114 context.resetConfigChangeList(); 3115 cache.processConfigChangeList(changeList, confFilesChanged, 3116 mimeFilesChanged); 3117 ArrayList eventList = cache.getAndResetCachedEvents(); 3118 if (getInstanceStatusCode() != Status.kInstanceRunningCode) { 3119 sLogger.log(Level.INFO, "mbean.inst_down_skip_event", mInstanceName); 3120 return false; 3121 } 3122 boolean requiresRestart = cache.isInstanceRestartNeeded(); 3123 Iterator iter = eventList.iterator(); 3124 while (iter.hasNext()) { 3125 AdminEvent event = (AdminEvent)iter.next(); 3126 if (sLogger.isLoggable(Level.FINEST)) { 3127 sLogger.log(Level.FINEST, "mbean.event_sent", 3128 event.getEventInfo()); 3129 } else { 3130 sLogger.log(Level.INFO, "mbean.send_event", event.toString()); 3131 } 3132 AdminEventResult result = AdminEventMulticaster.multicastEvent(event); 3133 sLogger.log(Level.FINE, "mbean.event_res", result.getResultCode()); 3134 sLogger.log(Level.FINEST, "mbean.event_reply", 3135 result.getAllMessagesAsString()); 3136 if (!AdminEventResult.SUCCESS.equals(result.getResultCode())) 3137 { 3138 requiresRestart = true; 3139 cache.setRestartNeeded(true); 3140 sLogger.log(Level.INFO, "applyChanges: AdminEventMulticaster.multiCastEvent indicates serverRestart=true , resultCode=" + result.getResultCode(), event.toString()); 3142 sLogger.log(Level.WARNING, "mbean.notif_failed"); 3143 } 3144 } 3145 return requiresRestart; 3146 } 3147 3148 3152 private void deleteFile(String filePath) 3153 { 3154 File f = new File (filePath); 3155 if (f.exists()) 3156 { 3157 File parentDir = f.getParentFile(); 3158 File tmpDir = new File (AdminService.getAdminService(). 3159 getTempDirPath(), mInstanceName); 3160 3161 if (tmpDir != null && tmpDir.equals(parentDir)) 3162 { 3163 boolean couldDelete = f.delete(); 3164 if (couldDelete) 3165 { 3166 sLogger.log(Level.FINE, "mbean.delete_temp_file_ok", filePath); 3167 } 3168 else 3169 { 3170 sLogger.log(Level.INFO, "mbean.delete_temp_file_failed", filePath); 3171 } 3172 } 3173 } 3174 } 3175 3176 private boolean isAppExists(String appName, int appType) 3177 { 3178 ConfigBean appConfigBean = null; 3179 try 3180 { 3181 ConfigContext serverContext = super.getConfigContext(); 3182 Applications applicationsConfigBean = 3183 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 3184 serverContext, 3185 ServerXPathHelper.XPATH_APPLICATIONS); 3186 if (applicationsConfigBean != null) 3187 { 3188 switch (appType) 3189 { 3190 case DeploymentConstants.EAR : 3191 { 3192 appConfigBean = applicationsConfigBean. 3193 getJ2eeApplicationByName(appName); 3194 break; 3195 } 3196 case DeploymentConstants.EJB : 3197 { 3198 appConfigBean = applicationsConfigBean. 3199 getEjbModuleByName(appName); 3200 break; 3201 } 3202 case DeploymentConstants.WAR : 3203 { 3204 appConfigBean = applicationsConfigBean. 3205 getWebModuleByName(appName); 3206 break; 3207 } 3208 case DeploymentConstants.RAR : 3209 { 3210 appConfigBean = applicationsConfigBean. 3211 getConnectorModuleByName(appName); 3212 break; 3213 } 3214 } 3215 } 3216 } 3217 catch (Exception e) 3218 { 3219 sLogger.log(Level.WARNING, "appexists failed", e); } 3221 return (appConfigBean != null); 3222 } 3223 3224 3228 private boolean isAppExists(String moduleName, ModuleType moduleType) 3229 { 3230 ConfigBean moduleConfigBean = null; 3231 try 3232 { 3233 ConfigContext serverContext = super.getConfigContext(); 3234 Applications applicationsConfigBean = 3235 (Applications) ConfigBeansFactory.getConfigBeanByXPath( 3236 serverContext, 3237 ServerXPathHelper.XPATH_APPLICATIONS); 3238 if (applicationsConfigBean != null) 3239 { 3240 if (moduleType.equals(ModuleType.EAR)) 3241 { 3242 moduleConfigBean = applicationsConfigBean. 3243 getJ2eeApplicationByName(moduleName); 3244 } else 3245 if (moduleType.equals(ModuleType.EJB)) 3246 { 3247 moduleConfigBean = applicationsConfigBean. 3248 getEjbModuleByName(moduleName); 3249 } else 3250 if (moduleType.equals(ModuleType.WAR)) 3251 { 3252 moduleConfigBean = applicationsConfigBean. 3253 getWebModuleByName(moduleName); 3254 } else 3255 if (moduleType.equals(ModuleType.RAR)) 3256 { 3257 moduleConfigBean = applicationsConfigBean. 3258 getConnectorModuleByName(moduleName); 3259 } 3260 } 3261 } 3262 catch (Exception e) 3263 { 3264 sLogger.log(Level.WARNING, "appexists failed", e); } 3266 return (moduleConfigBean != null); 3267 } 3268 3269 3270 3271 3274 private final boolean isDebug() 3275 { 3276 boolean isDebug = false; 3277 try 3278 { 3279 JavaConfig jvmConfig = getJavaConfigBean(); 3280 String value = jvmConfig.getAttributeValue( 3281 ServerTags.DEBUG_ENABLED); 3282 if (value != null) 3283 { 3284 isDebug = Boolean.valueOf(value).booleanValue(); 3285 } 3286 } 3287 catch (Exception e) 3288 { 3289 sLogger.log(Level.WARNING, "mbean.is_debug_failed", e); 3290 } 3291 return isDebug; 3292 } 3293 3294 3297 private final void setDebug(boolean debug) throws Exception 3298 { 3299 JavaConfig jvmConfig = getJavaConfigBean(); 3300 String value = String.valueOf(debug); 3301 jvmConfig.setAttributeValue(ServerTags.DEBUG_ENABLED, value); 3302 } 3303 3304 3307 private final void setDebugOptions(String options) throws Exception 3308 { 3309 JavaConfig jvmConfig = getJavaConfigBean(); 3310 jvmConfig.setAttributeValue(ServerTags.DEBUG_OPTIONS, options); 3311 } 3312 3313 3316 private final String getDebugOptions() throws Exception 3317 { 3318 JavaConfig jvmConfig = getJavaConfigBean(); 3319 return jvmConfig.getAttributeValue(ServerTags.DEBUG_OPTIONS); 3320 } 3321 3322 3325 private final String getDefaultDebugOptions() throws Exception 3326 { 3327 return JavaConfig.getDefaultAttributeValue(ServerTags.DEBUG_OPTIONS); 3328 } 3329 3330 private final int getDebugPort() throws Exception 3331 { 3332 int debugPort = -1; 3333 final String debugOptions = getDebugOptions(); 3334 if (debugOptions != null) 3335 { 3336 int index = debugOptions.indexOf("-Xrunjdwp"); 3337 if (index >= 0) 3338 { 3339 final String jdwpOption = debugOptions.substring(index); 3340 index = jdwpOption.indexOf("address="); 3341 if (index >= 0) 3342 { 3343 final String nvPairs = jdwpOption.substring(index); 3344 StringTokenizer optionTok = 3345 new StringTokenizer (nvPairs, "=, "); 3346 optionTok.nextToken(); String portValue = optionTok.nextToken(); 3348 debugPort = Integer.parseInt(portValue); 3349 } 3350 } 3351 } 3352 return debugPort; 3353 } 3354 3355 3358 private final void setDebugPort(int port) throws Exception 3359 { 3360 StringBuffer sb = new StringBuffer (); 3361 String debugOptions = getDefaultDebugOptions(); 3362 StringTokenizer strTok = new StringTokenizer (debugOptions, " "); 3363 while (strTok.hasMoreTokens()) 3364 { 3365 String option = strTok.nextToken(); 3366 sb.append(option); 3367 if (option.startsWith("-Xrunjdwp")) 3368 { 3369 sb.append(",address=" + port); 3370 } 3371 if (strTok.hasMoreTokens()) 3372 { 3373 sb.append(' '); 3374 } 3375 } 3376 debugOptions = sb.toString(); 3377 debugOptions += " -Xnoagent -Djava.compiler=NONE"; 3380 sLogger.log(Level.INFO, "mbean.debug_options", debugOptions); 3381 setDebugOptions(debugOptions); 3382 } 3383 3384 private final JavaConfig getJavaConfigBean() throws Exception 3385 { 3386 Config config = (Config) super.getConfigBeanByXPath(ServerXPathHelper.XPATH_CONFIG); 3389 JavaConfig jvmConfig = config.getJavaConfig(); 3390 jvmConfig.setConfigContext(super.getConfigContext()); 3391 return jvmConfig; 3392 } 3393 3394 3395 private FileRealm getInstanceRealmKeyFile() throws MBeanConfigException 3399 { 3400 InstanceEnvironment env = new InstanceEnvironment(mInstanceName); 3401 try 3402 { 3403 return new FileRealm(env.getBackupRealmsKeyFilePath()); 3404 } 3405 catch(BadRealmException bre) 3406 { 3407 throw new MBeanConfigException(bre.getMessage()); 3409 } 3410 catch(NoSuchRealmException nsr) 3411 { 3412 throw new MBeanConfigException(nsr.getMessage()); 3414 } 3415 3416 } 3417 private void saveInstanceRealmKeyFile(FileRealm realm) throws MBeanConfigException 3418 { 3419 InstanceEnvironment env = new InstanceEnvironment(mInstanceName); 3420 try 3421 { 3422 final String filePath = env.getBackupRealmsKeyFilePath(); 3423 sLogger.log(Level.INFO, "filerealm.write", filePath); 3424 realm.writeKeyFile(filePath); 3425 } 3426 catch(IOException ioe) 3427 { 3428 sLogger.log(Level.WARNING, "filerealm.writeerror", ioe); 3430 throw new MBeanConfigException(ioe.getMessage()); 3431 } 3432 } 3433 3434 3435 private String [] convertEnumerationToStringArray(Enumeration e) 3436 { 3437 ArrayList list = new ArrayList (); 3438 while(e.hasMoreElements()) 3439 list.add(e.nextElement()); 3440 return (String [])list.toArray(new String [list.size()]); 3441 } 3442 3443 3446 public String [] getUserNames() throws MBeanConfigException 3447 { 3448 FileRealm realm = getInstanceRealmKeyFile(); 3449 try 3450 { 3451 return convertEnumerationToStringArray(realm.getUserNames()); 3452 } 3453 catch(BadRealmException bre) 3454 { 3455 throw new MBeanConfigException(bre.getMessage()); 3457 } 3458 } 3459 3460 3463 public String [] getGroupNames() throws MBeanConfigException 3464 { 3465 FileRealm realm = getInstanceRealmKeyFile(); 3466 try 3467 { 3468 return convertEnumerationToStringArray(realm.getGroupNames()); 3469 } 3470 catch(BadRealmException bre) 3471 { 3472 throw new MBeanConfigException(bre.getMessage()); 3474 } 3475 } 3476 3477 3480 public String [] getUserGroupNames(String userName) throws MBeanConfigException 3481 { 3482 FileRealm realm = getInstanceRealmKeyFile(); 3483 try 3484 { 3485 return convertEnumerationToStringArray(realm.getGroupNames(userName)); 3486 } 3487 catch(NoSuchUserException nse) 3488 { 3489 throw new MBeanConfigException(nse.getMessage()); 3491 } 3492 } 3493 3494 3497 public void addUser(String userName, String password, String [] groupList) throws MBeanConfigException 3498 { 3499 FileRealm realm = getInstanceRealmKeyFile(); 3500 try 3501 { 3502 realm.addUser(userName, password, groupList); 3503 saveInstanceRealmKeyFile(realm); 3504 } 3505 catch(BadRealmException bre) 3506 { 3507 throw new MBeanConfigException(bre.getMessage()); 3509 } 3510 catch(IASSecurityException ise) 3511 { 3512 throw new MBeanConfigException(ise.getMessage()); 3514 } 3515 3516 } 3517 3518 3521 public void removeUser(String userName) throws MBeanConfigException 3522 { 3523 FileRealm realm = getInstanceRealmKeyFile(); 3524 try 3525 { 3526 realm.removeUser(userName); 3527 saveInstanceRealmKeyFile(realm); 3528 } 3529 catch(NoSuchUserException nse) 3530 { 3531 throw new MBeanConfigException(nse.getMessage()); 3533 } 3534 } 3535 3536 3539 public void updateUser(String userName, String password, String [] groupList) throws MBeanConfigException 3540 { 3541 FileRealm realm = getInstanceRealmKeyFile(); 3542 try 3543 { 3544 realm.updateUser(userName, userName, password, groupList); 3545 saveInstanceRealmKeyFile(realm); 3546 } 3547 catch(BadRealmException bre) 3548 { 3549 throw new MBeanConfigException(bre.getMessage()); 3551 } 3552 catch(NoSuchUserException nse) 3553 { 3554 throw new MBeanConfigException(nse.getMessage()); 3556 } 3557 catch(IASSecurityException ise) 3558 { 3559 throw new MBeanConfigException(ise.getMessage()); 3561 } 3562 } 3563 3564 3568 private void testDeployedFile(String archiveName, boolean bDirectory) throws DeploymentException 3569 { 3570 if(archiveName==null) 3571 { 3572 String msg = localStrings.getString( "admin.server.core.mbean.config.deploy_null_name"); 3573 throw new DeploymentException(msg); 3574 } 3575 File f = new File (archiveName); 3576 if(bDirectory && !f.isDirectory()) 3577 { 3578 String msg = localStrings.getString( "admin.server.core.mbean.config.deploy_not_directory", archiveName); 3579 throw new DeploymentException(msg); 3580 } 3581 else 3582 if(!bDirectory && !f.isFile()) 3583 { 3584 String msg = localStrings.getString( "admin.server.core.mbean.config.deploy_not_file", archiveName); 3585 throw new DeploymentException(msg); 3586 } 3587 } 3588 3589 3592 public String getInstanceRoot() 3593 { 3594 InstanceEnvironment env = new InstanceEnvironment(mInstanceName); 3595 return env.getInstancesRoot(); 3596 } 3597 3598 3604 private void checkWebModuleReferences(String webModuleName) 3605 throws ConfigException 3606 { 3607 ArrayList virtualServerIds = new ArrayList (); 3608 3609 ConfigContext context = super.getConfigContext(); 3610 Config config = (Config) super.getConfigBeanByXPath(ServerXPathHelper.XPATH_CONFIG); 3612 HttpService httpService = config.getHttpService(); 3613 VirtualServer[] virtualServers = httpService.getVirtualServer(); 3614 for (int j = 0; j < virtualServers.length; j++) 3615 { 3616 VirtualServer aServer = virtualServers[j]; 3617 String defWebModule = aServer.getDefaultWebModule(); 3618 if ((defWebModule != null) && 3619 (defWebModule.equals(webModuleName))) 3620 { 3621 virtualServerIds.add(aServer.getId()); 3622 } 3623 } 3624 if (!virtualServerIds.isEmpty()) 3625 { 3626 throw new ConfigException(localStrings.getString( 3627 "admin.server.core.mbean.config.def_web_module_refs_exist", 3628 virtualServerIds.toString(), webModuleName)); 3629 } 3630 } 3631 3632 private void setDeployDirOwner(DeploymentRequest request, 3633 InstanceEnvironment env) { 3634 3650 } 3651 3652 private void chownDir(File dir, String user) { 3653 if (dir == null || user == null || user.trim().equals("")) { 3654 return; 3655 } 3656 String err = null; 3657 3658 3665 } 3666 3667 public void addAdminObject(String type, Properties properties, String raName, String jndiName) 3669 throws AFResourceException 3670 { 3671 3677 3678 try 3679 { 3680 sLogger.log(Level.FINE, "mbean.create_admin_object_resource", jndiName); 3681 ConfigContext serverContext = getConfigContext(mInstanceName); 3682 Resources resourcesBean = 3683 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 3684 ServerXPathHelper.XPATH_RESOURCES); 3685 AdminObjectResource resource = new AdminObjectResource(); 3686 resource.setJndiName(jndiName); 3687 resource.setResType(type); 3688 resource.setResAdapter(raName); 3689 resourcesBean.addAdminObjectResource(resource); 3690 Enumeration e = properties.keys(); 3692 String n, v; 3693 ElementProperty el = null; 3694 while (e.hasMoreElements()) { 3695 n = (String ) e.nextElement(); 3696 v = (String ) properties.get(n); 3697 el = new ElementProperty(); 3698 el.setName(n); 3699 el.setValue(v); 3700 resource.addElementProperty(el); 3701 } 3702 createResourceRef(jndiName); 3703 serverContext.flush(); 3704 3705 } 3706 catch (Exception e) 3707 { 3708 sLogger.log(Level.WARNING, "mbean.create_resource_failed", e); 3709 throw new AFResourceException(e.getLocalizedMessage()); 3710 } 3711 } 3712 3713 public void deleteAdminObject(String jndiName) 3714 throws AFResourceException 3715 { 3716 3720 sLogger.log(Level.FINE, "mbean.delele_admin_object", jndiName); 3721 try 3722 { 3723 ConfigContext serverContext = getConfigContext(mInstanceName); 3724 Resources resourcesBean = 3725 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 3726 ServerXPathHelper.XPATH_RESOURCES); 3727 com.sun.enterprise.config.serverbeans.AdminObjectResource resource = 3728 resourcesBean.getAdminObjectResourceByJndiName(jndiName); 3729 3730 if (resource == null) 3731 { 3732 String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource", jndiName ); 3733 throw new Exception ( msg ); 3734 } 3735 resourcesBean.removeAdminObjectResource(resource); 3736 deleteResourceRef(jndiName); 3737 serverContext.flush(); 3738 } 3739 catch (Exception e) 3740 { 3741 sLogger.log(Level.WARNING, "mbean.delete_connector_connection_pool_failed", e); 3742 throw new AFResourceException(e.getLocalizedMessage()); 3743 } 3744 } 3745 3746 public String [] listAdminObjects() throws AFException 3747 { 3748 String [] sa = null; 3749 try 3750 { 3751 sLogger.log(Level.FINE, "mbean.list_components"); 3752 ConfigContext serverContext = getConfigContext(mInstanceName); 3753 Resources resourcesBean = 3754 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 3755 ServerXPathHelper.XPATH_RESOURCES); 3756 com.sun.enterprise.config.serverbeans.AdminObjectResource[] resources = 3757 resourcesBean.getAdminObjectResource(); 3758 if (resources != null) 3759 { 3760 sa = new String [resources.length]; 3761 for(int i=0; i<resources.length; i++) 3762 { 3763 sa[i] = resources[i].getJndiName(); 3764 } 3765 } 3766 } 3767 catch (Exception e) 3768 { 3769 sLogger.log(Level.WARNING, "mbean.list_failed", e); 3770 throw new AFException(e.getLocalizedMessage()); 3771 } 3772 return sa; 3773 } 3774 3775 3776 3777 3778 public void createConnectorConnectionPool(String raName, String conDefn, String steadyPoolSize, 3779 String maxPoolSize, String maxWaitTime, String poolResizeQty, String idleTimeout, 3780 Boolean failAllConns, Properties properties, String poolName) 3781 throws AFResourceException 3782 { 3783 3789 3790 try 3791 { 3792 sLogger.log(Level.FINE, "mbean.create_connector_connection_pool", poolName); 3793 ConfigContext serverContext = getConfigContext(mInstanceName); 3794 Resources resourcesBean = 3795 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 3796 ServerXPathHelper.XPATH_RESOURCES); 3797 com.sun.enterprise.config.serverbeans.ConnectorConnectionPool conPool = 3798 new com.sun.enterprise.config.serverbeans.ConnectorConnectionPool(); 3799 conPool.setResourceAdapterName(raName); 3800 conPool.setConnectionDefinitionName(conDefn); 3801 if (steadyPoolSize != null) conPool.setSteadyPoolSize(steadyPoolSize); 3802 if (maxPoolSize != null) conPool.setMaxPoolSize(maxPoolSize); 3803 if (maxWaitTime != null) conPool.setMaxWaitTimeInMillis(maxWaitTime); 3804 if (poolResizeQty != null) conPool.setPoolResizeQuantity(poolResizeQty); 3805 if (idleTimeout != null) conPool.setIdleTimeoutInSeconds(idleTimeout); 3806 if (failAllConns != null) conPool.setFailAllConnections(failAllConns.booleanValue()); 3807 conPool.setName(poolName); 3808 resourcesBean.addConnectorConnectionPool(conPool); 3809 if (properties != null) { 3811 Enumeration e = properties.keys(); 3812 String n, v; 3813 ElementProperty el = null; 3814 while (e.hasMoreElements()) { 3815 n = (String ) e.nextElement(); 3816 v = (String ) properties.get(n); 3817 el = new ElementProperty(); 3818 el.setName(n); 3819 el.setValue(v); 3820 conPool.addElementProperty(el); 3821 } 3822 } 3823 serverContext.flush(); 3824 3825 } 3826 catch (Exception e) 3827 { 3828 sLogger.log(Level.WARNING, "mbean.create_resource_failed", e); 3829 throw new AFResourceException(e.getLocalizedMessage()); 3830 } 3831 } 3832 3833 public void deleteConnectorConnectionPool(String poolName) 3834 throws AFResourceException 3835 { 3836 ArgChecker.checkValid(poolName, "poolName", 3837 StringValidator.getInstance()); sLogger.log(Level.FINE, "mbean.delele_connector_connection_pool", poolName); 3839 try 3840 { 3841 ConfigContext serverContext = getConfigContext(mInstanceName); 3842 Resources resourcesBean = 3843 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 3844 ServerXPathHelper.XPATH_RESOURCES); 3845 com.sun.enterprise.config.serverbeans.ConnectorConnectionPool resource = 3846 resourcesBean.getConnectorConnectionPoolByName(poolName); 3847 3848 if (resource == null) 3849 { 3850 3854 } 3855 resourcesBean.removeConnectorConnectionPool(resource); 3856 serverContext.flush(); 3857 } 3858 catch (Exception e) 3859 { 3860 sLogger.log(Level.WARNING, "mbean.delete_connector_connection_pool_failed", e); 3861 throw new AFResourceException(e.getLocalizedMessage()); 3862 } 3863 } 3864 3865 public String [] listConnectorConnectionPools() throws AFException 3866 { 3867 String [] sa = null; 3868 try 3869 { 3870 sLogger.log(Level.FINE, "mbean.list_components"); 3871 ConfigContext serverContext = getConfigContext(mInstanceName); 3872 Resources resourcesBean = 3873 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 3874 ServerXPathHelper.XPATH_RESOURCES); 3875 com.sun.enterprise.config.serverbeans.ConnectorConnectionPool[] connectionPools = 3876 resourcesBean.getConnectorConnectionPool(); 3877 if (connectionPools != null) 3878 { 3879 sa = new String [connectionPools.length]; 3880 for(int i=0; i<connectionPools.length; i++) 3881 { 3882 sa[i] = connectionPools[i].getName(); 3883 } 3884 } 3885 } 3886 catch (Exception e) 3887 { 3888 sLogger.log(Level.WARNING, "mbean.list_failed", e); 3889 throw new AFException(e.getLocalizedMessage()); 3890 } 3891 return sa; 3892 } 3893 3894 3897 public void createConnectorResource(String jndiName, String poolName, String description, 3898 Boolean enabled, Properties properties ) 3899 throws AFResourceException 3900 { 3901 3907 try 3908 { 3909 sLogger.log(Level.FINE, "mbean.create_resource", jndiName); 3910 ConfigContext serverContext = getConfigContext(mInstanceName); 3911 Resources resourcesBean = 3912 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 3913 ServerXPathHelper.XPATH_RESOURCES); 3914 3920 3921 com.sun.enterprise.config.serverbeans.ConnectorResource resource = 3922 new com.sun.enterprise.config.serverbeans.ConnectorResource(); 3923 resource.setJndiName(jndiName); 3924 resource.setPoolName(poolName); 3925 if (description != null) resource.setDescription(description); 3926 resourcesBean.addConnectorResource(resource); 3928 if (properties != null) { 3930 Enumeration e = properties.keys(); 3931 String n, v; 3932 ElementProperty el = null; 3933 while (e.hasMoreElements()) { 3934 n = (String ) e.nextElement(); 3935 v = (String ) properties.get(n); 3936 el = new ElementProperty(); 3937 el.setName(n); 3938 el.setValue(v); 3939 resource.addElementProperty(el); 3940 } 3941 } 3942 createResourceRef(jndiName); 3943 serverContext.flush(); 3944 3945 } 3946 catch (Exception e) 3947 { 3948 sLogger.log(Level.WARNING, "mbean.create_resource_failed", e); 3949 throw new AFResourceException(e.getLocalizedMessage()); 3950 } 3951 } 3952 3953 public void deleteConnectorResource(String jndiName) 3954 throws AFResourceException 3955 { 3956 3960 sLogger.log(Level.FINE, "mbean.delete_connector_resource", jndiName); 3961 try 3962 { 3963 ConfigContext serverContext = getConfigContext(mInstanceName); 3964 Resources resourcesBean = 3965 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 3966 ServerXPathHelper.XPATH_RESOURCES); 3967 com.sun.enterprise.config.serverbeans.ConnectorResource resource = 3968 resourcesBean.getConnectorResourceByJndiName(jndiName); 3969 3970 if (resource == null) 3971 { 3972 String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource", jndiName ); 3973 throw new Exception ( msg ); 3974 } 3975 resourcesBean.removeConnectorResource(resource); 3976 deleteResourceRef(jndiName); 3977 serverContext.flush(); 3978 } 3979 catch (Exception e) 3980 { 3981 sLogger.log(Level.WARNING, "mbean.delete_connector_connection_pool_failed", e); 3982 throw new AFResourceException(e.getLocalizedMessage()); 3983 } 3984 } 3985 3986 public String [] listConnectorResources() throws AFException 3987 { 3988 String [] sa = null; 3989 try 3990 { 3991 sLogger.log(Level.FINE, "mbean.list_components"); 3992 ConfigContext serverContext = getConfigContext(mInstanceName); 3993 Resources resourcesBean = 3994 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 3995 ServerXPathHelper.XPATH_RESOURCES); 3996 com.sun.enterprise.config.serverbeans.ConnectorResource[] resources = 3997 resourcesBean.getConnectorResource(); 3998 if (resources != null) 3999 { 4000 sa = new String [resources.length]; 4001 for(int i=0; i<resources.length; i++) 4002 { 4003 sa[i] = resources[i].getJndiName(); 4004 } 4005 } 4006 } 4007 catch (Exception e) 4008 { 4009 sLogger.log(Level.WARNING, "mbean.list_failed", e); 4010 throw new AFException(e.getLocalizedMessage()); 4011 } 4012 return sa; 4013 } 4014 4015 private void transform(InstanceEnvironment ie) { 4016 if (PORT_DOMAIN_TO_SERVER) { 4017 final String domainXMLPath = ie.getConfigFilePath(); 4018 final String serverXMLPath = java.lang.System.getProperty(Constants.IAS_ROOT) 4019 + "/" 4020 + ie.getName() 4021 + "/config/" 4022 + ie.kServerXMLFileName; 4023 new Domain2ServerTransformer(domainXMLPath, serverXMLPath).transform(); 4024 } 4025 4026 } 4027 4028 public String [] listConnectorJMSResources(String type) throws AFException 4029 { 4030 Vector v = new Vector (); 4031 String [] sa = null; 4032 int j = 0; 4033 try 4034 { 4035 sLogger.log(Level.FINE, "mbean.list_jms_resources"); 4036 ConfigContext serverContext = getConfigContext(mInstanceName); 4037 Resources resourcesBean = 4038 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext, 4039 ServerXPathHelper.XPATH_RESOURCES); 4040 if (type == null || type.equals("javax.jms.TopicConnectionFactory") || 4042 type.equals("javax.jms.QueueConnectionFactory")) { 4043 com.sun.enterprise.config.serverbeans.ConnectorResource[] resources = 4044 resourcesBean.getConnectorResource(); 4045 if (resources != null) 4046 { 4047 sa = new String [resources.length]; 4048 for(int i=0; i<resources.length; i++) 4049 { 4050 String jndiName = resources[i].getJndiName(); 4051 String defPoolName = ConnectorRuntime.getRuntime().getDefaultPoolName(jndiName); 4052 if (resources[i].getPoolName().equals(defPoolName) ) { 4053 com.sun.enterprise.config.serverbeans.ConnectorConnectionPool poolResource = 4054 resourcesBean.getConnectorConnectionPoolByName(defPoolName); 4055 if (type == null || (poolResource != null && poolResource.getConnectionDefinitionName().equals(type))) { 4056 v.addElement(resources[i].getJndiName()); 4057 } 4058 } 4059 } 4060 } 4061 } 4062 if (type == null || type.equals("javax.jms.Topic") || 4064 type.equals("javax.jms.Queue")) { 4065 com.sun.enterprise.config.serverbeans.AdminObjectResource[] resources = 4066 resourcesBean.getAdminObjectResource(); 4067 if (resources != null) 4068 { 4069 sa = new String [resources.length]; 4070 for(int i=0; i<resources.length; i++) 4071 { 4072 if (type == null || resources[i].getResType().equals(type)) { 4073 v.addElement(resources[i].getJndiName()); 4074 } 4075 } 4076 } 4077 } 4078 4079 } 4080 catch (Exception e) 4081 { 4082 sLogger.log(Level.WARNING, "mbean.list_jms_resources_failed", e); 4083 throw new AFException(e.getLocalizedMessage()); 4084 } 4085 sa = new String [v.size()]; 4086 for (int k = 0; k < sa.length; k++) 4087 sa[k] = (String ) v.elementAt(k); 4088 return sa; 4089 } 4090 4091 4092 4093} 4094 | Popular Tags |