Author: markt
Date: Wed Mar  1 13:10:42 2017
New Revision: 1784926

URL: http://svn.apache.org/viewvc?rev=1784926&view=rev
Log:
Servlet 4.0
New elements for the deployment descriptor and new methods on the 
ServletContext to enable the default request and response character encodings 
to be set per web application.

Modified:
    tomcat/trunk/java/javax/servlet/ServletContext.java
    tomcat/trunk/java/javax/servlet/ServletRequest.java
    tomcat/trunk/java/javax/servlet/ServletResponse.java
    tomcat/trunk/java/javax/servlet/resources/web-app_4_0.xsd
    tomcat/trunk/java/org/apache/catalina/Context.java
    tomcat/trunk/java/org/apache/catalina/connector/Request.java
    tomcat/trunk/java/org/apache/catalina/connector/Response.java
    tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
    tomcat/trunk/java/org/apache/catalina/core/ApplicationContextFacade.java
    tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
    tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
    tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java
    tomcat/trunk/java/org/apache/coyote/Request.java
    tomcat/trunk/java/org/apache/coyote/Response.java
    tomcat/trunk/java/org/apache/jasper/servlet/JspCServletContext.java
    tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebRuleSet.java
    tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java
    tomcat/trunk/test/org/apache/tomcat/unittest/TesterContext.java
    tomcat/trunk/test/org/apache/tomcat/unittest/TesterServletContext.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/javax/servlet/ServletContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/servlet/ServletContext.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/javax/servlet/ServletContext.java (original)
+++ tomcat/trunk/java/javax/servlet/ServletContext.java Wed Mar  1 13:10:42 2017
@@ -1013,4 +1013,82 @@ public interface ServletContext {
      * @since Servlet 4.0
      */
     public void setSessionTimeout(int sessionTimeout);
+
+    /**
+     * Get the default character encoding for reading request bodies.
+     *
+     * @return The character encoding name or {@code null} if no default has
+     *         been specified
+     *
+     * @throws UnsupportedOperationException    If called from a
+     *    {@link 
ServletContextListener#contextInitialized(ServletContextEvent)}
+     *    method of a {@link ServletContextListener} that was not defined in a
+     *    web.xml file, a web-fragment.xml file nor annotated with
+     *    {@link javax.servlet.annotation.WebListener}. For example, a
+     *    {@link ServletContextListener} defined in a TLD would not be able to
+     *    use this method.
+     *
+     * @since Servlet 4.0
+     */
+    public String getRequestCharacterEncoding();
+
+    /**
+     * Set the default character encoding to use for reading request bodies.
+     * Calling this method will over-ride any value set in the deployment
+     * descriptor.
+     *
+     * @param encoding The name of the character encoding to use
+     *
+     * @throws UnsupportedOperationException    If called from a
+     *    {@link 
ServletContextListener#contextInitialized(ServletContextEvent)}
+     *    method of a {@link ServletContextListener} that was not defined in a
+     *    web.xml file, a web-fragment.xml file nor annotated with
+     *    {@link javax.servlet.annotation.WebListener}. For example, a
+     *    {@link ServletContextListener} defined in a TLD would not be able to
+     *    use this method.
+     * @throws IllegalStateException If the ServletContext has already been
+     *         initialised
+     *
+     * @since Servlet 4.0
+     */
+    public void setRequestCharacterEncoding(String encoding);
+
+    /**
+     * Get the default character encoding for writing response bodies.
+     *
+     * @return The character encoding name or {@code null} if no default has
+     *         been specified
+     *
+     * @throws UnsupportedOperationException    If called from a
+     *    {@link 
ServletContextListener#contextInitialized(ServletContextEvent)}
+     *    method of a {@link ServletContextListener} that was not defined in a
+     *    web.xml file, a web-fragment.xml file nor annotated with
+     *    {@link javax.servlet.annotation.WebListener}. For example, a
+     *    {@link ServletContextListener} defined in a TLD would not be able to
+     *    use this method.
+     *
+     * @since Servlet 4.0
+     */
+    public String getResponseCharacterEncoding();
+
+    /**
+     * Set the default character encoding to use for writing response bodies.
+     * Calling this method will over-ride any value set in the deployment
+     * descriptor.
+     *
+     * @param encoding The name of the character encoding to use
+     *
+     * @throws UnsupportedOperationException    If called from a
+     *    {@link 
ServletContextListener#contextInitialized(ServletContextEvent)}
+     *    method of a {@link ServletContextListener} that was not defined in a
+     *    web.xml file, a web-fragment.xml file nor annotated with
+     *    {@link javax.servlet.annotation.WebListener}. For example, a
+     *    {@link ServletContextListener} defined in a TLD would not be able to
+     *    use this method.
+     * @throws IllegalStateException If the ServletContext has already been
+     *         initialised
+     *
+     * @since Servlet 4.0
+     */
+    public void setResponseCharacterEncoding(String encoding);
 }

