Author: ips
Date: 2011-07-29 13:09:55 -0400 (Fri, 29 Jul 2011)
New Revision: 1025
Modified:
trunk/core/src/main/java/org/jboss/on/embedded/ui/content/AbstractFileUploadAction.java
trunk/core/src/main/webapp/WEB-INF/components.xml
Log:
[EMBJOPR-259] fix so uploaded EAR and WAR files are not stored in byte arrays to prevent
potentially consuming a lot of the app server's heap
(
https://issues.jboss.org/browse/EMBJOPR-359)
Modified:
trunk/core/src/main/java/org/jboss/on/embedded/ui/content/AbstractFileUploadAction.java
===================================================================
---
trunk/core/src/main/java/org/jboss/on/embedded/ui/content/AbstractFileUploadAction.java 2011-07-28
21:24:15 UTC (rev 1024)
+++
trunk/core/src/main/java/org/jboss/on/embedded/ui/content/AbstractFileUploadAction.java 2011-07-29
17:09:55 UTC (rev 1025)
@@ -1,6 +1,6 @@
/*
* Embedded Jopr Project
- * Copyright (C) 2006-2009 Red Hat, Inc.
+ * Copyright (C) 2006-2011 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -21,6 +21,7 @@
import java.io.File;
import java.io.FileOutputStream;
+import java.io.InputStream;
import java.io.IOException;
import javax.faces.application.FacesMessage;
@@ -31,6 +32,8 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.faces.FacesMessages;
+import org.rhq.core.util.stream.StreamUtil;
+
import org.jboss.on.embedded.ui.BootstrapAction;
import org.jboss.on.embedded.ui.NavigationAction;
@@ -47,7 +50,7 @@
private final Log log = LogFactory.getLog(this.getClass());
private String fileName;
- private byte[] file;
+ private InputStream file;
private String fileContentType;
/**
@@ -72,14 +75,13 @@
{
uploadsDir.mkdirs();
- String baseName = new File(this.fileName).getName();
+ String baseName = new File(this.fileName).getName();
tempFile = new File(uploadsDir, baseName);
log.debug("Writing uploaded file to '" + tempFile +
"'...");
FileOutputStream fos = new FileOutputStream(tempFile);
- fos.write(this.file);
- log.debug("Wrote " + this.file.length + " bytes to '"
+ tempFile + "'.");
- fos.close();
+ StreamUtil.copy(this.file, fos, true);
+ log.debug("Wrote " + tempFile.length() + " bytes to
'" + tempFile + "'.");
}
catch (IOException e)
{
@@ -101,12 +103,12 @@
this.fileName = fileName;
}
- public byte[] getFile()
+ public InputStream getFile()
{
return file;
}
- public void setFile(byte[] file)
+ public void setFile(InputStream file)
{
this.file = file;
}
@@ -121,3 +123,4 @@
this.fileContentType = fileContentType;
}
}
+
Modified: trunk/core/src/main/webapp/WEB-INF/components.xml
===================================================================
--- trunk/core/src/main/webapp/WEB-INF/components.xml 2011-07-28 21:24:15 UTC (rev 1024)
+++ trunk/core/src/main/webapp/WEB-INF/components.xml 2011-07-29 17:09:55 UTC (rev 1025)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Embedded Jopr Project
- ~ Copyright (C) 2006-2009 Red Hat, Inc.
+ ~ Copyright (C) 2006-2011 Red Hat, Inc.
~ All rights reserved.
~
~ This program is free software; you can redistribute it and/or modify
@@ -21,8 +21,9 @@
<components
xmlns="http://jboss.com/products/seam/components"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://jboss.com/products/seam/security"
+
xmlns:web="http://jboss.com/products/seam/web"
xsi:schemaLocation=
- "http://jboss.com/products/seam/components
http://jboss.com/products/seam/components-2.0.xsd
+ "http://jboss.com/products/seam/components
http://jboss.com/products/seam/components-2.0.xsd
http://jboss.com/products/seam/security
http://jboss.com/products/seam/security-2.0.xsd">
<component name="org.jboss.seam.core.init">
@@ -39,6 +40,10 @@
<property name="scanPeriod">60000</property>
</component>
+ <!-- write uploaded WAR or EAR files out to temp files rather than storing
+ them in memory, to avoid consuming a lot of the app server's heap -->
+ <web:multipart-filter create-temp-files="true"/>
+
<!-- security stuff -->
<security:identity authenticate-method="#{authenticator.authenticate}"
jaas-config-name="jmx-console"/>
@@ -53,3 +58,4 @@
</event>
</components>
+