modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatVHostComponent.java
| 8 ----
modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatWarComponent.java
| 18 ++--------
modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/helper/FileContentDelegate.java
| 14 +++++--
3 files changed, 15 insertions(+), 25 deletions(-)
New commits:
commit 39a4e87a05763fa1c44540b703f111512c7b2e19
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Thu Dec 8 14:45:00 2011 -0600
[BZ 761593] The war component was not using the content delegate to redeploy
applications. Because of this any redeployments were missing the SHA manifest attribute.
diff --git
a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatVHostComponent.java
b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatVHostComponent.java
index 0f63e1f..aa48a20 100644
---
a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatVHostComponent.java
+++
b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatVHostComponent.java
@@ -23,13 +23,10 @@
package org.jboss.on.plugins.tomcat;
-import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.util.jar.JarEntry;
@@ -54,7 +51,6 @@ import org.rhq.core.pluginapi.content.ContentServices;
import org.rhq.core.pluginapi.inventory.ApplicationServerComponent;
import org.rhq.core.pluginapi.inventory.CreateChildResourceFacet;
import org.rhq.core.pluginapi.inventory.CreateResourceReport;
-import org.rhq.core.util.MessageDigestGenerator;
import org.rhq.core.util.exception.ThrowableUtil;
import org.rhq.plugins.jmx.MBeanResourceComponent;
@@ -308,9 +304,7 @@ public class TomcatVHostComponent extends
MBeanResourceComponent<TomcatServerCom
}
FileContentDelegate fileContent = new FileContentDelegate(deployDir,
details.getPackageTypeName());
- InputStream isForTempDir = new BufferedInputStream(new
FileInputStream(tempFile));
- String sha = new
MessageDigestGenerator(MessageDigestGenerator.SHA_256).getDigestString(tempFile);
- fileContent.createContent(path, isForTempDir, explodeOnDeploy, sha);
+ fileContent.createContent(path, tempFile, explodeOnDeploy);
// Resource key is a canonical objectName similar to:
//
Catalina:j2eeType=WebModule,name=//<vHost>/<path>,J2EEApplication=none,J2EEServer=none
diff --git
a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatWarComponent.java
b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatWarComponent.java
index 9ecc0d7..d865f56 100644
---
a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatWarComponent.java
+++
b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatWarComponent.java
@@ -43,6 +43,7 @@ import org.mc4j.ems.connection.bean.EmsBean;
import org.mc4j.ems.connection.bean.attribute.EmsAttribute;
import org.mc4j.ems.connection.bean.operation.EmsOperation;
+import org.jboss.on.plugins.tomcat.helper.FileContentDelegate;
import org.jboss.on.plugins.tomcat.helper.TomcatApplicationDeployer;
import org.rhq.core.domain.configuration.Configuration;
@@ -507,15 +508,17 @@ public class TomcatWarComponent extends
MBeanResourceComponent<TomcatVHostCompon
log.warn("Failed to create app backup but proceeding with redeploy of
" + appFile.getPath() + ": " + e);
}
+ FileContentDelegate contentDelegate = new
FileContentDelegate(appFile.getParentFile(), packageDetails.getName());
+
try {
// Write the new bits for the application. If successful Tomcat will pick it
up and complete the deploy.
- moveTempFileToDeployLocation(tempFile, appFile, isExploded);
+ contentDelegate.createContent(appFile, tempFile, isExploded);
} catch (Exception e) {
// Deploy failed - rollback to the original app file...
String errorMessage = ThrowableUtil.getAllMessages(e);
try {
FileUtils.purge(appFile, true);
- moveTempFileToDeployLocation(backupFile, appFile, isExploded);
+ contentDelegate.createContent(appFile, backupFile, isExploded);
errorMessage += " ***** ROLLED BACK TO ORIGINAL APPLICATION FILE.
*****";
} catch (Exception e1) {
errorMessage += " ***** FAILED TO ROLLBACK TO ORIGINAL APPLICATION
FILE. *****: "
@@ -536,17 +539,6 @@ public class TomcatWarComponent extends
MBeanResourceComponent<TomcatVHostCompon
return response;
}
- private void moveTempFileToDeployLocation(File tempFile, File appFile, boolean
isExploded) throws IOException {
- InputStream tempIs = null;
- if (isExploded) {
- tempIs = new BufferedInputStream(new FileInputStream(tempFile));
- appFile.mkdir();
- ZipUtil.unzipFile(tempIs, appFile);
- } else {
- tempFile.renameTo(appFile);
- }
- }
-
private File backupAppBitsToTempFile(File appFile) throws Exception {
File tempDir = getResourceContext().getTemporaryDirectory();
File tempFile = new File(tempDir.getAbsolutePath(), appFile.getName() +
System.currentTimeMillis());
diff --git
a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/helper/FileContentDelegate.java
b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/helper/FileContentDelegate.java
index 709c6b7..42dbde7 100644
---
a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/helper/FileContentDelegate.java
+++
b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/helper/FileContentDelegate.java
@@ -37,6 +37,7 @@ import org.rhq.core.domain.content.PackageDetails;
import org.rhq.core.domain.content.PackageDetailsKey;
import org.rhq.core.domain.content.transfer.ResourcePackageDetails;
import org.rhq.core.pluginapi.util.FileUtils;
+import org.rhq.core.util.MessageDigestGenerator;
import org.rhq.core.util.ZipUtil;
import org.rhq.core.util.file.FileUtil;
@@ -80,12 +81,13 @@ public class FileContentDelegate {
* it is written, using the package name as the base directory; if
<code>false</code> the
* content will be written to directly to a file using the package
name as the file name
*/
- public void createContent(File contentFile, InputStream content, boolean unzip,
String sha) {
+ @SuppressWarnings("static-access")
+ public void createContent(File destination, File content, boolean unzip) {
try {
if (unzip) {
- ZipUtil.unzipFile(content, contentFile);
+ ZipUtil.unzipFile(content, destination);
- File manifestFile = new File(contentFile,
"META-INF/MANIFEST.MF");
+ File manifestFile = new File(destination,
"META-INF/MANIFEST.MF");
Manifest manifest;
if (manifestFile.exists()) {
FileInputStream inputStream = new FileInputStream(manifestFile);
@@ -99,6 +101,7 @@ public class FileContentDelegate {
}
Attributes attribs = manifest.getMainAttributes();
+ String sha = new
MessageDigestGenerator(MessageDigestGenerator.SHA_256).getDigestString(content);
attribs.putValue("RHQ-Sha256", sha);
FileOutputStream outputStream = new FileOutputStream(manifestFile);
@@ -108,10 +111,11 @@ public class FileContentDelegate {
outputStream.close();
}
} else {
- FileUtil.writeFile(content, contentFile);
+ InputStream contentStream = new BufferedInputStream(new
FileInputStream(content));
+ FileUtil.writeFile(contentStream, destination);
}
} catch (IOException e) {
- throw new RuntimeException("Error creating artifact for contentFile:
" + contentFile, e);
+ throw new RuntimeException("Error creating artifact for contentFile:
" + destination, e);
}
}