Modified: tomcat/trunk/java/javax/servlet/ServletRequest.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/servlet/ServletRequest.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/javax/servlet/ServletRequest.java (original)
+++ tomcat/trunk/java/javax/servlet/ServletRequest.java Wed Mar  1 13:10:42 2017
@@ -76,8 +76,15 @@ public interface ServletRequest {
 
     /**
      * Returns the name of the character encoding used in the body of this
-     * request. This method returns <code>null</code> if the request does not
-     * specify a character encoding
+     * request. This method returns <code>null</code> if the no character
+     * encoding has been specified. The following priority order is used to
+     * determine the specified encoding:
+     * <ol>
+     * <li>per request</li>
+     * <li>web application default via the deployment descriptor or
+     *     {@link ServletContext#setRequestCharacterEncoding(String)}</li>
+     * <li>container default via container specific configuration</li>
+     * </ol>
      *
      * @return a <code>String</code> containing the name of the character
      *         encoding, or <code>null</code> if the request does not specify a

Modified: tomcat/trunk/java/javax/servlet/ServletResponse.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/servlet/ServletResponse.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/javax/servlet/ServletResponse.java (original)
+++ tomcat/trunk/java/javax/servlet/ServletResponse.java Wed Mar  1 13:10:42 
2017
@@ -32,14 +32,20 @@ import java.util.Locale;
  * multipart response, use a <code>ServletOutputStream</code> and manage the
  * character sections manually.
  * <p>
- * The charset for the MIME body response can be specified explicitly using the
- * {@link #setCharacterEncoding} and {@link #setContentType} methods, or
- * implicitly using the {@link #setLocale} method. Explicit specifications take
- * precedence over implicit specifications. If no charset is specified,
- * ISO-8859-1 will be used. The <code>setCharacterEncoding</code>,
- * <code>setContentType</code>, or <code>setLocale</code> method must be called
- * before <code>getWriter</code> and before committing the response for the
- * character encoding to be used.
+ * The charset for the MIME body response can be specified explicitly or
+ * implicitly. The priority order for specifying the response body is:
+ * <ol>
+ * <li>explicitly per request using {@link #setCharacterEncoding} and
+ *    {@link #setContentType}</li>
+ * <li>implicitly per request using {@link #setLocale}</li>
+ * <li>per web application via the deployment descriptor or
+ *     {@link ServletContext#setRequestCharacterEncoding(String)}</li>
+ * <li>container default via vendor specific configuration</li>
+ * <li>ISO-8859-1</li>
+ * </ol>
+ * The <code>setCharacterEncoding</code>, <code>setContentType</code>, or
+ * <code>setLocale</code> method must be called before <code>getWriter</code>
+ * and before committing the response for the character encoding to be used.
  * <p>
  * See the Internet RFCs such as <a href="http://www.ietf.org/rfc/rfc2045.txt";>
  * RFC 2045</a> for more information on MIME. Protocols such as SMTP and HTTP
@@ -51,14 +57,23 @@ public interface ServletResponse {
 
     /**
      * Returns the name of the character encoding (MIME charset) used for the
-     * body sent in this response. The character encoding may have been
-     * specified explicitly using the {@link #setCharacterEncoding} or
-     * {@link #setContentType} methods, or implicitly using the
-     * {@link #setLocale} method. Explicit specifications take precedence over
-     * implicit specifications. Calls made to these methods after
-     * <code>getWriter</code> has been called or after the response has been
-     * committed have no effect on the character encoding. If no character
-     * encoding has been specified, <code>ISO-8859-1</code> is returned.
+     * body sent in this response.
+     * The charset for the MIME body response can be specified explicitly or
+     * implicitly. The priority order for specifying the response body is:
+     * <ol>
+     * <li>explicitly per request using {@link #setCharacterEncoding} and
+     *    {@link #setContentType}</li>
+     * <li>implicitly per request using {@link #setLocale}</li>
+     * <li>per web application via the deployment descriptor or
+     *     {@link ServletContext#setRequestCharacterEncoding(String)}</li>
+     * <li>container default via vendor specific configuration</li>
+     * <li>ISO-8859-1</li>
+     * </ol>
+     * Calls made to {@link #setCharacterEncoding}, {@link #setContentType} or
+     * {@link #setLocale} after <code>getWriter</code> has been called or after
+     * the response has been committed have no effect on the character 
encoding.
+     * If no character encoding has been specified, <code>ISO-8859-1</code> is
+     * returned.
      * <p>
      * See RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt) for more information
      * about character encoding and MIME.
@@ -134,11 +149,12 @@ public interface ServletResponse {
     /**
      * Sets the character encoding (MIME charset) of the response being sent to
      * the client, for example, to UTF-8. If the character encoding has already
-     * been set by {@link #setContentType} or {@link #setLocale}, this method
-     * overrides it. Calling {@link #setContentType} with the
-     * <code>String</code> of <code>text/html</code> and calling this method
-     * with the <code>String</code> of <code>UTF-8</code> is equivalent with
-     * calling <code>setContentType</code> with the <code>String</code> of
+     * been set by container default, ServletContext default,
+     * {@link #setContentType} or {@link #setLocale}, this method overrides it.
+     * Calling {@link #setContentType} with the <code>String</code> of
+     * <code>text/html</code> and calling this method with the
+     * <code>String</code> of <code>UTF-8</code> is equivalent with calling
+     * <code>setContentType</code> with the <code>String</code> of
      * <code>text/html; charset=UTF-8</code>.
      * <p>
      * This method can be called repeatedly to change the character encoding.

Modified: tomcat/trunk/java/javax/servlet/resources/web-app_4_0.xsd
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/servlet/resources/web-app_4_0.xsd?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/javax/servlet/resources/web-app_4_0.xsd (original)
+++ tomcat/trunk/java/javax/servlet/resources/web-app_4_0.xsd Wed Mar  1 
13:10:42 2017
@@ -298,6 +298,26 @@
           </xsd:documentation>
         </xsd:annotation>
       </xsd:element>
+      <xsd:element name="request-encoding" type="javaee:string">
+        <xsd:annotation>
+          <xsd:documentation>
+
+            When specified, this element provides a default request
+            encoding of the web application.
+
+          </xsd:documentation>
+        </xsd:annotation>
+      </xsd:element>
+      <xsd:element name="response-encoding" type="javaee:string">
+        <xsd:annotation>
+          <xsd:documentation>
+
+            When specified, this element provides a default response
+            encoding of the web application.
+
+          </xsd:documentation>
+        </xsd:annotation>
+      </xsd:element>
       <xsd:element name="deny-uncovered-http-methods" type="javaee:emptyType">
         <xsd:annotation>
           <xsd:documentation>

Modified: tomcat/trunk/java/org/apache/catalina/Context.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Context.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Context.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Context.java Wed Mar  1 13:10:42 2017
@@ -1790,4 +1790,32 @@ public interface Context extends Contain
      *         {@code false}
      */
     public boolean getDispatchersUseEncodedPaths();
+
+    /**
+     * Set the default request body encoding for this web application.
+     *
+     * @param encoding The default encoding
+     */
+    public void setRequestCharacterEncoding(String encoding);
+
+    /**
+     * Get the default request body encoding for this web application.
+     *
+     * @return The default request body encoding
+     */
+    public String getRequestCharacterEncoding();
+
+    /**
+     * Set the default response body encoding for this web application.
+     *
+     * @param encoding The default encoding
+     */
+    public void setResponseCharacterEncoding(String encoding);
+
+    /**
+     * Get the default response body encoding for this web application.
+     *
+     * @return The default response body encoding
+     */
+    public String getResponseCharacterEncoding();
 }

