[tomcat] branch 7.0.x updated (5c81607 -> 91cea73)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[tomcat] branch 7.0.x updated (5c81607 -> 91cea73)

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

markt pushed a change to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git.


    from 5c81607  Add placeholder for when annotation API docs are not installed
     new 37cb506  Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64000 i18n / UTF-8
     new 91cea73  Align with 8.5.x and later

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 webapps/docs/changelog.xml                         |  9 +++++
 .../examples/WEB-INF/classes/CookieExample.java    | 39 +++++++++++++---------
 .../WEB-INF/classes/HelloWorldExample.java         |  4 ++-
 .../WEB-INF/classes/RequestHeaderExample.java      | 10 +++---
 .../WEB-INF/classes/RequestInfoExample.java        | 20 ++++++-----
 .../WEB-INF/classes/RequestParamExample.java       | 22 ++++++------
 .../examples/WEB-INF/classes/SessionExample.java   | 27 ++++++++-------
 .../WEB-INF/classes/util/CookieFilter.java         | 18 ++++++----
 .../examples/WEB-INF/classes/util/HTMLFilter.java  |  7 ++--
 .../examples/WEB-INF/jsp2/jsp2-example-taglib.tld  |  2 +-
 10 files changed, 96 insertions(+), 62 deletions(-)


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[tomcat] 01/02: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64000 i18n / UTF-8

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

markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 37cb5069f5d7dbbedf924a4f6ad0b7ffef49e29f
Author: Mark Thomas <[hidden email]>
AuthorDate: Tue Jan 14 19:45:03 2020 +0000

    Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64000 i18n / UTF-8
   
    Ensure that the example web application uses the client locale rather
    than the server locale where it provides i18n support.
    Switch the servlet examples to UTF-8 so the i18n works correctly.
---
 webapps/docs/changelog.xml                         |  9 +++++
 .../examples/WEB-INF/classes/CookieExample.java    | 39 +++++++++++++---------
 .../WEB-INF/classes/HelloWorldExample.java         |  4 ++-
 .../WEB-INF/classes/RequestHeaderExample.java      | 10 +++---
 .../WEB-INF/classes/RequestInfoExample.java        | 20 ++++++-----
 .../WEB-INF/classes/RequestParamExample.java       | 22 ++++++------
 .../examples/WEB-INF/classes/SessionExample.java   | 27 ++++++++-------
 .../WEB-INF/classes/util/CookieFilter.java         | 18 ++++++----
 .../examples/WEB-INF/classes/util/HTMLFilter.java  |  7 ++--
 9 files changed, 95 insertions(+), 61 deletions(-)

diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 86eb1aa..a2e88f1 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -109,6 +109,15 @@
       </fix>
     </changelog>
   </subsection>
+  <subsection name="Web applications">
+    <changelog>
+      <fix>
+        <bug>64000</bug>: In the examples web application, where a Servlet
+        example includes ii18n support, the Locale used should be based on the
+        request locale and not the server locale. (markt)
+      </fix>
+    </changelog>
+  </subsection>
 </section>
 <section name="Tomcat 7.0.99 (violetagg)" rtext="released 2019-12-17">
   <subsection name="Catalina">
diff --git a/webapps/examples/WEB-INF/classes/CookieExample.java b/webapps/examples/WEB-INF/classes/CookieExample.java
index 87956fe..3774e05 100644
--- a/webapps/examples/WEB-INF/classes/CookieExample.java
+++ b/webapps/examples/WEB-INF/classes/CookieExample.java
@@ -24,7 +24,9 @@ import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
 
