details:   https://code.openbravo.com/erp/devel/pi/rev/af64a035d451
changeset: 32257:af64a035d451
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Jun 01 14:55:14 2017 +0200
summary:   fixed bug 36165: useless log for non matching DB messages

  - downgraded level from info to debug
  - don't concatenate log String if it's not logged

details:   https://code.openbravo.com/erp/devel/pi/rev/0d4ef3abdea4
changeset: 32258:0d4ef3abdea4
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Jun 01 16:58:38 2017 +0200
summary:   fixed bug 36141: stateful WS calls create long lived HttpSessions

  - Now expiration time for sessions in WS calls is configurable through
    ws.maxInactiveInterval property, which defaults to 1 minute
  - Removed log while destroying context to just summarize number of sessions
    to deactive from DB + spent time.

diffstat:

 src/org/openbravo/erpCommon/security/SessionListener.java       |   9 +-
 src/org/openbravo/erpCommon/utility/ErrorTextParserPOSTGRE.java |  11 +-
 src/org/openbravo/service/web/BaseWebServiceServlet.java        |  37 
+++++++++-
 3 files changed, 45 insertions(+), 12 deletions(-)

diffs (156 lines):

diff -r e00c7560119e -r 0d4ef3abdea4 
src/org/openbravo/erpCommon/security/SessionListener.java
--- a/src/org/openbravo/erpCommon/security/SessionListener.java Thu Jun 01 
14:28:39 2017 +0200
+++ b/src/org/openbravo/erpCommon/security/SessionListener.java Thu Jun 01 
16:58:38 2017 +0200
@@ -59,7 +59,6 @@
    */
   @Override
   public void sessionDestroyed(HttpSessionEvent event) {
-    log.debug("Destroying session");
     HttpSession session = event.getSession();
     String sessionId = (String) session.getAttribute("#AD_SESSION_ID");
     if (sessionId != null) {
@@ -78,7 +77,8 @@
    */
   @Override
   public void contextDestroyed(ServletContextEvent event) {
-    log.info("Destroy context");
+    log.info("Destroying context. " + sessionsInContext.size() + " sessions to 
deactivate in DB.");
+    long t = System.currentTimeMillis();
 
     for (String sessionId : sessionsInContext) {
       try {
@@ -86,13 +86,12 @@
         SessionLoginData
             .deactivate((ConnectionProvider) event.getServletContext()
                 .getAttribute("openbravoPool"), sessionId);
-        SessionListener.context = null;
-        log.info("Deactivated session: " + sessionId);
       } catch (ServletException e1) {
         log.error(e1.getMessage(), e1);
       }
     }
-
+    SessionListener.context = null;
+    log.info("Sessions deactivated in " + (System.currentTimeMillis() - t) + " 
ms");
   }
 
   /**
diff -r e00c7560119e -r 0d4ef3abdea4 
src/org/openbravo/erpCommon/utility/ErrorTextParserPOSTGRE.java
--- a/src/org/openbravo/erpCommon/utility/ErrorTextParserPOSTGRE.java   Thu Jun 
01 14:28:39 2017 +0200
+++ b/src/org/openbravo/erpCommon/utility/ErrorTextParserPOSTGRE.java   Thu Jun 
01 16:58:38 2017 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -24,7 +24,8 @@
 
 import javax.servlet.ServletException;
 
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 // examples for the types of postgres messages to be parsed by this class
 
@@ -67,7 +68,7 @@
  *         POSTGRESQL RDBMS.
  */
 class ErrorTextParserPOSTGRE extends ErrorTextParser {
-  static Logger log4j = Logger.getLogger(ErrorTextParserPOSTGRE.class);
+  private static final Logger log4j = 
LoggerFactory.getLogger(ErrorTextParserPOSTGRE.class);
 
   /**
    * Extracts the name of a constraint out of a postgresql generated error 
message about a
@@ -80,11 +81,11 @@
    * @return name of the constraint, or null if no name can be found
    */
   private static String findConstraintName(String input) {
-    log4j.debug("find constraint name in : " + input);
+    log4j.debug("find constraint name in : {}", input);
     Pattern p = Pattern.compile("\".+?\"|«.+?»");
     Matcher m = p.matcher(input);
     if (!m.find()) {
-      log4j.info("did not find constraint name for error message: " + input);
+      log4j.debug("did not find constraint name for error message: {}", input);
       return null;
     }
     String constraintName = input.substring(m.start(), m.end());
diff -r e00c7560119e -r 0d4ef3abdea4 
src/org/openbravo/service/web/BaseWebServiceServlet.java
--- a/src/org/openbravo/service/web/BaseWebServiceServlet.java  Thu Jun 01 
14:28:39 2017 +0200
+++ b/src/org/openbravo/service/web/BaseWebServiceServlet.java  Thu Jun 01 
16:58:38 2017 +0200
@@ -26,12 +26,14 @@
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
 
 import org.apache.log4j.Logger;
 import org.openbravo.authentication.AuthenticationException;
 import org.openbravo.authentication.AuthenticationManager;
 import org.openbravo.base.exception.OBSecurityException;
 import org.openbravo.base.provider.OBProvider;
+import org.openbravo.base.session.OBPropertiesProvider;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.core.SessionHandler;
 
@@ -53,6 +55,9 @@
 
   private static final long serialVersionUID = 1L;
 
+  private static Integer wsInactiveInterval = null;
+  private static final int DEFAULT_WS_INACTIVE_INTERVAL = 60;
+
   @Override
   protected final void service(HttpServletRequest request, HttpServletResponse 
response)
       throws ServletException, IOException {
@@ -92,8 +97,20 @@
       log.debug("WS accessed by userId " + userId);
       
OBContext.setOBContext(UserContextCache.getInstance().getCreateOBContext(userId));
       OBContext.setOBContextInSession(request, OBContext.getOBContext());
-
-      doService(request, response);
+      try {
+        doService(request, response);
+      } finally {
+        HttpSession session = request.getSession(false);
+        if (session != null) {
+          // HttpSession for WS should typically expire fast
+          int maxExpireInterval = getWSInactiveInterval();
+          if (maxExpireInterval == 0) {
+            session.invalidate();
+          } else {
+            session.setMaxInactiveInterval(getWSInactiveInterval());
+          }
+        }
+      }
 
     } else {
       log.debug("WS accessed by unauthenticated user, requesting 
authentication");
@@ -105,6 +122,22 @@
     }
   }
 
+  private int getWSInactiveInterval() {
+    if (wsInactiveInterval == null) {
+      try {
+        wsInactiveInterval = 
Integer.parseInt(OBPropertiesProvider.getInstance()
+            .getOpenbravoProperties()
+            .getProperty("ws.maxInactiveInterval", 
Integer.toString(DEFAULT_WS_INACTIVE_INTERVAL)));
+      } catch (Exception e) {
+        wsInactiveInterval = DEFAULT_WS_INACTIVE_INTERVAL;
+      }
+      log.info("Sessions for WS calls expire after " + wsInactiveInterval
+          + " seconds. This can be configured with ws.maxInactiveInterval 
property.");
+    }
+
+    return wsInactiveInterval;
+  }
+
   protected WebService getWebService(HttpServletRequest request) {
     final String segment = 
WebServiceUtil.getInstance().getFirstSegment(request.getPathInfo());
     final Object o = OBProvider.getInstance().get(segment);

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to