Modified: tomcat/trunk/java/org/apache/catalina/connector/Request.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Request.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Request.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Request.java Wed Mar  1 
13:10:42 2017
@@ -968,7 +968,14 @@ public class Request implements HttpServ
      */
     @Override
     public String getCharacterEncoding() {
-      return coyoteRequest.getCharacterEncoding();
+        String result = coyoteRequest.getCharacterEncoding();
+        if (result == null) {
+            Context context = getContext();
+            if (context != null) {
+                result =  context.getRequestCharacterEncoding();
+            }
+        }
+        return result;
     }
 
 

Modified: tomcat/trunk/java/org/apache/catalina/connector/Response.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Response.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Response.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Response.java Wed Mar  1 
13:10:42 2017
@@ -549,7 +549,17 @@ public class Response implements HttpSer
      */
     @Override
     public String getCharacterEncoding() {
-        return (getCoyoteResponse().getCharacterEncoding());
+        String result = getCoyoteResponse().getCharacterEncoding();
+        if (result == null) {
+            Context context = getContext();
+            if (context != null) {
+                result =  context.getResponseCharacterEncoding();
+            }
+        }
+        if (result == null) {
+            result = org.apache.coyote.Constants.DEFAULT_CHARACTER_ENCODING;
+        }
+        return result;
     }
 
 

Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java Wed Mar  
1 13:10:42 2017
@@ -1288,6 +1288,42 @@ public class ApplicationContext implemen
     }
 
 
