412938 Request.setCharacterEncoding now throws UnsupportedEncodingException instead of UnsupportedCharsetException

This commit is contained in:
Thomas Becker 2013-08-13 13:50:42 +02:00
parent 75f87a289a
commit 9a7b0f5c10
2 changed files with 26 additions and 19 deletions

View File

@ -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());
}
}
}
/* ------------------------------------------------------------ */

View File

@ -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
{