1 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 42 public class WebLogic7xContainer extends AbstractJavaContainer 43 { 44 45 47 50 private File beaHome; 51 52 56 private File dir; 57 58 61 private int port = 8080; 62 63 68 private File configXml; 69 70 73 private File tmpDir; 74 75 77 82 public final void setBeaHome(File theBeaHome) 83 { 84 this.beaHome = theBeaHome; 85 } 86 87 92 public final void setDir(File theDir) 93 { 94 this.dir = theDir; 95 } 96 97 102 public final void setPort(int thePort) 103 { 104 this.port = thePort; 105 } 106 107 113 public final void setConfigXml(File theConfigXml) 114 { 115 this.configXml = theConfigXml; 116 } 117 118 123 public final void setTmpDir(File theTmpDir) 124 { 125 this.tmpDir = theTmpDir; 126 } 127 128 130 133 public final String getName() 134 { 135 return "WebLogic 7.x"; 136 } 137 138 143 public final int getPort() 144 { 145 return this.port; 146 } 147 148 151 public final void init() 152 { 153 if (!this.dir.isDirectory()) 154 { 155 throw new BuildException(this.dir + " is not a directory"); 156 } 157 158 if (this.beaHome == null) 161 { 162 getLog().debug("Extrapolating beaHome to be [" 163 + this.dir.getParentFile() + "]"); 164 this.beaHome = this.dir.getParentFile(); 165 } 166 } 167 168 171 public final void startUp() 172 { 173 try 174 { 175 prepare("cactus/weblogic7x"); 176 177 Java java = createJavaForStartUp(); 178 java.setDir(new File (this.tmpDir, "testdomain")); 179 180 java.createJvmarg().setValue("-hotspot"); 181 java.createJvmarg().setValue("-Xms32m"); 182 java.createJvmarg().setValue("-Xmx200m"); 183 184 File serverDir = new File (this.dir, "server"); 185 186 java.addSysproperty( 187 createSysProperty("weblogic.Name", "testserver")); 188 java.addSysproperty( 189 createSysProperty("bea.home", this.beaHome)); 190 java.addSysproperty( 191 createSysProperty("weblogic.management.username", "weblogic")); 192 java.addSysproperty( 193 createSysProperty("weblogic.management.password", "weblogic")); 194 195 java.addSysproperty( 202 createSysProperty("java.security.policy", 203 "=./server/lib/weblogic.policy")); 204 205 Path classpath = java.createClasspath(); 206 classpath.createPathElement().setLocation( 207 new File (serverDir, "lib/weblogic_sp.jar")); 208 classpath.createPathElement().setLocation( 209 new File (serverDir, "lib/weblogic.jar")); 210 211 java.setClassname("weblogic.Server"); 212 java.execute(); 213 } 214 catch (IOException ioe) 215 { 216 getLog().error("Failed to startup the container", ioe); 217 throw new BuildException(ioe); 218 } 219 } 220 221 224 public final void shutDown() 225 { 226 Java java = createJavaForShutDown(); 227 228 File serverDir = new File (this.dir, "server"); 229 230 Path classpath = java.createClasspath(); 231 classpath.createPathElement().setLocation( 232 new File (serverDir, "lib/weblogic_sp.jar")); 233 classpath.createPathElement().setLocation( 234 new File (serverDir, "lib/weblogic.jar")); 235 236 java.setClassname("weblogic.Admin"); 237 java.createArg().setValue("-url"); 238 java.createArg().setValue("t3://localhost:" + getPort()); 239 java.createArg().setValue("-username"); 240 java.createArg().setValue("weblogic"); 241 java.createArg().setValue("-password"); 242 java.createArg().setValue("weblogic"); 243 244 java.createArg().setValue("FORCESHUTDOWN"); 246 247 java.execute(); 248 } 249 250 252 260 private void prepare(String theDirName) throws IOException 261 { 262 FileUtils fileUtils = FileUtils.newFileUtils(); 263 FilterChain filterChain = createFilterChain(); 264 265 this.tmpDir = setupTempDirectory(this.tmpDir, theDirName); 266 cleanTempDirectory(this.tmpDir); 267 268 File testDomainDir = createDirectory(this.tmpDir, "testdomain"); 269 270 if (this.configXml != null) 271 { 272 fileUtils.copyFile(this.configXml, 273 new File (testDomainDir, "config.xml")); 274 } 275 else 276 { 277 ResourceUtils.copyResource(getProject(), 278 RESOURCE_PATH + "weblogic7x/config.xml", 279 new File (testDomainDir, "config.xml"), 280 filterChain); 281 } 282 283 ResourceUtils.copyResource(getProject(), 284 RESOURCE_PATH + "weblogic7x/DefaultAuthenticatorInit.ldift", 285 new File (testDomainDir, "DefaultAuthenticatorInit.ldift"), 286 filterChain); 287 288 291 File weblogicXml = new File (this.tmpDir, "weblogic.xml"); 293 ResourceUtils.copyResource(getProject(), 294 RESOURCE_PATH + "weblogic7x/weblogic.xml", 295 weblogicXml, filterChain); 296 297 File applicationsDir = 300 createDirectory(testDomainDir, "applications"); 301 Jar jar = (Jar) createAntTask("jar"); 302 jar.setDestFile(new File (applicationsDir, 303 getDeployableFile().getFile().getName())); 304 ZipFileSet zip = new ZipFileSet(); 305 zip.setSrc(getDeployableFile().getFile()); 306 jar.addZipfileset(zip); 307 ZipFileSet fileSet = new ZipFileSet(); 308 fileSet.setDir(this.tmpDir); 309 fileSet.createInclude().setName("weblogic.xml"); 310 fileSet.setPrefix("WEB-INF"); 311 jar.addZipfileset(fileSet); 312 jar.execute(); 313 } 314 315 } 316 | Popular Tags |