This is an automated email from the ASF dual-hosted git repository.
jamesyong pushed a commit to branch trunk
in repository
https://gitbox.apache.org/repos/asf/ofbiz-framework.gitThe following commit(s) were added to refs/heads/trunk by this push:
new 11e958f Improved: multi-block attribute for html-template tag (OFBIZ-11686)
11e958f is described below
commit 11e958ff8a2f7a9139b606b0283f1a1a6c212786
Author: James Yong <
[hidden email]>
AuthorDate: Sat Aug 15 22:01:19 2020 +0800
Improved: multi-block attribute for html-template tag (OFBIZ-11686)
Return 404 response when getJs has no result.
Also remove script from cache after read by getJs.
---
.../common/src/main/java/org/apache/ofbiz/common/CommonEvents.java | 4 ++++
.../org/apache/ofbiz/widget/model/MultiBlockHtmlTemplateUtil.java | 6 +++---
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/framework/common/src/main/java/org/apache/ofbiz/common/CommonEvents.java b/framework/common/src/main/java/org/apache/ofbiz/common/CommonEvents.java
index 9450567..3ecf80b 100644
--- a/framework/common/src/main/java/org/apache/ofbiz/common/CommonEvents.java
+++ b/framework/common/src/main/java/org/apache/ofbiz/common/CommonEvents.java
@@ -190,6 +190,10 @@ public class CommonEvents {
response.setContentType("application/javascript");
// script.length is not reliable for unicode characters
response.setContentLength(script.getBytes("UTF8").length);
+ // return 404 if script is empty
+ if (UtilValidate.isEmpty(script)) {
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ }
out = response.getWriter();
out.write(script);
diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MultiBlockHtmlTemplateUtil.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MultiBlockHtmlTemplateUtil.java
index 3717c58..abbc57f 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MultiBlockHtmlTemplateUtil.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MultiBlockHtmlTemplateUtil.java
@@ -440,15 +440,15 @@ public final class MultiBlockHtmlTemplateUtil {
}
/**
- * Get the script stored in cache.
+ * Remove script from cache after reading.
* @param session
* @param fileName
* @return script to be sent back to browser
*/
public static String getScriptFromCache(HttpSession session, final String fileName) {
Map<String, String> scriptMap = UtilGenerics.cast(scriptCache.get(session.getId()));
- if (scriptMap != null) {
- return scriptMap.get(fileName);
+ if (scriptMap != null && scriptMap.containsKey(fileName)) {
+ return scriptMap.remove(fileName);
}
return "";
}