+    @Override
+    public String getRequestCharacterEncoding() {
+        return context.getRequestCharacterEncoding();
+    }
+
+
+    @Override
+    public void setRequestCharacterEncoding(String encoding) {
+        if (!context.getState().equals(LifecycleState.STARTING_PREP)) {
+            throw new IllegalStateException(
+                    sm.getString("applicationContext.setRequestEncoding.ise",
+                            getContextPath()));
+        }
+
+        context.setRequestCharacterEncoding(encoding);
+    }
+
+
+    @Override
+    public String getResponseCharacterEncoding() {
+        return context.getResponseCharacterEncoding();
+    }
+
+
+    @Override
+    public void setResponseCharacterEncoding(String encoding) {
+        if (!context.getState().equals(LifecycleState.STARTING_PREP)) {
+            throw new IllegalStateException(
+                    sm.getString("applicationContext.setResponseEncoding.ise",
+                            getContextPath()));
+        }
+
+        context.setResponseCharacterEncoding(encoding);
+    }
+
+
     // -------------------------------------------------------- Package Methods
     protected StandardContext getContext() {
         return this.context;

Modified: 
tomcat/trunk/java/org/apache/catalina/core/ApplicationContextFacade.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationContextFacade.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationContextFacade.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationContextFacade.java 
Wed Mar  1 13:10:42 2017
@@ -801,6 +801,46 @@ public class ApplicationContextFacade im
     }
 
 
