This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch release18.12
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/release18.12 by this push:
     new cd84c69bfe Fixed: ControlServlet falls into error with Cookies log 
output when Debug log level is switched to verbose (OFBIZ-13148)
cd84c69bfe is described below

commit cd84c69bfe06471637838dcd3e25ae8e5a29d825
Author: Jacques Le Roux <[email protected]>
AuthorDate: Fri Oct 11 08:55:05 2024 +0200

    Fixed: ControlServlet falls into error with Cookies log output when Debug 
log level is switched to verbose (OFBIZ-13148)
    
    When running OfBiz with debug level logging, the ControlServlet on WebApp 
falls
    into a runtime error as follows when a web page is invoked:
      Servlet.service() for servlet [ControlServlet] in context with path
      [/cdc-resmon] threw exception java.lang.ArrayStoreException:
      javax.servlet.http.Cookie
    
    This is caused by the way Cookies are lined up to be streamed using a 
Cookie[].
    instead, Cookies should be rendered to a Map before being streamed to String
    for logging.
    
    Conflict handled by hand
---
 .../main/java/org/apache/ofbiz/webapp/stats/VisitHandler.java    | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git 
a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/stats/VisitHandler.java
 
b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/stats/VisitHandler.java
index 091d98c1f3..9dcbbb3c1d 100644
--- 
a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/stats/VisitHandler.java
+++ 
b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/stats/VisitHandler.java
@@ -22,6 +22,7 @@ import java.net.InetAddress;
 import java.sql.Timestamp;
 import java.util.Arrays;
 import java.util.Locale;
+import java.util.stream.Collectors;
 
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
@@ -228,9 +229,11 @@ public class VisitHandler {
                             String cookieVisitorId = null;
                             Cookie[] cookies = request.getCookies();
                             if (cookies != null) {
-                            if (Debug.verboseOn()) {
-                                Debug.logVerbose("Cookies:" + String.join(",", 
Arrays.stream(cookies).toArray(String[]::new)), module);
-                            }
+                                if (Debug.verboseOn()) {
+                                    Debug.logVerbose("Cookies:" + 
String.join(",", Arrays.stream(cookies)
+                                            .map(cookie -> cookie.getName() + 
"=" + cookie.getValue())
+                                            .collect(Collectors.joining(", 
"))), module);
+                                }
                                 for (int i = 0; i < cookies.length; i++) {
                                     if 
(cookies[i].getName().equals(visitorCookieName)) {
                                         cookieVisitorId = 
cookies[i].getValue();

Reply via email to