Author: markt
Date: Mon Jun 19 19:56:33 2017
New Revision: 1799273

URL: http://svn.apache.org/viewvc?rev=1799273&view=rev
Log:
Refactor to reduce the need to deprecate code in 8.5.x

Modified:
    tomcat/tc8.5.x/trunk/java/org/apache/catalina/connector/Response.java
    tomcat/tc8.5.x/trunk/java/org/apache/coyote/Response.java

Modified: tomcat/tc8.5.x/trunk/java/org/apache/catalina/connector/Response.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/catalina/connector/Response.java?rev=1799273&r1=1799272&r2=1799273&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/java/org/apache/catalina/connector/Response.java 
(original)
+++ tomcat/tc8.5.x/trunk/java/org/apache/catalina/connector/Response.java Mon 
Jun 19 19:56:33 2017
@@ -18,7 +18,6 @@ package org.apache.catalina.connector;
 
 import java.io.IOException;
 import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.nio.charset.Charset;
@@ -808,8 +807,8 @@ public class Response implements HttpSer
             // Ignore charset if getWriter() has already been called
             if (!usingWriter) {
                 try {
-                    getCoyoteResponse().setCharset(m[1]);
-                } catch (UnsupportedEncodingException e) {
+                    getCoyoteResponse().setCharacterEncoding(m[1]);
+                } catch (IllegalArgumentException e) {
                     log.warn(sm.getString("coyoteResponse.encoding.invalid", 
m[1]), e);
                 }
 
@@ -824,10 +823,11 @@ public class Response implements HttpSer
      * of the request. This method must be called prior to reading
      * request parameters or reading input using getReader().
      *
-     * @param charset String containing the name of the character encoding.
+     * @param characterEncoding String containing the name of the character
+     *                          encoding.
      */
     @Override
-    public void setCharacterEncoding(String charset) {
+    public void setCharacterEncoding(String characterEncoding) {
 
         if (isCommitted()) {
             return;
@@ -845,9 +845,9 @@ public class Response implements HttpSer
         }
 
         try {
-            getCoyoteResponse().setCharset(charset);
-        } catch (UnsupportedEncodingException e) {
-            log.warn(sm.getString("coyoteResponse.encoding.invalid", charset), 
e);
+            getCoyoteResponse().setCharacterEncoding(characterEncoding);
+        } catch (IllegalArgumentException e) {
+            log.warn(sm.getString("coyoteResponse.encoding.invalid", 
characterEncoding), e);
             return;
         }
         isCharacterEncodingSet = true;
@@ -887,8 +887,8 @@ public class Response implements HttpSer
         String charset = getContext().getCharset(locale);
         if (charset != null) {
             try {
-                getCoyoteResponse().setCharset(charset);
-            } catch (UnsupportedEncodingException e) {
+                getCoyoteResponse().setCharacterEncoding(charset);
+            } catch (IllegalArgumentException e) {
                 log.warn(sm.getString("coyoteResponse.encoding.invalid", 
charset), e);
             }
         }

Modified: tomcat/tc8.5.x/trunk/java/org/apache/coyote/Response.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/coyote/Response.java?rev=1799273&r1=1799272&r2=1799273&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/java/org/apache/coyote/Response.java (original)
+++ tomcat/tc8.5.x/trunk/java/org/apache/coyote/Response.java Mon Jun 19 
19:56:33 2017
@@ -400,30 +400,10 @@ public final class Response {
      * of the response. This method must be called prior to writing output
      * using getWriter().
      *
-     * @param charset String containing the name of the character encoding.
-     *
-     * @deprecated This method will be removed in Tomcat 9.0.x
+     * @param characterEncoding String containing the name of the character
+     *                          encoding.
      */
-    @Deprecated
-    public void setCharacterEncoding(String charset) {
-        try {
-            setCharset(charset);
-        } catch (UnsupportedEncodingException e) {
-            log.warn(sm.getString("response.encoding.invalid", charset), e);
-        }
-    }
-
-
-    /**
-     * Overrides the character encoding used in the body of the response. This
-     * method must be called prior to writing output using getWriter().
-     *
-     * @param characterEncoding The name of character encoding.
-     *
-     * @throws UnsupportedEncodingException If the specified name is not
-     *         recognised
-     */
-    public void setCharset(String characterEncoding) throws 
UnsupportedEncodingException {
+    public void setCharacterEncoding(String characterEncoding) {
         if (isCommitted()) {
             return;
         }
@@ -431,7 +411,11 @@ public final class Response {
             return;
         }
 
-        this.charset = B2CConverter.getCharset(characterEncoding);
+        try {
+            this.charset = B2CConverter.getCharset(characterEncoding);
+        } catch (UnsupportedEncodingException e) {
+            throw new IllegalArgumentException(e);
+        }
         this.characterEncoding = characterEncoding;
     }
 



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

Reply via email to