Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2013-11-03 07:22:09 +0000
committerGreg Wilkins2013-11-03 07:22:09 +0000
commiteb3bb660b52b6eaa146b4fa77afd8fd1f63e6bba (patch)
tree6d501857bbc82c9240ba1cd603f981797349b3d5 /jetty-servlets
parent6f1eb712e9bb3341d257a75511ebc8e73e0faca0 (diff)
parent6b0269a16d7ee923ae70082eb60595d432861707 (diff)
downloadorg.eclipse.jetty.project-eb3bb660b52b6eaa146b4fa77afd8fd1f63e6bba.tar.gz
org.eclipse.jetty.project-eb3bb660b52b6eaa146b4fa77afd8fd1f63e6bba.tar.xz
org.eclipse.jetty.project-eb3bb660b52b6eaa146b4fa77afd8fd1f63e6bba.zip
Merge remote-tracking branch 'origin/master' into jetty-9.1
Conflicts: jetty-client/src/main/java/org/eclipse/jetty/client/util/DigestAuthentication.java jetty-client/src/test/java/org/eclipse/jetty/client/HttpReceiverTest.java jetty-client/src/test/java/org/eclipse/jetty/client/HttpSenderTest.java jetty-http/src/main/java/org/eclipse/jetty/http/HttpField.java jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/HeadersBlockGenerator.java jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/parser/HeadersBlockParser.java jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketFrame.java jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateCompressionMethodTest.java jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/PerMessageDeflateExtensionTest.java
Diffstat (limited to 'jetty-servlets')
-rw-r--r--jetty-servlets/src/main/java/org/eclipse/jetty/servlets/EventSourceServlet.java31
-rw-r--r--jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java25
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java7
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/EventSourceServletTest.java5
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java3
5 files changed, 38 insertions, 33 deletions
diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/EventSourceServlet.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/EventSourceServlet.java
index ebabd6845a..697d329806 100644
--- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/EventSourceServlet.java
+++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/EventSourceServlet.java
@@ -22,8 +22,7 @@ package org.eclipse.jetty.servlets;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.Enumeration;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@@ -54,24 +53,10 @@ import javax.servlet.http.HttpServletResponse;
*/
public abstract class EventSourceServlet extends HttpServlet
{
- private static final Charset UTF_8 = Charset.forName("UTF-8");
private static final byte[] CRLF = new byte[]{'\r', '\n'};
- private static final byte[] EVENT_FIELD;
- private static final byte[] DATA_FIELD;
- private static final byte[] COMMENT_FIELD;
- static
- {
- try
- {
- EVENT_FIELD = "event: ".getBytes(UTF_8.name());
- DATA_FIELD = "data: ".getBytes(UTF_8.name());
- COMMENT_FIELD = ": ".getBytes(UTF_8.name());
- }
- catch (UnsupportedEncodingException x)
- {
- throw new RuntimeException(x);
- }
- }
+ private static final byte[] EVENT_FIELD = "event: ".getBytes(StandardCharsets.UTF_8);
+ private static final byte[] DATA_FIELD = "data: ".getBytes(StandardCharsets.UTF_8);
+ private static final byte[] COMMENT_FIELD = ": ".getBytes(StandardCharsets.UTF_8);
private ScheduledExecutorService scheduler;
private int heartBeatPeriod = 10;
@@ -129,7 +114,7 @@ public abstract class EventSourceServlet extends HttpServlet
protected void respond(HttpServletRequest request, HttpServletResponse response) throws IOException
{
response.setStatus(HttpServletResponse.SC_OK);
- response.setCharacterEncoding(UTF_8.name());
+ response.setCharacterEncoding(StandardCharsets.UTF_8.name());
response.setContentType("text/event-stream");
// By adding this header, and not closing the connection,
// we disable HTTP chunking, and we can use write()+flush()
@@ -164,7 +149,7 @@ public abstract class EventSourceServlet extends HttpServlet
synchronized (this)
{
output.write(EVENT_FIELD);
- output.write(name.getBytes(UTF_8.name()));
+ output.write(name.getBytes(StandardCharsets.UTF_8));
output.write(CRLF);
data(data);
}
@@ -180,7 +165,7 @@ public abstract class EventSourceServlet extends HttpServlet
while ((line = reader.readLine()) != null)
{
output.write(DATA_FIELD);
- output.write(line.getBytes(UTF_8.name()));
+ output.write(line.getBytes(StandardCharsets.UTF_8));
output.write(CRLF);
}
output.write(CRLF);
@@ -194,7 +179,7 @@ public abstract class EventSourceServlet extends HttpServlet
synchronized (this)
{
output.write(COMMENT_FIELD);
- output.write(comment.getBytes(UTF_8.name()));
+ output.write(comment.getBytes(StandardCharsets.UTF_8));
output.write(CRLF);
output.write(CRLF);
flush();
diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java
index 253d6d5f18..85013735b2 100644
--- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java
+++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java
@@ -24,6 +24,9 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.charset.UnsupportedCharsetException;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
@@ -223,7 +226,7 @@ public class MultiPartFilter implements Filter
/* ------------------------------------------------------------------------------- */
private static class Wrapper extends HttpServletRequestWrapper
{
- String _encoding=StringUtil.__UTF8;
+ Charset _encoding=StandardCharsets.UTF_8;
MultiMap<Object> _params;
/* ------------------------------------------------------------------------------- */
@@ -339,7 +342,14 @@ public class MultiPartFilter implements Filter
public void setCharacterEncoding(String enc)
throws UnsupportedEncodingException
{
- _encoding=enc;
+ try
+ {
+ _encoding=Charset.forName(enc);
+ }
+ catch (UnsupportedCharsetException e)
+ {
+ throw new UnsupportedEncodingException(e.getMessage());
+ }
}
@@ -350,11 +360,18 @@ public class MultiPartFilter implements Filter
//check if there is a specific encoding for the parameter
Object ct = _params.getValue(name+CONTENT_TYPE_SUFFIX,0);
//use default if not
- String contentType = _encoding;
+ Charset contentType = _encoding;
if (ct != null)
{
String tmp = MimeTypes.getCharsetFromContentType((String)ct);
- contentType = (tmp == null?_encoding:tmp);
+ try
+ {
+ contentType = (tmp == null?_encoding:Charset.forName(tmp));
+ }
+ catch (UnsupportedCharsetException e)
+ {
+ throw new UnsupportedEncodingException(e.getMessage());
+ }
}
return new String(bytes,contentType);
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java
index 63c6711f9b..516c690d5b 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java
@@ -27,6 +27,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.EnumSet;
import javax.servlet.DispatcherType;
@@ -122,7 +123,7 @@ public abstract class AbstractDoSFilterTest
for (int i = loops; i-- > 0;)
{
- out.write(loopRequests.getBytes("UTF-8"));
+ out.write(loopRequests.getBytes(StandardCharsets.UTF_8));
out.flush();
if (i > 0 && pauseBetweenLoops > 0)
{
@@ -133,7 +134,7 @@ public abstract class AbstractDoSFilterTest
{
Thread.sleep(pauseBeforeLast);
}
- out.write(lastRequest.getBytes("UTF-8"));
+ out.write(lastRequest.getBytes(StandardCharsets.UTF_8));
out.flush();
InputStream in = socket.getInputStream();
@@ -142,7 +143,7 @@ public abstract class AbstractDoSFilterTest
// don't read in anything, forcing the request to time out
Thread.sleep(_requestMaxTime * 2);
}
- String response = IO.toString(in,"UTF-8");
+ String response = IO.toString(in,StandardCharsets.UTF_8);
return response;
}
}
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/EventSourceServletTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/EventSourceServletTest.java
index 6f2d6ab715..75fc4b7191 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/EventSourceServletTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/EventSourceServletTest.java
@@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@@ -326,7 +327,7 @@ public class EventSourceServletTest
handshake += "Host: localhost:" + serverPort + "\r\n";
handshake += "Accept: text/event-stream\r\n";
handshake += "\r\n";
- output.write(handshake.getBytes("UTF-8"));
+ output.write(handshake.getBytes(StandardCharsets.UTF_8));
output.flush();
}
@@ -334,7 +335,7 @@ public class EventSourceServletTest
{
// Read and discard the HTTP response
InputStream input = socket.getInputStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
String line = reader.readLine();
while (line != null)
{
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java
index 9098ea3bcf..ba434298e0 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java
@@ -31,6 +31,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
import java.util.EnumSet;
import java.util.Map;
@@ -867,7 +868,7 @@ public class MultipartFilterTest
baos.write(("--" + boundary + "\r\n"+
"Content-Disposition: form-data; name=\"ttt\"\r\n"+
"Content-Type: application/octet-stream; charset=UTF-8\r\n\r\n").getBytes());
- baos.write("ttt\u01FCzzz".getBytes(StringUtil.__UTF8));
+ baos.write("ttt\u01FCzzz".getBytes(StandardCharsets.UTF_8));
baos.write(("\r\n--" + boundary + "--\r\n\r\n").getBytes());

Back to the top