svn commit: r1821037 - in /ofbiz/ofbiz-framework/branches/release17.12: ./ applications/content/config/ applications/content/src/main/java/org/apache/ofbiz/content/data/ framework/base/src/main/java/org/apache/ofbiz/base/util/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1821037 - in /ofbiz/ofbiz-framework/branches/release17.12: ./ applications/content/config/ applications/content/src/main/java/org/apache/ofbiz/content/data/ framework/base/src/main/java/org/apache/ofbiz/base/util/

jleroux@apache.org
Author: jleroux
Date: Fri Jan 12 22:00:22 2018
New Revision: 1821037

URL: http://svn.apache.org/viewvc?rev=1821037&view=rev
Log:
"Applied fix from trunk for revision: 1821036  "
------------------------------------------------------------------------
r1821036 | jleroux | 2018-01-12 22:59:22 +0100 (ven., 12 janv. 2018) | 11 lines

Fixed: streaming large content cause out of memory exception.
(OFBIZ-10133)

When ofbiz streams a large content (eg. video file), get out of memory exception.

To reproduce the issue see the Jira

jleroux: I just removed final for bufferSize, I see no needs for that local
variable

Thanks: Wai for the patch Michael for the discussion
------------------------------------------------------------------------


Modified:
    ofbiz/ofbiz-framework/branches/release17.12/   (props changed)
    ofbiz/ofbiz-framework/branches/release17.12/applications/content/config/content.properties
    ofbiz/ofbiz-framework/branches/release17.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataEvents.java
    ofbiz/ofbiz-framework/branches/release17.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java
    ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java

Propchange: ofbiz/ofbiz-framework/branches/release17.12/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jan 12 22:00:22 2018
@@ -10,4 +10,4 @@
 /ofbiz/branches/json-integration-refactoring:1634077-1635900
 /ofbiz/branches/multitenant20100310:921280-927264
 /ofbiz/branches/release13.07:1547657
-/ofbiz/ofbiz-framework/trunk:1819499,1819598,1819800,1819805,1819811,1820038,1820262,1820374-1820375,1820441,1820457,1820644,1820658,1820790,1820823,1820949,1820966,1821012
+/ofbiz/ofbiz-framework/trunk:1819499,1819598,1819800,1819805,1819811,1820038,1820262,1820374-1820375,1820441,1820457,1820644,1820658,1820790,1820823,1820949,1820966,1821012,1821036

Modified: ofbiz/ofbiz-framework/branches/release17.12/applications/content/config/content.properties
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/applications/content/config/content.properties?rev=1821037&r1=1821036&r2=1821037&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/applications/content/config/content.properties (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/applications/content/config/content.properties Fri Jan 12 22:00:22 2018
@@ -21,6 +21,7 @@ img.request=/content/control/img/
 img.request.param.name=imgId
 
 stream.permission.service=genericContentPermission
+stream.buffersize=8192
 
 baseUrl=https://localhost:8443
 disable.ftl.template.cache=true
@@ -37,4 +38,6 @@ content.upload.always.local.file=true
 content.output.path=runtime/output
 
 # default mime type used in *ContentWrapper classes
-defaultMimeType=text/html; charset=utf-8
\ No newline at end of file
+defaultMimeType=text/html; charset=utf-8
+
+

Modified: ofbiz/ofbiz-framework/branches/release17.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataEvents.java?rev=1821037&r1=1821036&r2=1821037&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataEvents.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataEvents.java Fri Jan 12 22:00:22 2018
@@ -169,7 +169,7 @@ public class DataEvents {
         String mimeType = DataResourceWorker.getMimeType(dataResource);
 
         // hack for IE and mime types
-        if (userAgent.indexOf("MSIE") > -1) {
+        if (UtilValidate.isNotEmpty(userAgent) && userAgent.indexOf("MSIE") > -1) {
             Debug.logInfo("Found MSIE changing mime type from - " + mimeType, module);
             mimeType = "application/octet-stream";
         }

Modified: ofbiz/ofbiz-framework/branches/release17.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java?rev=1821037&r1=1821036&r2=1821037&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java Fri Jan 12 22:00:22 2018
@@ -30,6 +30,8 @@ import java.io.Writer;
 import java.net.URL;
 import java.net.URLConnection;
 import java.nio.ByteBuffer;
+import java.nio.file.Files;
+import java.nio.file.StandardOpenOption;
 import java.sql.Timestamp;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -49,7 +51,6 @@ import org.apache.commons.fileupload.Fil
 import org.apache.commons.fileupload.FileUploadException;
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 import org.apache.commons.fileupload.servlet.ServletFileUpload;
-import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.ofbiz.base.location.FlexibleLocation;
 import org.apache.ofbiz.base.util.Debug;
@@ -1100,7 +1101,7 @@ public class DataResourceWorker  impleme
             String objectInfo = dataResource.getString("objectInfo");
             if (UtilValidate.isNotEmpty(objectInfo)) {
                 File file = DataResourceWorker.getContentFile(dataResourceTypeId, objectInfo, contextRoot);
-                return UtilMisc.toMap("stream", new ByteArrayInputStream(FileUtils.readFileToByteArray(file)), "length", Long.valueOf(file.length()));
+                return UtilMisc.toMap("stream", Files.newInputStream(file.toPath(), StandardOpenOption.READ), "length", Long.valueOf(file.length()));
             }
             throw new GeneralException("No objectInfo found for FILE type [" + dataResourceTypeId + "]; cannot stream");
 

Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java?rev=1821037&r1=1821036&r2=1821037&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java Fri Jan 12 22:00:22 2018
@@ -56,6 +56,7 @@ import org.apache.http.conn.ssl.TrustSel
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.ssl.SSLContexts;
+import org.apache.ofbiz.entity.util.EntityUtilProperties;
 import org.apache.ofbiz.widget.renderer.VisualTheme;
 import org.apache.oro.text.regex.MalformedPatternException;
 import org.apache.oro.text.regex.Pattern;
@@ -1086,8 +1087,6 @@ public final class UtilHttp {
      * @throws IOException
      */
     public static void streamContent(OutputStream out, InputStream in, int length) throws IOException {
-        int bufferSize = 512; // same as the default buffer size; change as needed
-
         // make sure we have something to write to
         if (out == null) {
             throw new IOException("Attempt to write to null output stream");
@@ -1104,8 +1103,8 @@ public final class UtilHttp {
         }
 
         // initialize the buffered streams
-
-        byte[] buffer = new byte[length];
+        int bufferSize = EntityUtilProperties.getPropertyAsInteger("content", "stream.buffersize", 8192);
+        byte[] buffer = new byte[bufferSize];
         int read = 0;
         try (
                 BufferedOutputStream bos = new BufferedOutputStream(out, bufferSize);