+    @Override
+    public String getRequestCharacterEncoding() {
+        if (SecurityUtil.isPackageProtectionEnabled()) {
+            return (String) doPrivileged("getRequestCharacterEncoding", null);
+        } else  {
+            return context.getRequestCharacterEncoding();
+        }
+    }
+
+
+    @Override
+    public void setRequestCharacterEncoding(String encoding) {
+        if (SecurityUtil.isPackageProtectionEnabled()) {
+            doPrivileged("setRequestCharacterEncoding", new Object[] { 
encoding });
+        } else  {
+            context.setRequestCharacterEncoding(encoding);
+        }
+    }
+
+
+    @Override
+    public String getResponseCharacterEncoding() {
+        if (SecurityUtil.isPackageProtectionEnabled()) {
+            return (String) doPrivileged("getResponseCharacterEncoding", null);
+        } else  {
+            return context.getResponseCharacterEncoding();
+        }
+    }
+
+
+    @Override
+    public void setResponseCharacterEncoding(String encoding) {
+        if (SecurityUtil.isPackageProtectionEnabled()) {
+            doPrivileged("setResponseCharacterEncoding", new Object[] { 
encoding });
+        } else  {
+            context.setResponseCharacterEncoding(encoding);
+        }
+    }
+
+
     /**
      * Use reflection to invoke the requested method. Cache the method object
      * to speed up the process

Modified: tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties 
(original)
+++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties Wed Mar  
1 13:10:42 2017
@@ -33,6 +33,8 @@ applicationContext.role.iae=An individua
 applicationContext.roles.iae=Array of roles to declare for context [{0}] 
cannot be null
 applicationContext.setAttribute.namenull=Name cannot be null
 applicationContext.setInitParam.ise=Initialization parameters cannot be set 
after the context has been initialized
+applicationContext.setRequestEncoding.ise=The request encoding cannot be set 
for context {0} as the context has been initialised
+applicationContext.setResponseEncoding.ise=The response encoding cannot be set 
for context {0} as the context has been initialised
 applicationContext.setSessionTimeout.ise=The session timeout cannot be set for 
context {0} as the context has been initialised
 applicationContext.setSessionTracking.ise=The session tracking modes for 
context {0} cannot be set whilst the context is running
 applicationContext.setSessionTracking.iae.invalid=The session tracking mode 
{0} requested for context {1} is not supported by that context

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Wed Mar  1 
13:10:42 2017
@@ -807,10 +807,37 @@ public class StandardContext extends Con
 
     private boolean dispatchersUseEncodedPaths = true;
 
+    private String requestEncoding = null;
+
+    private String responseEncoding = null;
 
     // ----------------------------------------------------- Context Properties
 
     @Override
+    public String getRequestCharacterEncoding() {
+        return requestEncoding;
+    }
+
+
+    @Override
+    public void setRequestCharacterEncoding(String requestEncoding) {
+        this.requestEncoding = requestEncoding;
+    }
+
+
+    @Override
+    public String getResponseCharacterEncoding() {
+        return responseEncoding;
+    }
+
+
+    @Override
+    public void setResponseCharacterEncoding(String responseEncoding) {
+        this.responseEncoding = responseEncoding;
+    }
+
+
+    @Override
     public void setDispatchersUseEncodedPaths(boolean 
dispatchersUseEncodedPaths) {
         this.dispatchersUseEncodedPaths = dispatchersUseEncodedPaths;
     }
@@ -6715,5 +6742,29 @@ public class StandardContext extends Con
             throw new UnsupportedOperationException(
                     sm.getString("noPluggabilityServletContext.notAllowed"));
         }
+
+        @Override
+        public String getRequestCharacterEncoding() {
+            throw new UnsupportedOperationException(
+                    sm.getString("noPluggabilityServletContext.notAllowed"));
+        }
+
+        @Override
+        public void setRequestCharacterEncoding(String encoding) {
+            throw new UnsupportedOperationException(
+                    sm.getString("noPluggabilityServletContext.notAllowed"));
+        }
+
+        @Override
+        public String getResponseCharacterEncoding() {
+            throw new UnsupportedOperationException(
+                    sm.getString("noPluggabilityServletContext.notAllowed"));
+        }
+
+        @Override
+        public void setResponseCharacterEncoding(String encoding) {
+            throw new UnsupportedOperationException(
+                    sm.getString("noPluggabilityServletContext.notAllowed"));
+        }
     }
 }

Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java Wed Mar  1 
13:10:42 2017
@@ -1299,6 +1299,7 @@ public class ContextConfig implements Li
                 webxml.getMimeMappings().entrySet()) {
             context.addMimeMapping(entry.getKey(), entry.getValue());
         }
+        context.setRequestCharacterEncoding(webxml.getRequestEncoding());
         // Name is just used for ordering
         for (ContextResourceEnvRef resource :
                 webxml.getResourceEnvRefs().values()) {
@@ -1307,6 +1308,7 @@ public class ContextConfig implements Li
         for (ContextResource resource : webxml.getResourceRefs().values()) {
             context.getNamingResources().addResource(resource);
         }
+        context.setResponseCharacterEncoding(webxml.getResponseEncoding());
         boolean allAuthenticatedUsersIsAppRole =
                 webxml.getSecurityRoles().contains(
                         SecurityConstraint.ROLE_ALL_AUTHENTICATED_USERS);

Modified: tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java Wed Mar  1 
13:10:42 2017
@@ -789,4 +789,14 @@ public class FailedContext extends Lifec
     public void setDispatchersUseEncodedPaths(boolean 
dispatchersUseEncodedPaths) { /* NO-OP */ }
     @Override
     public boolean getDispatchersUseEncodedPaths() { return true; }
+
+    @Override
+    public void setRequestCharacterEncoding(String encoding) { /* NO-OP */ }
+    @Override
+    public String getRequestCharacterEncoding() { return null; }
+
+    @Override
+    public void setResponseCharacterEncoding(String encoding) { /* NO-OP */ }
+    @Override
+    public String getResponseCharacterEncoding() { return null; }
 }
\ No newline at end of file

Modified: tomcat/trunk/java/org/apache/coyote/Request.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/Request.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/Request.java (original)
+++ tomcat/trunk/java/org/apache/coyote/Request.java Wed Mar  1 13:10:42 2017
@@ -292,8 +292,8 @@ public final class Request {
         }
 
         charEncoding = getCharsetFromContentType(getContentType());
-        return charEncoding;
 
