2 Replies Latest reply on Nov 18, 2010 6:19 AM by Jonathan Clarke

    Forcing an EAR Shutdown on Exception

    Jonathan Clarke Newbie

      Dear All,

      I am trying to find a way to shut down/undeploy an EAR when an arbitrary exception is detected somewhere in my source. However, I can't find a way to remove the EAR from the container. Is there an event and then call through Seam to JBoss to undeploy an EAR? Once the exception is detected, I would then want to run code that forces a clean shutdown of the EAR, including and backing up of datafiles etc.


        • 1. Re: Forcing an EAR Shutdown on Exception
          Philippe Aubertin Newbie

          You can use JMX to interact with your server:

          Jboss should probably provide you a librairy.

          Here an example with WebLogic (found on the net).

          Hope this help.

          import java.io.*;
          import weblogic.deploy.api.tools.*;  //SesionHelper
          import weblogic.deploy.api.spi .*;  //WebLogicDeploymentManager
          import weblogic.deploy.api.spi.DeploymentOptions;
          import javax.enterprise.deploy.spi.TargetModuleID;
          import javax.enterprise.deploy.spi.status.ProgressObject;
          import javax.enterprise.deploy.spi.status.DeploymentStatus;
          import javax.enterprise.deploy.shared.ModuleType;
          import javax.enterprise.deploy.spi.Target;
          public class ApplicationUndeployment
          public static void main(String ar[]) throws Exception
          ApplicationUndeployment appDeploy=new ApplicationUndeployment();
          String protocol=”t3″;
          String hostName=”localhost”;
          String portString=”7001″;
          String adminUser=”weblogic”;
          String adminPassword=”weblogic”;
          WebLogicDeploymentManager deployManager=SessionHelper.getRemoteDeploymentManager( protocol,hostName,portString,adminUser,adminPassword);
          System.out.println(“\n\t WebLogicDeploymentManager: “+deployManager);
          DeploymentOptions options = new DeploymentOptions();
          System.out.println(“\n\t DeploymentOptions: “+options);
          TargetModuleID[] targetModuleIDs=deployManager.getAvailableModules(ModuleType.EAR, deployManager.getTargets());
          System.out.println(“targetModuleIDs length: “+targetModuleIDs.length);
          for(int i=0;i<targetModuleIDs.length;i++)
          System.out.println(“\n\n\tUNDEPLOYING——- targetModuleIDs["+i+"]: “+targetModuleIDs[i]);
          ProgressObject processStatus=deployManager.undeploy(new TargetModuleID[]{targetModuleIDs[i]});
          DeploymentStatus deploymentStatus=processStatus.getDeploymentStatus() ;
          System.out.println(“UnDeploymentStayus.getMessage(): “+deploymentStatus.getMessage() );

          • 2. Re: Forcing an EAR Shutdown on Exception
            Jonathan Clarke Newbie

            Many thanks. Will give this a go.