+import util.CookieFilter;
 import util.HTMLFilter;
 
 /**
@@ -37,13 +39,12 @@ public class CookieExample extends HttpServlet {
 
     private static final long serialVersionUID = 1L;
 
-    private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
-
     @Override
     public void doGet(HttpServletRequest request,
                       HttpServletResponse response)
         throws IOException, ServletException
     {
+        ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",request.getLocale());
 
         String cookieName = request.getParameter("cookiename");
         String cookieValue = request.getParameter("cookievalue");
@@ -55,12 +56,14 @@ public class CookieExample extends HttpServlet {
         }
 
         response.setContentType("text/html");
+        response.setCharacterEncoding("UTF-8");
 
         PrintWriter out = response.getWriter();
-        out.println("<html>");
+        out.println("<!DOCTYPE html><html>");
         out.println("<head>");
+        out.println("<meta charset=\"UTF-8\" />");
 
-        String title = RB.getString("cookies.title");
+        String title = rb.getString("cookies.title");
         out.println("<title>" + title + "</title>");
         out.println("</head>");
         out.println("<body bgcolor=\"white\">");
@@ -82,35 +85,41 @@ public class CookieExample extends HttpServlet {
 
         Cookie[] cookies = request.getCookies();
         if ((cookies != null) && (cookies.length > 0)) {
-            out.println(RB.getString("cookies.cookies") + "<br>");
+            HttpSession session = request.getSession(false);
+            String sessionId = null;
+            if (session != null) {
+                sessionId = session.getId();
+            }
+            out.println(rb.getString("cookies.cookies") + "<br>");
             for (int i = 0; i < cookies.length; i++) {
                 Cookie cookie = cookies[i];
-                out.print("Cookie Name: " + HTMLFilter.filter(cookie.getName())
-                          + "<br>");
+                String cName = cookie.getName();
+                String cValue = cookie.getValue();
+                out.print("Cookie Name: " + HTMLFilter.filter(cName) + "<br>");
                 out.println("  Cookie Value: "
-                            + HTMLFilter.filter(cookie.getValue())
+                            + HTMLFilter.filter(CookieFilter.filter(cName, cValue, sessionId))
                             + "<br><br>");
             }
         } else {
-            out.println(RB.getString("cookies.no-cookies"));
+            out.println(rb.getString("cookies.no-cookies"));
         }
 
         if (aCookie != null) {
             out.println("<P>");
-            out.println(RB.getString("cookies.set") + "<br>");
-            out.print(RB.getString("cookies.name") + "  "
+            out.println(rb.getString("cookies.set") + "<br>");
+            out.print(rb.getString("cookies.name") + "  "
                       + HTMLFilter.filter(cookieName) + "<br>");
-            out.print(RB.getString("cookies.value") + "  "
+            out.print(rb.getString("cookies.value") + "  "
                       + HTMLFilter.filter(cookieValue));
         }
 
         out.println("<P>");
-        out.println(RB.getString("cookies.make-cookie") + "<br>");
+        out.println(rb.getString("cookies.make-cookie") + "<br>");
         out.print("<form action=\"");
         out.println("CookieExample\" method=POST>");
-        out.print(RB.getString("cookies.name") + "  ");
+        out.print(rb.getString("cookies.name") + "  ");
         out.println("<input type=text length=20 name=cookiename><br>");
-        out.print(RB.getString("cookies.value") + "  ");
+        out.print(rb.getString("cookies.value") + "  ");
         out.println("<input type=text length=20 name=cookievalue><br>");
         out.println("<input type=submit></form>");
 
diff --git a/webapps/examples/WEB-INF/classes/HelloWorldExample.java b/webapps/examples/WEB-INF/classes/HelloWorldExample.java
index 49b8601..4a75a4d 100644
--- a/webapps/examples/WEB-INF/classes/HelloWorldExample.java
+++ b/webapps/examples/WEB-INF/classes/HelloWorldExample.java
@@ -41,10 +41,12 @@ public class HelloWorldExample extends HttpServlet {
         ResourceBundle rb =
             ResourceBundle.getBundle("LocalStrings",request.getLocale());
         response.setContentType("text/html");
+        response.setCharacterEncoding("UTF-8");
         PrintWriter out = response.getWriter();
 
-        out.println("<html>");
+        out.println("<!DOCTYPE html><html>");
         out.println("<head>");
+        out.println("<meta charset=\"UTF-8\" />");
 
         String title = rb.getString("helloworld.title");
 
diff --git a/webapps/examples/WEB-INF/classes/RequestHeaderExample.java b/webapps/examples/WEB-INF/classes/RequestHeaderExample.java
index 6ca9071..6d8a442 100644
--- a/webapps/examples/WEB-INF/classes/RequestHeaderExample.java
+++ b/webapps/examples/WEB-INF/classes/RequestHeaderExample.java
@@ -40,20 +40,22 @@ public class RequestHeaderExample extends HttpServlet {
 
     private static final long serialVersionUID = 1L;
 
-    private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
-
     @Override
     public void doGet(HttpServletRequest request,
                       HttpServletResponse response)
         throws IOException, ServletException
     {
+        ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",request.getLocale());
+
         response.setContentType("text/html");
+        response.setCharacterEncoding("UTF-8");
 
         PrintWriter out = response.getWriter();
-        out.println("<html>");
+        out.println("<!DOCTYPE html><html>");
         out.println("<head>");
+        out.println("<meta charset=\"UTF-8\" />");
 
-        String title = RB.getString("requestheader.title");
+        String title = rb.getString("requestheader.title");
         out.println("<title>" + title + "</title>");
         out.println("</head>");
         out.println("<body bgcolor=\"white\">");
diff --git a/webapps/examples/WEB-INF/classes/RequestInfoExample.java b/webapps/examples/WEB-INF/classes/RequestInfoExample.java
index 231393b..791e088 100644
--- a/webapps/examples/WEB-INF/classes/RequestInfoExample.java
+++ b/webapps/examples/WEB-INF/classes/RequestInfoExample.java
@@ -36,20 +36,22 @@ public class RequestInfoExample extends HttpServlet {
 
     private static final long serialVersionUID = 1L;
 
-    private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
-
     @Override
     public void doGet(HttpServletRequest request,
                       HttpServletResponse response)
         throws IOException, ServletException
     {
+        ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",request.getLocale());
+
         response.setContentType("text/html");
+        response.setCharacterEncoding("UTF-8");
 
         PrintWriter out = response.getWriter();
-        out.println("<html>");
+        out.println("<!DOCTYPE html><html>");
         out.println("<head>");
+        out.println("<meta charset=\"UTF-8\" />");
 
-        String title = RB.getString("requestinfo.title");
+        String title = rb.getString("requestinfo.title");
         out.println("<title>" + title + "</title>");
         out.println("</head>");
         out.println("<body bgcolor=\"white\">");
@@ -70,23 +72,23 @@ public class RequestInfoExample extends HttpServlet {
 
         out.println("<h3>" + title + "</h3>");
         out.println("<table border=0><tr><td>");
-        out.println(RB.getString("requestinfo.label.method"));
+        out.println(rb.getString("requestinfo.label.method"));
         out.println("</td><td>");
         out.println(HTMLFilter.filter(request.getMethod()));
         out.println("</td></tr><tr><td>");
-        out.println(RB.getString("requestinfo.label.requesturi"));
+        out.println(rb.getString("requestinfo.label.requesturi"));
         out.println("</td><td>");
         out.println(HTMLFilter.filter(request.getRequestURI()));
         out.println("</td></tr><tr><td>");
-        out.println(RB.getString("requestinfo.label.protocol"));
+        out.println(rb.getString("requestinfo.label.protocol"));
         out.println("</td><td>");
         out.println(HTMLFilter.filter(request.getProtocol()));
         out.println("</td></tr><tr><td>");
-        out.println(RB.getString("requestinfo.label.pathinfo"));
+        out.println(rb.getString("requestinfo.label.pathinfo"));
         out.println("</td><td>");
         out.println(HTMLFilter.filter(request.getPathInfo()));
         out.println("</td></tr><tr><td>");
-        out.println(RB.getString("requestinfo.label.remoteaddr"));
+        out.println(rb.getString("requestinfo.label.remoteaddr"));
         out.println("</td><td>");
         out.println(HTMLFilter.filter(request.getRemoteAddr()));
         out.println("</td></tr>");
diff --git a/webapps/examples/WEB-INF/classes/RequestParamExample.java b/webapps/examples/WEB-INF/classes/RequestParamExample.java
index e1e2733..b5e2dfa 100644
--- a/webapps/examples/WEB-INF/classes/RequestParamExample.java
+++ b/webapps/examples/WEB-INF/classes/RequestParamExample.java
@@ -36,20 +36,22 @@ public class RequestParamExample extends HttpServlet {
 
     private static final long serialVersionUID = 1L;
 
-    private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
-
     @Override
     public void doGet(HttpServletRequest request,
                       HttpServletResponse response)
         throws IOException, ServletException
     {
+        ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",request.getLocale());
+
         response.setContentType("text/html");
+        response.setCharacterEncoding("UTF-8");
 
         PrintWriter out = response.getWriter();
-        out.println("<html>");
+        out.println("<!DOCTYPE html><html>");
         out.println("<head>");
+        out.println("<meta charset=\"UTF-8\" />");
 
-        String title = RB.getString("requestparams.title");
+        String title = rb.getString("requestparams.title");
         out.println("<title>" + title + "</title>");
         out.println("</head>");
         out.println("<body bgcolor=\"white\">");
@@ -72,23 +74,23 @@ public class RequestParamExample extends HttpServlet {
         out.println("<h3>" + title + "</h3>");
         String firstName = request.getParameter("firstname");
         String lastName = request.getParameter("lastname");
-        out.println(RB.getString("requestparams.params-in-req") + "<br>");
+        out.println(rb.getString("requestparams.params-in-req") + "<br>");
         if (firstName != null || lastName != null) {
-            out.println(RB.getString("requestparams.firstname"));
+            out.println(rb.getString("requestparams.firstname"));
             out.println(" = " + HTMLFilter.filter(firstName) + "<br>");
-            out.println(RB.getString("requestparams.lastname"));
+            out.println(rb.getString("requestparams.lastname"));
             out.println(" = " + HTMLFilter.filter(lastName));
         } else {
-            out.println(RB.getString("requestparams.no-params"));
+            out.println(rb.getString("requestparams.no-params"));
         }
         out.println("<P>");
         out.print("<form action=\"");
         out.print("RequestParamExample\" ");
         out.println("method=POST>");
-        out.println(RB.getString("requestparams.firstname"));
+        out.println(rb.getString("requestparams.firstname"));
         out.println("<input type=text size=20 name=firstname>");
         out.println("<br>");
-        out.println(RB.getString("requestparams.lastname"));
+        out.println(rb.getString("requestparams.lastname"));
         out.println("<input type=text size=20 name=lastname>");
         out.println("<br>");
         out.println("<input type=submit>");
diff --git a/webapps/examples/WEB-INF/classes/SessionExample.java b/webapps/examples/WEB-INF/classes/SessionExample.java
index 004e66a..a306560 100644
--- a/webapps/examples/WEB-INF/classes/SessionExample.java
+++ b/webapps/examples/WEB-INF/classes/SessionExample.java
@@ -39,20 +39,23 @@ public class SessionExample extends HttpServlet {
 
     private static final long serialVersionUID = 1L;
 
-    private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
-
     @Override
     public void doGet(HttpServletRequest request,
                       HttpServletResponse response)
         throws IOException, ServletException
     {
+        ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",request.getLocale());
+
         response.setContentType("text/html");
+        response.setCharacterEncoding("UTF-8");
 
         PrintWriter out = response.getWriter();
-        out.println("<html>");
+        out.println("<!DOCTYPE html><html>");
         out.println("<head>");
+        out.println("<meta charset=\"UTF-8\" />");
+
 
-        String title = RB.getString("sessions.title");
+        String title = rb.getString("sessions.title");
         out.println("<title>" + title + "</title>");
         out.println("</head>");
         out.println("<body bgcolor=\"white\">");
@@ -74,11 +77,11 @@ public class SessionExample extends HttpServlet {
         out.println("<h3>" + title + "</h3>");
 
         HttpSession session = request.getSession(true);
-        out.println(RB.getString("sessions.id") + " " + session.getId());
+        out.println(rb.getString("sessions.id") + " " + session.getId());
         out.println("<br>");
-        out.println(RB.getString("sessions.created") + " ");
+        out.println(rb.getString("sessions.created") + " ");
         out.println(new Date(session.getCreationTime()) + "<br>");
-        out.println(RB.getString("sessions.lastaccessed") + " ");
+        out.println(rb.getString("sessions.lastaccessed") + " ");
         out.println(new Date(session.getLastAccessedTime()));
 
         String dataName = request.getParameter("dataname");
@@ -88,7 +91,7 @@ public class SessionExample extends HttpServlet {
         }
 
         out.println("<P>");
-        out.println(RB.getString("sessions.data") + "<br>");
+        out.println(rb.getString("sessions.data") + "<br>");
         Enumeration<String> names = session.getAttributeNames();
         while (names.hasMoreElements()) {
             String name = names.nextElement();
@@ -102,10 +105,10 @@ public class SessionExample extends HttpServlet {
         out.print(response.encodeURL("SessionExample"));
         out.print("\" ");
         out.println("method=POST>");
-        out.println(RB.getString("sessions.dataname"));
+        out.println(rb.getString("sessions.dataname"));
         out.println("<input type=text size=20 name=dataname>");
         out.println("<br>");
-        out.println(RB.getString("sessions.datavalue"));
+        out.println(rb.getString("sessions.datavalue"));
         out.println("<input type=text size=20 name=datavalue>");
         out.println("<br>");
         out.println("<input type=submit>");
@@ -116,10 +119,10 @@ public class SessionExample extends HttpServlet {
         out.print(response.encodeURL("SessionExample"));
         out.print("\" ");
         out.println("method=GET>");
-        out.println(RB.getString("sessions.dataname"));
+        out.println(rb.getString("sessions.dataname"));
         out.println("<input type=text size=20 name=dataname>");
         out.println("<br>");
-        out.println(RB.getString("sessions.datavalue"));
+        out.println(rb.getString("sessions.datavalue"));
         out.println("<input type=text size=20 name=datavalue>");
         out.println("<br>");
         out.println("<input type=submit>");
diff --git a/webapps/examples/WEB-INF/classes/util/CookieFilter.java b/webapps/examples/WEB-INF/classes/util/CookieFilter.java
index 1e156db..19243ee 100644
--- a/webapps/examples/WEB-INF/classes/util/CookieFilter.java
+++ b/webapps/examples/WEB-INF/classes/util/CookieFilter.java
@@ -40,14 +40,14 @@ public class CookieFilter {
         // Hide default constructor
     }
 
-    public static String filter(String input, String sessionId) {
+    public static String filter(String cookieHeader, String sessionId) {
 
-        StringBuilder sb = new StringBuilder(input.length());
+        StringBuilder sb = new StringBuilder(cookieHeader.length());
 
         // Cookie name value pairs are ';' separated.
         // Session IDs don't use ; in the value so don't worry about quoted
         // values that contain ;
-        StringTokenizer st = new StringTokenizer(input, ";");
+        StringTokenizer st = new StringTokenizer(cookieHeader, ";");
 
         boolean first = true;
         while (st.hasMoreTokens()) {
@@ -71,11 +71,15 @@ public class CookieFilter {
         String name = input.substring(0, i);
         String value = input.substring(i + 1, input.length());
 
-        if (name.toLowerCase(Locale.ENGLISH).contains("jsessionid") &&
-                (sessionId == null || !value.contains(sessionId))) {
-            value = OBFUSCATED;
+        return name + "=" + filter(name, value, sessionId);
+    }
+
+    public static String filter(String cookieName, String cookieValue, String sessionId) {
+        if (cookieName.toLowerCase(Locale.ENGLISH).contains("jsessionid") &&
+                (sessionId == null || !cookieValue.contains(sessionId))) {
+            cookieValue = OBFUSCATED;
         }
 
-        return name + "=" + value;
+        return cookieValue;
     }
 }
diff --git a/webapps/examples/WEB-INF/classes/util/HTMLFilter.java b/webapps/examples/WEB-INF/classes/util/HTMLFilter.java
index a0f7dec..29463fb 100644
--- a/webapps/examples/WEB-INF/classes/util/HTMLFilter.java
+++ b/webapps/examples/WEB-INF/classes/util/HTMLFilter.java
@@ -31,11 +31,13 @@ public final class HTMLFilter {
      * codes in the request URL that is often reported in error messages.
      *
      * @param message The message string to be filtered
+     *
+     * @return the filtered version of the message
      */
     public static String filter(String message) {
 
         if (message == null)
-            return (null);
+            return null;
 
         char content[] = new char[message.length()];
         message.getChars(0, message.length(), content, 0);
@@ -58,8 +60,7 @@ public final class HTMLFilter {
                 result.append(content[i]);
             }
         }
-        return (result.toString());
-
+        return result.toString();
     }
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[tomcat] 02/02: Align with 8.5.x and later

markt
In reply to this post by markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 91cea735f12733374f89779799ec551e336f9dcd
Author: Mark Thomas <[hidden email]>
AuthorDate: Tue Jan 14 20:11:17 2020 +0000

    Align with 8.5.x and later
---
 webapps/examples/WEB-INF/jsp2/jsp2-example-taglib.tld | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/webapps/examples/WEB-INF/jsp2/jsp2-example-taglib.tld b/webapps/examples/WEB-INF/jsp2/jsp2-example-taglib.tld
index bb2234a..73173bd 100644
--- a/webapps/examples/WEB-INF/jsp2/jsp2-example-taglib.tld
+++ b/webapps/examples/WEB-INF/jsp2/jsp2-example-taglib.tld
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8" ?>
+<?xml version="1.0" encoding="UTF-8"?>
 <!--
  Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]