[Yanel-commits] rev 50820 - in public/yanel/trunk/src: contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/contactform webapp/src/java/org/wyona/yanel/servlet

michi at wyona.com michi at wyona.com
Wed Jun 30 16:00:21 CEST 2010


Author: michi
Date: 2010-06-30 16:00:20 +0200 (Wed, 30 Jun 2010)
New Revision: 50820

Modified:
   public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/contactform/ContactResource.java
   public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet/AccessLog.java
Log:
thanks to Cedric the parameters are now encoded

Modified: public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/contactform/ContactResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/contactform/ContactResource.java	2010-06-30 13:42:20 UTC (rev 50819)
+++ public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/contactform/ContactResource.java	2010-06-30 14:00:20 UTC (rev 50820)
@@ -117,7 +117,9 @@
                     throw new Exception("there is no spamblock implemented in the form.");
                 }
                 if (request.getParameter("spamblock_hidden").equals("TRyAg41n") && request.getParameter("spamblock_input").equals("8989890")) {    
-                    logAccess.info(org.wyona.yanel.servlet.AccessLog.getLogMessage(request, getRealm().getID()) + " e-mail:" + request.getParameter("email"));
+                    logAccess.info(
+                        org.wyona.yanel.servlet.AccessLog.getLogMessage(request, getRealm().getID()) + 
+                        org.wyona.yanel.servlet.AccessLog.encodeLogField("e-mail", request.getParameter("email")));
                     javax.servlet.http.Cookie cookie = org.wyona.yanel.servlet.AccessLog.getYanelAnalyticsCookie(request);
                     String cookieValue = null;
                     if (cookie != null) {

Modified: public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet/AccessLog.java
===================================================================
--- public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet/AccessLog.java	2010-06-30 13:42:20 UTC (rev 50819)
+++ public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet/AccessLog.java	2010-06-30 14:00:20 UTC (rev 50820)
@@ -5,6 +5,8 @@
 import javax.servlet.http.HttpServletResponse;
 
 import java.util.Date;
+import java.net.URLEncoder;
+import java.io.UnsupportedEncodingException;
 
 import org.apache.log4j.Logger;
 
@@ -17,6 +19,8 @@
 
     private static String ANALYTICS_COOKIE_NAME = "_yanel-analytics";
 
+    private static final String LOG_ENCODING = "UTF-8";
+
     /**
      * log4j category
      */
@@ -32,10 +36,36 @@
      * @param userAgent User agent, e.g. Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.0.19) Gecko/2010031218 Firefox/3.0.19
      */
     public static String getLogMessage(String requestURL, String realmID, String cookieValue, String referer, String userAgent) {
-        return requestURL + " r:" + realmID + " c:" + cookieValue + " ref:" + referer + " ua:" + userAgent;
+        String result =
+            encodeLogField("url", requestURL) +
+            encodeLogField("r", realmID) +
+            encodeLogField("c", cookieValue) +
+            encodeLogField("ref", referer) +
+            encodeLogField("ua", userAgent);
+
+        return result;
     }
 
     /**
+     * Correctly encode field for log message
+     *
+     * @param field Name of the field
+     * @param value Value of the field
+     */
+    public static String encodeLogField(String field, String value) {
+        String result;
+        
+        try {
+            result = field + ":" + URLEncoder.encode(value, LOG_ENCODING) + " ";
+        } catch(UnsupportedEncodingException e) {
+            // Fall back to default encoding
+            result = field + ":" + URLEncoder.encode(value) + " ";
+        }
+
+        return result;
+    }
+
+    /**
      * Get log message
      */
     public static String getLogMessage(HttpServletRequest request, HttpServletResponse response, String realmID) {



More information about the Yanel-commits mailing list