From 9a7b0f5c1049100db34a4bb539f1aca146fa1050 Mon Sep 17 00:00:00 2001 From: Thomas Becker Date: Tue, 13 Aug 2013 13:50:42 +0200 Subject: [PATCH] 412938 Request.setCharacterEncoding now throws UnsupportedEncodingException instead of UnsupportedCharsetException --- .../org/eclipse/jetty/server/Request.java | 12 ++++++- .../org/eclipse/jetty/server/RequestTest.java | 33 +++++++++---------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index c3733f48f8e..c6db08cc1e2 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -28,6 +28,7 @@ import java.io.UnsupportedEncodingException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.nio.charset.Charset; +import java.nio.charset.UnsupportedCharsetException; import java.security.Principal; import java.util.ArrayList; import java.util.Collection; @@ -1701,7 +1702,16 @@ public class Request implements HttpServletRequest // check encoding is supported if (!StringUtil.isUTF8(encoding)) - Charset.forName(encoding); + { + try + { + Charset.forName(encoding); + } + catch (UnsupportedCharsetException e) + { + throw new UnsupportedEncodingException(e.getMessage()); + } + } } /* ------------------------------------------------------------ */ diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java index 370c8e283c5..e2d94bfbbf4 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java @@ -18,26 +18,17 @@ package org.eclipse.jetty.server; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.Reader; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Enumeration; import java.util.Map; import java.util.concurrent.TimeUnit; - import javax.servlet.MultipartConfigElement; import javax.servlet.ServletException; import javax.servlet.ServletRequestEvent; @@ -58,10 +49,17 @@ import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.StdErrLog; import org.hamcrest.Matchers; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + public class RequestTest { private static final Logger LOG = Log.getLogger(RequestTest.class); @@ -466,13 +464,6 @@ public class RequestTest assertEquals("remote",results.get(i++)); assertEquals("::1",results.get(i++)); assertEquals("8888",results.get(i++)); - - - - - - - } @Test @@ -1042,6 +1033,12 @@ public class RequestTest } } + @Test(expected = UnsupportedEncodingException.class) + public void testNotSupportedCharacterEncoding() throws UnsupportedEncodingException + { + Request request = new Request(null, null); + request.setCharacterEncoding("doesNotExist"); + } interface RequestTester {