+        return charEncoding;
     }
 
 

Modified: tomcat/trunk/java/org/apache/coyote/Response.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/Response.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/Response.java (original)
+++ tomcat/trunk/java/org/apache/coyote/Response.java Wed Mar  1 13:10:42 2017
@@ -101,7 +101,7 @@ public final class Response {
      */
     String contentType = null;
     String contentLanguage = null;
-    String characterEncoding = Constants.DEFAULT_CHARACTER_ENCODING;
+    String characterEncoding = null;
     long contentLength = -1;
     private Locale locale = DEFAULT_LOCALE;
 
@@ -508,7 +508,7 @@ public final class Response {
         contentType = null;
         contentLanguage = null;
         locale = DEFAULT_LOCALE;
-        characterEncoding = Constants.DEFAULT_CHARACTER_ENCODING;
+        characterEncoding = null;
         charsetSet = false;
         contentLength = -1;
         status = 200;

Modified: tomcat/trunk/java/org/apache/jasper/servlet/JspCServletContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/servlet/JspCServletContext.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/servlet/JspCServletContext.java 
(original)
+++ tomcat/trunk/java/org/apache/jasper/servlet/JspCServletContext.java Wed Mar 
 1 13:10:42 2017
@@ -706,4 +706,24 @@ public class JspCServletContext implemen
     public void setSessionTimeout(int sessionTimeout) {
         // NO-OP
     }
+
+    @Override
+    public String getRequestCharacterEncoding() {
+        return null;
+    }
+
+    @Override
+    public void setRequestCharacterEncoding(String encoding) {
+        // NO-OP
+    }
+
+    @Override
+    public String getResponseCharacterEncoding() {
+        return null;
+    }
+
+    @Override
+    public void setResponseCharacterEncoding(String encoding) {
+        // NO-OP
+    }
 }

Modified: 
tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebRuleSet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebRuleSet.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebRuleSet.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebRuleSet.java Wed 
Mar  1 13:10:42 2017
@@ -196,6 +196,8 @@ public class WebRuleSet extends RuleSetB
                                    "addAbsoluteOrderingOthers");
             digester.addRule(fullPrefix + "/deny-uncovered-http-methods",
                     new SetDenyUncoveredHttpMethodsRule());
+            digester.addCallMethod(fullPrefix + "/request-encoding", 
"setRequestEncoding", 0);
+            digester.addCallMethod(fullPrefix + "/response-encoding", 
"setResponseEncoding", 0);
         }
 
         digester.addCallMethod(fullPrefix + "/context-param",

Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java Wed Mar 
 1 13:10:42 2017
@@ -41,6 +41,7 @@ import javax.servlet.descriptor.TaglibDe
 
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.buf.B2CConverter;
 import org.apache.tomcat.util.buf.UDecoder;
 import org.apache.tomcat.util.descriptor.XmlIdentifiers;
 import org.apache.tomcat.util.digester.DocumentProperties;
@@ -609,6 +610,36 @@ public class WebXml extends XmlEncodingB
         return new JspConfigDescriptorImpl(descriptors, tlds);
     }
 
+    private String requestEncoding;
+    public String getRequestEncoding() {
+        return requestEncoding;
+    }
+    public void setRequestEncoding(String requestEncoding) {
+        if (requestEncoding == null) {
+            try {
+                B2CConverter.getCharset(requestEncoding);
+            } catch (UnsupportedEncodingException e) {
+                throw new IllegalArgumentException(e);
+            }
+        }
+        this.requestEncoding = requestEncoding;
+    }
+
+    private String responseEncoding;
+    public String getResponseEncoding() {
+        return responseEncoding;
+    }
+    public void setResponseEncoding(String responseEncoding) {
+        if (responseEncoding == null) {
+            try {
+                B2CConverter.getCharset(responseEncoding);
+            } catch (UnsupportedEncodingException e) {
+                throw new IllegalArgumentException(e);
+            }
+        }
+        this.responseEncoding = responseEncoding;
+    }
+
     // Attributes not defined in web.xml or web-fragment.xml
 
     // URL of JAR / exploded JAR for this web-fragment
@@ -1307,6 +1338,7 @@ public class WebXml extends XmlEncodingB
                     sb.append("    </locale-encoding-mapping>\n");
                 }
                 sb.append("  </locale-encoding-mapping-list>\n");
+                sb.append("\n");
             }
         }
 
