diff --git a/applications/content/config/content.properties b/applications/content/config/content.properties index 0bda1143fe..963627d7bb 100644 --- a/applications/content/config/content.properties +++ b/applications/content/config/content.properties @@ -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 + + diff --git a/applications/content/src/main/java/org/apache/ofbiz/content/data/DataEvents.java b/applications/content/src/main/java/org/apache/ofbiz/content/data/DataEvents.java index fe3f1aeca7..68ac6ceca3 100644 --- a/applications/content/src/main/java/org/apache/ofbiz/content/data/DataEvents.java +++ b/applications/content/src/main/java/org/apache/ofbiz/content/data/DataEvents.java @@ -172,7 +172,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"; } diff --git a/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java b/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java index dcf5de5e6d..c9c063cca6 100644 --- a/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java +++ b/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java @@ -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.FileItem; 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; @@ -1104,7 +1105,7 @@ public class DataResourceWorker implements org.apache.ofbiz.widget.content.Data 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"); diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java index 28b80c59e5..be37c14818 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java @@ -56,6 +56,7 @@ import org.apache.http.conn.ssl.TrustSelfSignedStrategy; 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);