1 23 24 29 30 package com.sun.enterprise.deployment.backend; 31 32 import java.io.File ; 33 import java.io.IOException ; 34 import java.rmi.RemoteException ; 35 import java.security.AccessController ; 36 import java.security.PrivilegedAction ; 37 import java.util.logging.*; 38 import java.util.*; 39 import javax.enterprise.deploy.shared.ModuleType ; 40 import com.sun.enterprise.config.ConfigException; 41 import com.sun.enterprise.config.serverbeans.ServerTags; 42 import com.sun.enterprise.instance.ApplicationEnvironment; 43 import com.sun.enterprise.instance.AppsManager; 44 import com.sun.enterprise.instance.BaseManager; 45 import com.sun.enterprise.instance.InstanceEnvironment; 46 import com.sun.ejb.codegen.IASEJBCTimes; 47 import com.sun.enterprise.util.io.FileSource; 48 import com.sun.enterprise.util.io.FileUtils; 49 import com.sun.enterprise.util.zip.ZipItem; 50 import com.sun.enterprise.util.zip.ZipFileException; 51 import com.sun.enterprise.util.i18n.StringManager; 52 import com.sun.enterprise.util.diagnostics.Reminder; 53 54 import com.sun.enterprise.deployment.Application; 55 import com.sun.enterprise.deployment.BundleDescriptor; 56 import com.sun.enterprise.deployment.EjbBundleDescriptor; 57 import com.sun.enterprise.deployment.EjbDescriptor; 58 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 59 import com.sun.enterprise.deployment.deploy.shared.FileArchiveFactory; 60 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 61 import com.sun.enterprise.deployment.Descriptor; 62 import com.sun.enterprise.deployment.util.ModuleDescriptor; 63 import com.sun.enterprise.deployment.WebBundleDescriptor; 64 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 65 import com.sun.enterprise.deployment.archivist.ApplicationArchivist; 66 67 import com.sun.enterprise.deployment.interfaces.*; 69 import com.sun.enterprise.tools.verifier.AppVerifier; 70 71 import com.sun.enterprise.security.application.EJBSecurityManager; 72 import com.sun.enterprise.security.factory.EJBSecurityManagerFactory; 73 import com.sun.web.security.WebSecurityManagerFactory; 74 75 83 public class AppDeployer extends AppDeployerBase 84 { 85 AppDeployer(DeploymentRequest r) throws IASDeploymentException 86 { 87 super(r); 88 } 89 90 92 public void doRequest() throws IASDeploymentException 93 { 94 doRequestPrepare(); 95 doRequestFinish(); 96 } 97 98 99 101 public void doRequestPrepare() throws IASDeploymentException 102 { 103 try 104 { 105 begin(); 106 } 107 catch(Exception e) 108 { 109 rollback(); 110 String msg = localStrings.getString( 111 "enterprise.deployment.backend.dorequest_exception" ); 112 logger.log(Level.WARNING, msg, e); 113 if (e instanceof IASDeploymentException) { 114 throw (IASDeploymentException) e; 115 } else { 116 throw new IASDeploymentException( msg, e); 117 } 118 } 119 } 120 121 122 124 public void doRequestFinish() throws IASDeploymentException 125 { 126 try 127 { 128 predeploy(); 129 deploy(); 130 generatePolicy(); 131 } 132 catch(Exception e) 133 { 134 String msg = localStrings.getString( 135 "enterprise.deployment.backend.dorequest_exception" ); 136 rollback(); 137 logger.log(Level.FINE, msg, e); 138 if (e instanceof IASDeploymentException) { 139 throw (IASDeploymentException) e; 140 } else { 141 throw new IASDeploymentException( msg, e); 142 } 143 } 144 finally 145 { 146 finish(); 147 } 148 } 149 150 152 public void cleanup_internal() 153 { 154 } 156 157 159 protected void predeploy() throws IASDeploymentException 160 { 161 super.predeploy(); 162 166 if(request.isDeploy()) 167 liquidateAppDirAndStubsDirIfTheyHappenToExist(); 168 } 169 170 172 protected void deploy() throws IASDeploymentException 173 { 174 try 175 { 176 DeploymentStatus J2EECPhaseStatus = 178 request.getCurrentDeploymentStatus(); 179 180 Application app; 181 if(isArchive()) { 182 app = explodeArchive(); 183 } else { getXMLDir().mkdirs(); 186 getJWSDir().mkdirs(); 187 188 ApplicationArchivist appArchivist = new ApplicationArchivist(); 190 String dir = request.getDeployedDirectory().getAbsolutePath(); 191 FileArchive appArchive = new FileArchive(); 192 appArchive.open(dir); 193 if (!appArchivist.hasStandardDeploymentDescriptor(appArchive)) { 194 Application appDesc = 195 Application.createApplication(appArchive,true,true); 196 request.setDescriptor(appDesc); 197 } 198 199 app = loadDescriptors(); 201 } 202 request.setDescriptor(app); 203 204 request.getDescriptor().setGeneratedXMLDirectory(getXMLDir().getAbsolutePath()); 206 207 DeploymentStatus runEJBCStatus = 210 new DeploymentStatus(J2EECPhaseStatus); 211 request.setCurrentDeploymentStatus(runEJBCStatus); 212 runJSPC(); 213 runVerifier(); 214 ZipItem[] clientStubs = runEJBC(); 215 216 checkAppclientsMainClasses(); 217 218 createClientJar(clientStubs); 219 220 DeploymentStatus postDeployStatus = 223 new DeploymentStatus(J2EECPhaseStatus); 224 request.setCurrentDeploymentStatus(postDeployStatus); 225 postDeploy(); 226 227 addToSummary(getSuccessMessage() + getAppName() + "\n*********************\n"); 228 } 229 catch(IASDeploymentException e) 230 { 231 throw e; 232 } 233 catch(Exception e) 234 { 235 throw new IASDeploymentException(e); 236 } 237 } 238 239 241 protected void rollback() 242 { 243 247 try 249 { 250 DeleteOrKeepFailedStubs(getStubsDir()); 253 254 if(FileUtils.safeIsDirectory(getJSPDir())) 255 FileUtils.whack(getJSPDir()); 256 257 if (FileUtils.safeIsDirectory(getXMLDir())) { 258 FileUtils.whack(getXMLDir()); 259 } 260 261 if (FileUtils.safeIsDirectory(getJWSDir())) { 262 FileUtils.whack(getJWSDir()); 263 } 264 265 if(isArchive()) 266 { 267 if(FileUtils.safeIsDirectory(getAppDir())) 268 FileUtils.whack(getAppDir()); 269 } 270 271 } 272 catch(Throwable t) 273 { 274 logger.log( Level.WARNING, 276 "enterprise.deployment_rollback_error", t ); 277 } 278 } 279 280 282 private void liquidateAppDirAndStubsDirIfTheyHappenToExist() throws IASDeploymentException 283 { 284 if (isArchive()) { 285 cleanAndCheck(getAppDir()); 286 } 287 cleanAndCheck(getStubsDir()); 288 cleanAndCheck(getJSPDir()); 289 cleanAndCheck(getXMLDir()); 290 cleanAndCheck(getJWSDir()); 291 } 292 293 300 private void cleanAndCheck(File dir) throws IASDeploymentException { 301 if(FileUtils.safeIsDirectory(dir)) { 302 FileUtils.whack(dir); 303 310 if(FileUtils.safeIsDirectory(dir)) 311 { 312 String msg = localStrings.getString("enterprise.deployment.backend.cannot_delete_dir", dir); 313 throw new IASDeploymentException(msg); 314 } 315 } 316 } 317 319 private Application explodeArchive() throws Exception 320 { 321 322 Application appDesc = J2EEModuleExploder.explodeEar(request.getFileSource().getFile(), getAppDir()); 324 appDesc.setRegistrationName(request.getName()); 325 326 request.setDescriptor(appDesc); 327 getXMLDir().mkdirs(); 328 getJWSDir().mkdirs(); 329 getStubsDir().mkdirs(); 330 331 loadDescriptors(); 333 334 return appDesc; 335 } 336 337 339 private ZipItem[] runEJBC() throws IASDeploymentException 340 { 341 ZipItem[] clientStubs = null; 342 343 try { 344 IASEJBCTimes timing = new IASEJBCTimes(); 346 EJBCompiler compiler = new EJBCompiler 347 ( 348 getAppName(), 349 getAppDir(), 350 getOldAppDir(), 351 getStubsDir(), 352 getOldStubsDir(), 353 getManager(), 354 request, 355 timing 356 ); 357 358 clientStubs = compiler.compile(); 360 361 366 368 addEJBCTime(timing); 370 371 } 372 catch(IASDeploymentException e) { 373 throw e; 374 } 375 catch (Exception e) { 376 logger.log( Level.WARNING, 377 "enterprise.deployment_ejbc_error", e ); 378 String msg = localStrings.getString( 379 "enterprise.deployment.backend.ejbc_error" ); 380 throw new IASDeploymentException(msg, e); 381 } 382 383 return clientStubs; 385 } 386 387 389 private void runJSPC() throws IASDeploymentException 390 { 391 if(!request.getPrecompileJSP()) 392 return; 393 394 Application app = request.getDescriptor(); 395 Set webBundleDescriptors = app.getWebBundleDescriptors(); 396 if (webBundleDescriptors == null) { 397 return; 398 } 399 400 Iterator itr = webBundleDescriptors.iterator(); 401 while (itr.hasNext()) 402 { 403 WebBundleDescriptor wbd = (WebBundleDescriptor) itr.next(); 404 String warDirName = FileUtils.makeFriendlyFilename( 405 wbd.getModuleDescriptor().getArchiveUri()); 406 File outDir = new File (getJSPDir(), warDirName); 407 File inDir = new File (getAppDir(), warDirName); 408 long time = System.currentTimeMillis(); 411 JSPCompiler.compile(inDir, outDir, wbd, 412 request.getCompleteClasspath()); 413 addJSPCTime(System.currentTimeMillis() - time); 414 } 415 } 416 417 419 protected void postDeploy() throws ConfigException, IASDeploymentException 420 { 421 Application applicationDD = request.getDescriptor(); 422 getManager().registerDescriptor(applicationDD.getRegistrationName(), 423 applicationDD); 424 DeploymentEventInfo info = new DeploymentEventInfo( 425 getAppDir(), getStubsDir(), getOldStubsDir(), 426 applicationDD, getRequest()); 427 DeploymentEvent ev = new DeploymentEvent( 428 DeploymentEventType.POST_DEPLOY, info); 429 DeploymentEventManager.notifyDeploymentEvent(ev); 430 431 WebSecurityManagerFactory wsmfactory = 433 WebSecurityManagerFactory.getInstance(); 434 for (Iterator iter = applicationDD.getWebBundleDescriptors().iterator(); iter.hasNext();) 435 { 436 wsmfactory.newWebSecurityManager((WebBundleDescriptor)iter.next()); 437 } 438 EJBSecurityManagerFactory ejbmfactory = 440 (EJBSecurityManagerFactory)EJBSecurityManagerFactory.getInstance(); 441 for (Object ejbBundleDescObj : applicationDD.getEjbBundleDescriptors()) { 442 for (Object ejbDescObj : ((EjbBundleDescriptor)ejbBundleDescObj).getEjbs()) { 443 ejbmfactory.createSecurityManager((EjbDescriptor)ejbDescObj); 444 } 445 } 446 447 if(!isDirectory()) { 448 postDeployArchive(); 449 } 450 451 getManager().registerDescriptor(request.getName(), request.getDescriptor()); 452 453 Properties optionalAttributes = request.getOptionalAttributes(); 455 if (optionalAttributes == null) { 456 optionalAttributes = new Properties(); 457 } 458 String resourceType = getResourceType(getAppDir()); 459 if(resourceType != null) { 460 optionalAttributes.setProperty(ServerTags.OBJECT_TYPE, 461 resourceType); 462 } 463 } 464 465 467 private void postDeployArchive() throws ConfigException, IASDeploymentException 468 { 469 } 470 471 473 protected File setAppDir() throws IASDeploymentException { 474 ApplicationEnvironment aenv = getAppEnv(); 476 File appDirectory; 477 478 if(isArchive()) { 479 File parent = new File (getInstanceEnv().getApplicationRepositoryPath()); 480 appDirectory = new File (parent, getAppName()); 481 appDirectory.mkdirs(); 482 } 483 else if(isDirectory()) { 484 FileSource fileSource = request.getFileSource(); 485 486 if(!fileSource.exists()) { 487 String msg = localStrings.getString( 488 "enterprise.deployment.backend.file_source_does_not_exist", 489 fileSource.toString() ); 490 throw new IASDeploymentException( msg ); 491 } 492 493 assert fileSource.isDirectory(); 494 appDirectory = fileSource.getFile(); 495 } 496 else { 497 String msg = localStrings.getString( 498 "enterprise.deployment.backend.deployment_not_dir_or_archive"); 499 throw new IASDeploymentException( msg ); 500 } 501 502 return appDirectory; 503 } 504 505 507 protected File getOldStubsDir() 508 { 509 return null; 510 } 511 512 514 protected File getOldAppDir() 515 { 516 return null; 517 } 518 519 521 protected String whatAreYou() 522 { 523 return "Deployment"; 524 } 525 526 528 protected final String getSuccessMessage() 529 { 530 return stars + "**** " + whatAreYou() + " successful for " + getAppName() + " ****" + stars; 531 } 532 533 535 protected final String getFailureMessage() 536 { 537 return stars + "**** " + whatAreYou() + " failed for " + getAppName() + " ****" + stars; 538 } 539 540 548 private void runVerifier() throws IASDeploymentException 549 { 550 if (request.isVerifying()) { 551 try { 552 String archive = request.getDeployedDirectory().getCanonicalPath(); 553 File jspDir = (request.getPrecompileJSP())? getJSPDir():null; 554 new AppVerifier().verify(request.getDescriptor(), 555 (new FileArchiveFactory()).openArchive(archive), 556 request.getCompleteClasspath(), 557 jspDir); 558 } catch (Exception e) { 559 String msg = localStrings.getString( 560 "enterprise.deployment.backend.verifier_error"); 561 throw new IASDeploymentException(msg); 562 } 563 } 564 } 565 private final static String stars = "\n*********************\n"; 566 private static StringManager localStrings = 567 StringManager.getManager( AppDeployer.class ); 568 569 } 570 | Popular Tags |