Fixed FELIX-3408 Web Console date chooser shows garbage text
https://issues.apache.org/jira/browse/FELIX-3408

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1306227 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
index c465e8e..e8275f1 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
@@ -421,6 +421,23 @@
         // (we are authorative for our URL space and no other servlet should interfere)
         res.flushBuffer();
     }
+    
+    private void ensureLocaleCookieSet(HttpServletRequest request, HttpServletResponse response, Locale locale) {
+        Cookie[] cookies = request.getCookies();
+        boolean hasCookie = false;
+        for(int i=0; cookies != null && i<cookies.length;i++) {
+            if (COOKIE_LOCALE.equals(cookies[i].getName()) ) {
+                hasCookie = true;
+                break;
+            }
+        }
+        if (!hasCookie) {
+            Cookie cookie = new Cookie(COOKIE_LOCALE, locale.toString());
+            cookie.setPath((String)request.getAttribute(WebConsoleConstants.ATTR_APP_ROOT));
+            cookie.setMaxAge(20 * 365 * 24 * 60 * 60); // 20 years
+            response.addCookie(cookie);
+        }
+    }
 
     private void service(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException
@@ -466,6 +483,9 @@
             request.setAttribute(ATTR_APP_ROOT_OLD,
                 request.getContextPath() + request.getServletPath());
 
+            // fix for https://issues.apache.org/jira/browse/FELIX-3408
+            ensureLocaleCookieSet(request, response, locale);
+
             // wrap the response for localization and template variable replacement
             request = wrapRequest(request, locale);
             response = wrapResponse(request, response, plugin);