@@ -1314,11 +1346,16 @@ public class WebXml extends XmlEncodingB
         if (getMajorVersion() > 3 ||
                 (getMajorVersion() == 3 && getMinorVersion() > 0)) {
             if (denyUncoveredHttpMethods) {
-                sb.append("\n");
                 sb.append("  <deny-uncovered-http-methods/>");
+                sb.append("\n");
             }
         }
 
+        // request-encoding and response-encoding was introduced in Servlet 4.0
+        if (getMajorVersion() >= 4) {
+            appendElement(sb, INDENT2, "request-encoding", requestEncoding);
+            appendElement(sb, INDENT2, "response-encoding", responseEncoding);
+        }
         sb.append("</web-app>");
         return sb.toString();
     }
@@ -1432,7 +1469,7 @@ public class WebXml extends XmlEncodingB
         }
 
         // Note: Not permitted in fragments but we also use fragments for
-        //       per-Host and global defaults so it may appear there
+        //       per-Host and global defaults so they may appear there
         if (!denyUncoveredHttpMethods) {
             for (WebXml fragment : fragments) {
                 if (fragment.getDenyUncoveredHttpMethods()) {
@@ -1441,6 +1478,20 @@ public class WebXml extends XmlEncodingB
                 }
             }
         }
+        if (requestEncoding == null) {
+            for (WebXml fragment : fragments) {
+                if (fragment.getRequestEncoding() != null) {
+                    requestEncoding = fragment.getRequestEncoding();
+                }
+            }
+        }
+        if (responseEncoding == null) {
+            for (WebXml fragment : fragments) {
+                if (fragment.getResponseEncoding() != null) {
+                    responseEncoding = fragment.getResponseEncoding();
+                }
+            }
+        }
 
         if (distributable) {
             for (WebXml fragment : fragments) {

Modified: tomcat/trunk/test/org/apache/tomcat/unittest/TesterContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/unittest/TesterContext.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/unittest/TesterContext.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/unittest/TesterContext.java Wed Mar  1 
13:10:42 2017
@@ -1251,4 +1251,14 @@ public class TesterContext implements Co
     public void setDispatchersUseEncodedPaths(boolean 
dispatchersUseEncodedPaths) { /* NO-OP */ }
     @Override
     public boolean getDispatchersUseEncodedPaths() { return true; }
+
+    @Override
+    public void setRequestCharacterEncoding(String encoding) { /* NO-OP */ }
+    @Override
+    public String getRequestCharacterEncoding() { return null; }
+
+    @Override
+    public void setResponseCharacterEncoding(String encoding) { /* NO-OP */ }
+    @Override
+    public String getResponseCharacterEncoding() { return null; }
 }

Modified: tomcat/trunk/test/org/apache/tomcat/unittest/TesterServletContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/unittest/TesterServletContext.java?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/unittest/TesterServletContext.java 
(original)
+++ tomcat/trunk/test/org/apache/tomcat/unittest/TesterServletContext.java Wed 
Mar  1 13:10:42 2017
@@ -357,4 +357,24 @@ public class TesterServletContext implem
     public void setSessionTimeout(int sessionTimeout) {
         throw new RuntimeException("Not implemented");
     }
+
+    @Override
+    public String getRequestCharacterEncoding() {
+        throw new RuntimeException("Not implemented");
+    }
+
+    @Override
+    public void setRequestCharacterEncoding(String encoding) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    @Override
+    public String getResponseCharacterEncoding() {
+        throw new RuntimeException("Not implemented");
+    }
+
+    @Override
+    public void setResponseCharacterEncoding(String encoding) {
+        throw new RuntimeException("Not implemented");
+    }
 }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1784926&r1=1784925&r2=1784926&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed Mar  1 13:10:42 2017
@@ -128,8 +128,13 @@
       </fix>
       <update>
         Update the Servlet 4.0 API implementation to align with the latest
-        proposals from the Servlet 4.0 expert group. Note that the Servlet 4.0
-        API is still a work in progress and further changes are likely. (markt)
+        proposals from the Servlet 4.0 expert group. This includes updates to
+        the new Servlet mapping API, new methods on the
+        <code>ServletContext</code> to make the available API more equivalent 
to
+        the deployment descriptor, updates to the HTTP push API and the ability
+        to set default request and response character encoding per web
+        application. Note that the Servlet 4.0 API is still a work in progress
+        and further changes are likely. (markt)
       </update>
     </changelog>
   </subsection>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to