2011/08/05 - Jakarta Cactus has been retired.

For more information, please explore the Attic.

Clover coverage report - Cactus 1.8dev for J2EE API 1.3
Coverage timestamp: Sun Mar 26 2006 18:50:18 BRT
file stats: LOC: 316   Methods: 11
NCLOC: 158   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
WebLogic7xContainer.java 0% 0% 0% 0%
coverage
 1   
 /* 
 2   
  * ========================================================================
 3   
  * 
 4   
  * Copyright 2003 The Apache Software Foundation.
 5   
  *
 6   
  * Licensed under the Apache License, Version 2.0 (the "License");
 7   
  * you may not use this file except in compliance with the License.
 8   
  * You may obtain a copy of the License at
 9   
  * 
 10   
  *   http://www.apache.org/licenses/LICENSE-2.0
 11   
  * 
 12   
  * Unless required by applicable law or agreed to in writing, software
 13   
  * distributed under the License is distributed on an "AS IS" BASIS,
 14   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15   
  * See the License for the specific language governing permissions and
 16   
  * limitations under the License.
 17   
  * 
 18   
  * ========================================================================
 19   
  */
 20   
 package org.apache.cactus.integration.ant.container.weblogic;
 21   
 
 22   
 import java.io.File;
 23   
 import java.io.IOException;
 24   
 
 25   
 import org.apache.cactus.integration.ant.container.AbstractJavaContainer;
 26   
 import org.apache.cactus.integration.ant.util.ResourceUtils;
 27   
 import org.apache.tools.ant.BuildException;
 28   
 import org.apache.tools.ant.taskdefs.Jar;
 29   
 import org.apache.tools.ant.taskdefs.Java;
 30   
 import org.apache.tools.ant.types.FilterChain;
 31   
 import org.apache.tools.ant.types.Path;
 32   
 import org.apache.tools.ant.types.ZipFileSet;
 33   
 import org.apache.tools.ant.util.FileUtils;
 34   
 
 35   
 /**
 36   
  * Special container support for the Bea WebLogic 7.x application server.
 37   
  * 
 38   
  * TODO: this doesn't work for me on JDK 1.3.1 and WL 7.0 SP2
 39   
  * 
 40   
  * @version $Id: WebLogic7xContainer.java 239130 2005-01-29 15:49:18Z vmassol $
 41   
  */
 42   
 public class WebLogic7xContainer extends AbstractJavaContainer
 43   
 {
 44   
 
 45   
     // Instance Variables ------------------------------------------------------
 46   
 
 47   
     /**
 48   
      * The Bea home directory.
 49   
      */
 50   
     private File beaHome;
 51   
 
 52   
     /**
 53   
      * The WebLogic 7.x installation directory. For example:
 54   
      * "c:\bea\weblogic700".
 55   
      */
 56   
     private File dir;
 57   
 
 58   
     /**
 59   
      * The port to which the container should be bound.
 60   
      */
 61   
     private int port = 8080;
 62   
 
 63   
     /**
 64   
      * A user-specific <code>config.xml</code> WebLogic configuration file. 
 65   
      * If this variable is not set, the default configuration file from the 
 66   
      * JAR resources will be used.
 67   
      */
 68   
     private File configXml;
 69   
     
 70   
     /**
 71   
      * The temporary directory from which the container will be started.
 72   
      */
 73   
     private File tmpDir;
 74   
 
 75   
     // Public Methods ----------------------------------------------------------
 76   
 
 77   
     /**
 78   
      * Sets the Bea home directory.
 79   
      * 
 80   
      * @param theBeaHome The BEA home directory
 81   
      */
 82  0
     public final void setBeaHome(File theBeaHome)
 83   
     {
 84  0
         this.beaHome = theBeaHome;
 85   
     }
 86   
 
 87   
     /**
 88   
      * Sets the WebLogic 7.x installation directory.
 89   
      * 
 90   
      * @param theDir The directory to set
 91   
      */
 92  0
     public final void setDir(File theDir)
 93   
     {
 94  0
         this.dir = theDir;
 95   
     }
 96   
 
 97   
     /**
 98   
      * Sets the port to which the container should listen.
 99   
      * 
 100   
      * @param thePort The port to set
 101   
      */
 102  0
     public final void setPort(int thePort)
 103   
     {
 104  0
         this.port = thePort;
 105   
     }
 106   
 
 107   
     /**
 108   
      * Sets the configuration file to use for the test installation of 
 109   
      * WebLogic.
 110   
      * 
 111   
      * @param theConfigXml The custom <code>config.xml</code> file
 112   
      */
 113  0
     public final void setConfigXml(File theConfigXml)
 114   
     {
 115  0
         this.configXml = theConfigXml;
 116   
     }
 117   
     
 118   
     /**
 119   
      * Sets the temporary installation directory.
 120   
      * 
 121   
      * @param theTmpDir The temporary directory to set
 122   
      */
 123  0
     public final void setTmpDir(File theTmpDir)
 124   
     {
 125  0
         this.tmpDir = theTmpDir;
 126   
     }
 127   
 
 128   
     // AbstractContainer Implementation ----------------------------------------
 129   
 
 130   
     /**
 131   
      * @see org.apache.cactus.integration.ant.container.Container#getName
 132   
      */
 133  0
     public final String getName()
 134   
     {
 135  0
         return "WebLogic 7.x";
 136   
     }
 137   
 
 138   
     /**
 139   
      * Returns the port to which the container should listen.
 140   
      * 
 141   
      * @return The port
 142   
      */
 143  0
     public final int getPort()
 144   
     {
 145  0
         return this.port;
 146   
     }
 147   
 
 148   
     /**
 149   
      * @see org.apache.cactus.integration.ant.container.Container#init
 150   
      */
 151  0
     public final void init()
 152   
     {
 153  0
         if (!this.dir.isDirectory())
 154   
         {
 155  0
             throw new BuildException(this.dir + " is not a directory");
 156   
         }
 157   
 
 158   
         // If the beaHome attribute is not set, guess the bea home
 159   
         // directory using the parent directory of this.dir 
 160  0
         if (this.beaHome == null)
 161   
         {
 162  0
             getLog().debug("Extrapolating beaHome to be ["
 163   
                 + this.dir.getParentFile() + "]");
 164  0
             this.beaHome = this.dir.getParentFile();
 165   
         }
 166   
     }
 167   
 
 168   
     /**
 169   
      * @see org.apache.cactus.integration.ant.container.Container#startUp
 170   
      */
 171  0
     public final void startUp()
 172   
     {
 173  0
         try
 174   
         {
 175  0
             prepare("cactus/weblogic7x");
 176   
             
 177  0
             Java java = createJavaForStartUp();
 178  0
             java.setDir(new File(this.tmpDir, "testdomain"));
 179   
             
 180  0
             java.createJvmarg().setValue("-hotspot");
 181  0
             java.createJvmarg().setValue("-Xms32m");
 182  0
             java.createJvmarg().setValue("-Xmx200m");
 183   
             
 184  0
             File serverDir = new File(this.dir, "server");
 185   
             
 186  0
             java.addSysproperty(
 187   
                 createSysProperty("weblogic.Name", "testserver"));
 188  0
             java.addSysproperty(
 189   
                 createSysProperty("bea.home", this.beaHome));
 190  0
             java.addSysproperty(
 191   
                 createSysProperty("weblogic.management.username", "weblogic"));
 192  0
             java.addSysproperty(
 193   
                 createSysProperty("weblogic.management.password", "weblogic"));
 194   
 
 195   
             // Note: The "=" in the call below is on purpose. It is left so that
 196   
             // we end up with: 
 197   
             //   -Djava.security.policy==./server/lib/weblogic.policy
 198   
             // (otherwise, we would end up with:
 199   
             //   -Djava.security.policy=./server/lib/weblogic.policy, which
 200   
             //  will not add to the security policy but instead replace it).
 201  0
             java.addSysproperty(
 202   
                 createSysProperty("java.security.policy",
 203   
                     "=./server/lib/weblogic.policy"));
 204   
 
 205  0
             Path classpath = java.createClasspath();
 206  0
             classpath.createPathElement().setLocation(
 207   
                 new File(serverDir, "lib/weblogic_sp.jar"));
 208  0
             classpath.createPathElement().setLocation(
 209   
                 new File(serverDir, "lib/weblogic.jar"));
 210   
 
 211  0
             java.setClassname("weblogic.Server");
 212  0
             java.execute();
 213   
         }
 214   
         catch (IOException ioe)
 215   
         {
 216  0
             getLog().error("Failed to startup the container", ioe);
 217  0
             throw new BuildException(ioe);
 218   
         }
 219   
     }
 220   
 
 221   
     /**
 222   
      * @see org.apache.cactus.integration.ant.container.Container#shutDown
 223   
      */
 224  0
     public final void shutDown()
 225   
     {
 226  0
         Java java = createJavaForShutDown();
 227   
             
 228  0
         File serverDir = new File(this.dir, "server");
 229   
 
 230  0
         Path classpath = java.createClasspath();
 231  0
         classpath.createPathElement().setLocation(
 232   
             new File(serverDir, "lib/weblogic_sp.jar"));
 233  0
         classpath.createPathElement().setLocation(
 234   
             new File(serverDir, "lib/weblogic.jar"));
 235   
 
 236  0
         java.setClassname("weblogic.Admin");
 237  0
         java.createArg().setValue("-url");
 238  0
         java.createArg().setValue("t3://" + this.getServer() + ":" + getPort());
 239  0
         java.createArg().setValue("-username");
 240  0
         java.createArg().setValue("weblogic");
 241  0
         java.createArg().setValue("-password");
 242  0
         java.createArg().setValue("weblogic");
 243   
         
 244   
         // Forcing WebLogic shutdown to speed up the shutdown process
 245  0
         java.createArg().setValue("FORCESHUTDOWN");
 246   
 
 247  0
         java.execute();
 248   
     }
 249   
 
 250   
     // Private Methods ---------------------------------------------------------
 251   
 
 252   
     /**
 253   
      * Prepares a temporary installation of the container and deploys the 
 254   
      * web-application.
 255   
      * 
 256   
      * @param theDirName The name of the temporary container installation
 257   
      *        directory
 258   
      * @throws IOException If an I/O error occurs
 259   
      */
 260  0
     private void prepare(String theDirName) throws IOException
 261   
     {
 262  0
         FileUtils fileUtils = FileUtils.newFileUtils();
 263  0
         FilterChain filterChain = createFilterChain();
 264   
         
 265  0
         this.tmpDir = setupTempDirectory(this.tmpDir, theDirName);
 266  0
         cleanTempDirectory(this.tmpDir);
 267   
 
 268  0
         File testDomainDir = createDirectory(this.tmpDir, "testdomain");
 269   
 
 270  0
         if (this.configXml != null)
 271   
         {
 272  0
             fileUtils.copyFile(this.configXml,
 273   
                 new File(testDomainDir, "config.xml"));
 274   
         }
 275   
         else
 276   
         {
 277  0
             ResourceUtils.copyResource(getProject(),
 278   
                 RESOURCE_PATH + "weblogic7x/config.xml",
 279   
                 new File(testDomainDir, "config.xml"),
 280   
                 filterChain);
 281   
         }
 282   
         
 283  0
         ResourceUtils.copyResource(getProject(),
 284   
             RESOURCE_PATH + "weblogic7x/DefaultAuthenticatorInit.ldift",
 285   
             new File(testDomainDir, "DefaultAuthenticatorInit.ldift"),
 286   
             filterChain);
 287   
 
 288   
         // TODO: For improvement, do not copy the weblogic.xml file
 289   
         // in the tmpdir.
 290   
         
 291   
         // Extract the weblogic.xml descriptor
 292  0
         File weblogicXml = new File(this.tmpDir, "weblogic.xml");
 293  0
         ResourceUtils.copyResource(getProject(),
 294   
             RESOURCE_PATH + "weblogic7x/weblogic.xml",
 295   
             weblogicXml, filterChain);
 296   
 
 297   
         // deploy the web-app by copying the WAR file into the applications
 298   
         // directory, adding the weblogic.xml descriptor in WEB-INF
 299  0
         File applicationsDir =
 300   
             createDirectory(testDomainDir, "applications");
 301  0
         Jar jar = (Jar) createAntTask("jar");
 302  0
         jar.setDestFile(new File(applicationsDir,
 303   
             getDeployableFile().getFile().getName()));
 304  0
         ZipFileSet zip = new ZipFileSet();
 305  0
         zip.setSrc(getDeployableFile().getFile());
 306  0
         jar.addZipfileset(zip);
 307  0
         ZipFileSet fileSet = new ZipFileSet();
 308  0
         fileSet.setDir(this.tmpDir);
 309  0
         fileSet.createInclude().setName("weblogic.xml");
 310  0
         fileSet.setPrefix("WEB-INF");
 311  0
         jar.addZipfileset(fileSet);
 312  0
         jar.execute();
 313   
     }
 314   
 
 315   
 }
 316