Merge branch 'master' into release-9

This commit is contained in:
Jesse McConnell 2013-11-07 08:40:42 -06:00
commit ebe5e04f7b
134 changed files with 1079 additions and 672 deletions

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.client;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
import java.util.List;
@ -92,13 +93,20 @@ public class HttpContentResponse implements ContentResponse
public String getContentAsString()
{
String encoding = this.encoding;
try
if (encoding == null)
{
return new String(getContent(), encoding == null ? "UTF-8" : encoding);
return new String(getContent(), StandardCharsets.UTF_8);
}
catch (UnsupportedEncodingException e)
else
{
throw new UnsupportedCharsetException(encoding);
try
{
return new String(getContent(), encoding);
}
catch (UnsupportedEncodingException e)
{
throw new UnsupportedCharsetException(encoding);
}
}
}

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.client.util;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.Authentication;
@ -73,8 +74,7 @@ public class BasicAuthentication implements Authentication
@Override
public Result authenticate(Request request, ContentResponse response, HeaderInfo headerInfo, Attributes context)
{
String encoding = StringUtil.__ISO_8859_1;
String value = "Basic " + B64Code.encode(user + ":" + password, encoding);
String value = "Basic " + B64Code.encode(user + ":" + password, StandardCharsets.ISO_8859_1);
return new BasicResult(headerInfo.getHeader(), uri, value);
}

View File

@ -20,6 +20,8 @@ package org.eclipse.jetty.client.util;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
import java.util.Locale;
@ -130,7 +132,7 @@ public abstract class BufferingResponseListener extends Response.Listener.Empty
{
String encoding = this.encoding;
if (encoding == null)
encoding = "UTF-8";
return getContentAsString(StandardCharsets.UTF_8);
return getContentAsString(encoding);
}
@ -150,4 +152,14 @@ public abstract class BufferingResponseListener extends Response.Listener.Empty
throw new UnsupportedCharsetException(encoding);
}
}
/**
* @param encoding the encoding of the content bytes
* @return the content as a string, with the specified encoding
* @see #getContentAsString()
*/
public String getContentAsString(Charset encoding)
{
return new String(getContent(), encoding);
}
}

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.client.util;
import java.net.URI;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
@ -217,14 +218,13 @@ public class DigestAuthentication implements Authentication
if (digester == null)
return;
Charset charset = Charset.forName("ISO-8859-1");
String A1 = user + ":" + realm + ":" + password;
String hashA1 = toHexString(digester.digest(A1.getBytes(charset)));
String hashA1 = toHexString(digester.digest(A1.getBytes(StandardCharsets.ISO_8859_1)));
String A2 = request.method() + ":" + request.getURI();
if ("auth-int".equals(qop))
A2 += ":" + toHexString(digester.digest(content));
String hashA2 = toHexString(digester.digest(A2.getBytes(charset)));
String hashA2 = toHexString(digester.digest(A2.getBytes(StandardCharsets.ISO_8859_1)));
String nonceCount;
String clientNonce;
@ -241,7 +241,7 @@ public class DigestAuthentication implements Authentication
clientNonce = null;
A3 = hashA1 + ":" + nonce + ":" + hashA2;
}
String hashA3 = toHexString(digester.digest(A3.getBytes(charset)));
String hashA3 = toHexString(digester.digest(A3.getBytes(StandardCharsets.ISO_8859_1)));
StringBuilder value = new StringBuilder("Digest");
value.append(" username=\"").append(user).append("\"");

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.client.util;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.client.api.ContentProvider;
@ -32,7 +33,7 @@ public class StringContentProvider extends BytesContentProvider
{
public StringContentProvider(String content)
{
this(content, "UTF-8");
this(content, StandardCharsets.UTF_8);
}
public StringContentProvider(String content, String encoding)

View File

@ -26,6 +26,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@ -59,7 +60,7 @@ public class GZIPContentDecoderTest
data += data;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes("UTF-8"));
output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
@ -68,7 +69,7 @@ public class GZIPContentDecoderTest
int read;
while ((read = input.read()) >= 0)
baos.write(read);
assertEquals(data, new String(baos.toByteArray(), "UTF-8"));
assertEquals(data, new String(baos.toByteArray(), StandardCharsets.UTF_8));
}
@Test
@ -91,13 +92,13 @@ public class GZIPContentDecoderTest
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes("UTF-8"));
output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
GZIPContentDecoder decoder = new GZIPContentDecoder();
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes));
assertEquals(data, Charset.forName("UTF-8").decode(decoded).toString());
assertEquals(data, StandardCharsets.UTF_8.decode(decoded).toString());
}
@Test
@ -107,7 +108,7 @@ public class GZIPContentDecoderTest
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes("UTF-8"));
output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
@ -121,7 +122,7 @@ public class GZIPContentDecoderTest
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1));
assertEquals(0, decoded.capacity());
decoded = decoder.decode(ByteBuffer.wrap(bytes2));
assertEquals(data, Charset.forName("UTF-8").decode(decoded).toString());
assertEquals(data, StandardCharsets.UTF_8.decode(decoded).toString());
}
@Test
@ -131,7 +132,7 @@ public class GZIPContentDecoderTest
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes("UTF-8"));
output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
@ -143,7 +144,7 @@ public class GZIPContentDecoderTest
GZIPContentDecoder decoder = new GZIPContentDecoder();
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1));
assertEquals(data, Charset.forName("UTF-8").decode(decoded).toString());
assertEquals(data, StandardCharsets.UTF_8.decode(decoded).toString());
assertFalse(decoder.isFinished());
decoded = decoder.decode(ByteBuffer.wrap(bytes2));
assertEquals(0, decoded.remaining());
@ -157,7 +158,7 @@ public class GZIPContentDecoderTest
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes("UTF-8"));
output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
@ -171,7 +172,7 @@ public class GZIPContentDecoderTest
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1));
assertEquals(0, decoded.capacity());
decoded = decoder.decode(ByteBuffer.wrap(bytes2));
assertEquals(data, Charset.forName("UTF-8").decode(decoded).toString());
assertEquals(data, StandardCharsets.UTF_8.decode(decoded).toString());
}
@Test
@ -180,14 +181,14 @@ public class GZIPContentDecoderTest
String data1 = "0";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data1.getBytes("UTF-8"));
output.write(data1.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes1 = baos.toByteArray();
String data2 = "1";
baos = new ByteArrayOutputStream();
output = new GZIPOutputStream(baos);
output.write(data2.getBytes("UTF-8"));
output.write(data2.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes2 = baos.toByteArray();
@ -198,11 +199,11 @@ public class GZIPContentDecoderTest
GZIPContentDecoder decoder = new GZIPContentDecoder();
ByteBuffer buffer = ByteBuffer.wrap(bytes);
ByteBuffer decoded = decoder.decode(buffer);
assertEquals(data1, Charset.forName("UTF-8").decode(decoded).toString());
assertEquals(data1, StandardCharsets.UTF_8.decode(decoded).toString());
assertTrue(decoder.isFinished());
assertTrue(buffer.hasRemaining());
decoded = decoder.decode(buffer);
assertEquals(data2, Charset.forName("UTF-8").decode(decoded).toString());
assertEquals(data2, StandardCharsets.UTF_8.decode(decoded).toString());
assertTrue(decoder.isFinished());
assertFalse(buffer.hasRemaining());
}
@ -215,7 +216,7 @@ public class GZIPContentDecoderTest
data += data;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes("UTF-8"));
output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
@ -225,7 +226,7 @@ public class GZIPContentDecoderTest
while (buffer.hasRemaining())
{
ByteBuffer decoded = decoder.decode(buffer);
result += Charset.forName("UTF-8").decode(decoded).toString();
result += StandardCharsets.UTF_8.decode(decoded).toString();
}
assertEquals(data, result);
}
@ -238,7 +239,7 @@ public class GZIPContentDecoderTest
data += data;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes("UTF-8"));
output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
@ -249,7 +250,7 @@ public class GZIPContentDecoderTest
{
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(new byte[]{buffer.get()}));
if (decoded.hasRemaining())
result += Charset.forName("UTF-8").decode(decoded).toString();
result += StandardCharsets.UTF_8.decode(decoded).toString();
}
assertEquals(data, result);
assertTrue(decoder.isFinished());
@ -263,12 +264,12 @@ public class GZIPContentDecoderTest
data1 += data1;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data1.getBytes("UTF-8"));
output.write(data1.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes1 = baos.toByteArray();
String data2 = "HELLO";
byte[] bytes2 = data2.getBytes("UTF-8");
byte[] bytes2 = data2.getBytes(StandardCharsets.UTF_8);
byte[] bytes = new byte[bytes1.length + bytes2.length];
System.arraycopy(bytes1, 0, bytes, 0, bytes1.length);
@ -281,12 +282,12 @@ public class GZIPContentDecoderTest
{
ByteBuffer decoded = decoder.decode(buffer);
if (decoded.hasRemaining())
result += Charset.forName("UTF-8").decode(decoded).toString();
result += StandardCharsets.UTF_8.decode(decoded).toString();
if (decoder.isFinished())
break;
}
assertEquals(data1, result);
assertTrue(buffer.hasRemaining());
assertEquals(data2, Charset.forName("UTF-8").decode(buffer).toString());
assertEquals(data2, StandardCharsets.UTF_8.decode(buffer).toString());
}
}

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.client;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CountDownLatch;
@ -60,13 +61,13 @@ public class HttpClientContinueTest extends AbstractHttpClientServerTest
@Test
public void test_Expect100Continue_WithOneContent_Respond100Continue() throws Exception
{
test_Expect100Continue_Respond100Continue("data1".getBytes("UTF-8"));
test_Expect100Continue_Respond100Continue("data1".getBytes(StandardCharsets.UTF_8));
}
@Test
public void test_Expect100Continue_WithMultipleContents_Respond100Continue() throws Exception
{
test_Expect100Continue_Respond100Continue("data1".getBytes("UTF-8"), "data2".getBytes("UTF-8"), "data3".getBytes("UTF-8"));
test_Expect100Continue_Respond100Continue("data1".getBytes(StandardCharsets.UTF_8), "data2".getBytes(StandardCharsets.UTF_8), "data3".getBytes(StandardCharsets.UTF_8));
}
private void test_Expect100Continue_Respond100Continue(byte[]... contents) throws Exception

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.client;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.ServletException;
@ -83,7 +84,7 @@ public class HttpClientProxyTest extends AbstractHttpClientServerTest
{
final String user = "foo";
final String password = "bar";
final String credentials = B64Code.encode(user + ":" + password, "ISO-8859-1");
final String credentials = B64Code.encode(user + ":" + password, StandardCharsets.ISO_8859_1);
final String serverHost = "server";
final String realm = "test_realm";
final int status = HttpStatus.NO_CONTENT_204;

View File

@ -25,6 +25,7 @@ import java.net.URI;
import java.net.URLEncoder;
import java.nio.ByteBuffer;
import java.nio.channels.UnresolvedAddressException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@ -171,10 +172,10 @@ public class HttpClientTest extends AbstractHttpClientServerTest
response.setCharacterEncoding("UTF-8");
ServletOutputStream output = response.getOutputStream();
String paramValue1 = request.getParameter(paramName1);
output.write(paramValue1.getBytes("UTF-8"));
output.write(paramValue1.getBytes(StandardCharsets.UTF_8));
String paramValue2 = request.getParameter(paramName2);
Assert.assertEquals("", paramValue2);
output.write("empty".getBytes("UTF-8"));
output.write("empty".getBytes(StandardCharsets.UTF_8));
baseRequest.setHandled(true);
}
});
@ -186,7 +187,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
String content = new String(response.getContent(), "UTF-8");
String content = new String(response.getContent(), StandardCharsets.UTF_8);
Assert.assertEquals(value1 + "empty", content);
}
@ -204,9 +205,9 @@ public class HttpClientTest extends AbstractHttpClientServerTest
ServletOutputStream output = response.getOutputStream();
String[] paramValues1 = request.getParameterValues(paramName1);
for (String paramValue : paramValues1)
output.write(paramValue.getBytes("UTF-8"));
output.write(paramValue.getBytes(StandardCharsets.UTF_8));
String paramValue2 = request.getParameter(paramName2);
output.write(paramValue2.getBytes("UTF-8"));
output.write(paramValue2.getBytes(StandardCharsets.UTF_8));
baseRequest.setHandled(true);
}
});
@ -222,7 +223,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
String content = new String(response.getContent(), "UTF-8");
String content = new String(response.getContent(), StandardCharsets.UTF_8);
Assert.assertEquals(value11 + value12 + value2, content);
}
@ -254,7 +255,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(paramValue, new String(response.getContent(), "UTF-8"));
Assert.assertEquals(paramValue, new String(response.getContent(), StandardCharsets.UTF_8));
}
@Test
@ -286,7 +287,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(paramValue, new String(response.getContent(), "UTF-8"));
Assert.assertEquals(paramValue, new String(response.getContent(), StandardCharsets.UTF_8));
}
@Test

View File

@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@ -126,7 +127,7 @@ public class HttpReceiverTest
Assert.assertNotNull(headers);
Assert.assertEquals(1, headers.size());
Assert.assertEquals(String.valueOf(content.length()), headers.get(HttpHeader.CONTENT_LENGTH));
String received = listener.getContentAsString("UTF-8");
String received = listener.getContentAsString(StandardCharsets.UTF_8);
Assert.assertEquals(content, received);
}

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.client;
import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@ -191,7 +192,7 @@ public class HttpSenderTest
HttpConnection connection = new HttpConnection(client, endPoint, destination);
Request request = client.newRequest(URI.create("http://localhost/"));
String content = "abcdef";
request.content(new ByteBufferContentProvider(ByteBuffer.wrap(content.getBytes("UTF-8"))));
request.content(new ByteBufferContentProvider(ByteBuffer.wrap(content.getBytes(StandardCharsets.UTF_8))));
final CountDownLatch headersLatch = new CountDownLatch(1);
final CountDownLatch successLatch = new CountDownLatch(1);
request.listener(new Request.Listener.Empty()
@ -226,7 +227,7 @@ public class HttpSenderTest
Request request = client.newRequest(URI.create("http://localhost/"));
String content1 = "0123456789";
String content2 = "abcdef";
request.content(new ByteBufferContentProvider(ByteBuffer.wrap(content1.getBytes("UTF-8")), ByteBuffer.wrap(content2.getBytes("UTF-8"))));
request.content(new ByteBufferContentProvider(ByteBuffer.wrap(content1.getBytes(StandardCharsets.UTF_8)), ByteBuffer.wrap(content2.getBytes(StandardCharsets.UTF_8))));
final CountDownLatch headersLatch = new CountDownLatch(1);
final CountDownLatch successLatch = new CountDownLatch(1);
request.listener(new Request.Listener.Empty()
@ -261,7 +262,7 @@ public class HttpSenderTest
Request request = client.newRequest(URI.create("http://localhost/"));
String content1 = "0123456789";
String content2 = "ABCDEF";
request.content(new ByteBufferContentProvider(ByteBuffer.wrap(content1.getBytes("UTF-8")), ByteBuffer.wrap(content2.getBytes("UTF-8")))
request.content(new ByteBufferContentProvider(ByteBuffer.wrap(content1.getBytes(StandardCharsets.UTF_8)), ByteBuffer.wrap(content2.getBytes(StandardCharsets.UTF_8)))
{
@Override
public long getLength()

View File

@ -24,6 +24,7 @@ import java.io.OutputStream;
import java.net.HttpCookie;
import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@ -269,7 +270,7 @@ public class Usage
HttpClient client = new HttpClient();
client.start();
InputStream input = new ByteArrayInputStream("content".getBytes("UTF-8"));
InputStream input = new ByteArrayInputStream("content".getBytes(StandardCharsets.UTF_8));
ContentResponse response = client.newRequest("localhost", 8080)
// Provide the content as InputStream

View File

@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.SocketTimeoutException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
@ -151,7 +152,7 @@ public class SslBytesClientTest extends SslBytesTest
SimpleProxy.AutomaticFlow automaticProxyFlow = proxy.startAutomaticFlow();
// Read request
BufferedReader reader = new BufferedReader(new InputStreamReader(server.getInputStream(), "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(server.getInputStream(), StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.startsWith("GET"));
while (line.length() > 0)
@ -161,7 +162,7 @@ public class SslBytesClientTest extends SslBytesTest
OutputStream output = server.getOutputStream();
output.write(("HTTP/1.1 200 OK\r\n" +
"Content-Length: 0\r\n" +
"\r\n").getBytes("UTF-8"));
"\r\n").getBytes(StandardCharsets.UTF_8));
output.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
@ -197,7 +198,7 @@ public class SslBytesClientTest extends SslBytesTest
// Read request
InputStream serverInput = server.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(serverInput, "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(serverInput, StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.startsWith("GET"));
while (line.length() > 0)
@ -206,16 +207,16 @@ public class SslBytesClientTest extends SslBytesTest
OutputStream serverOutput = server.getOutputStream();
byte[] data1 = new byte[1024];
Arrays.fill(data1, (byte)'X');
String content1 = new String(data1, "UTF-8");
String content1 = new String(data1, StandardCharsets.UTF_8);
byte[] data2 = new byte[1024];
Arrays.fill(data2, (byte)'Y');
final String content2 = new String(data2, "UTF-8");
final String content2 = new String(data2, StandardCharsets.UTF_8);
// Write first part of the response
serverOutput.write(("HTTP/1.1 200 OK\r\n" +
"Content-Type: text/plain\r\n" +
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
"\r\n" +
content1).getBytes("UTF-8"));
content1).getBytes(StandardCharsets.UTF_8));
serverOutput.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
@ -319,7 +320,7 @@ public class SslBytesClientTest extends SslBytesTest
// Read request
InputStream serverInput = server.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(serverInput, "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(serverInput, StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.startsWith("GET"));
while (line.length() > 0)
@ -328,16 +329,16 @@ public class SslBytesClientTest extends SslBytesTest
OutputStream serverOutput = server.getOutputStream();
byte[] data1 = new byte[1024];
Arrays.fill(data1, (byte)'X');
String content1 = new String(data1, "UTF-8");
String content1 = new String(data1, StandardCharsets.UTF_8);
byte[] data2 = new byte[1024];
Arrays.fill(data2, (byte)'Y');
final String content2 = new String(data2, "UTF-8");
final String content2 = new String(data2, StandardCharsets.UTF_8);
// Write first part of the response
serverOutput.write(("HTTP/1.1 200 OK\r\n" +
"Content-Type: text/plain\r\n" +
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
"\r\n" +
content1).getBytes("UTF-8"));
content1).getBytes(StandardCharsets.UTF_8));
serverOutput.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));

View File

@ -28,6 +28,7 @@ import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
@ -575,7 +576,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n").getBytes("UTF-8"));
"\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@ -617,7 +618,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n").getBytes("UTF-8"));
"\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@ -633,7 +634,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record);
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@ -710,7 +711,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n").getBytes("UTF-8"));
"\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@ -727,7 +728,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record);
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@ -782,7 +783,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n").getBytes("UTF-8"));
"\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@ -850,7 +851,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n").getBytes("UTF-8"));
"\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@ -913,7 +914,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n").getBytes("UTF-8"));
"\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@ -964,7 +965,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n").getBytes("UTF-8"));
"\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@ -1007,7 +1008,7 @@ public class SslBytesServerTest extends SslBytesTest
byte[] data = new byte[128 * 1024];
Arrays.fill(data, (byte)'X');
final String content = new String(data, "UTF-8");
final String content = new String(data, StandardCharsets.UTF_8);
Future<Object> request = threadPool.submit(new Callable<Object>()
{
@Override
@ -1019,7 +1020,7 @@ public class SslBytesServerTest extends SslBytesTest
"Host: localhost\r\n" +
"Content-Length: " + content.length() + "\r\n" +
"\r\n" +
content).getBytes("UTF-8"));
content).getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@ -1065,7 +1066,7 @@ public class SslBytesServerTest extends SslBytesTest
byte[] data = new byte[128 * 1024];
Arrays.fill(data, (byte)'X');
final String content = new String(data, "UTF-8");
final String content = new String(data, StandardCharsets.UTF_8);
Future<Object> request = threadPool.submit(new Callable<Object>()
{
@Override
@ -1077,7 +1078,7 @@ public class SslBytesServerTest extends SslBytesTest
"Host: localhost\r\n" +
"Content-Length: " + content.length() + "\r\n" +
"\r\n" +
content).getBytes("UTF-8"));
content).getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@ -1139,7 +1140,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n").getBytes("UTF-8"));
"\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@ -1211,7 +1212,7 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Type: text/plain\r\n" +
"Content-Length: " + content.length() + "\r\n" +
"\r\n" +
content).getBytes("UTF-8"));
content).getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@ -1232,7 +1233,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record);
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@ -1263,7 +1264,7 @@ public class SslBytesServerTest extends SslBytesTest
// Use a content that is larger than the TLS record which is 2^14 (around 16k)
byte[] data = new byte[128 * 1024];
Arrays.fill(data, (byte)'X');
final String content = new String(data, "UTF-8");
final String content = new String(data, StandardCharsets.UTF_8);
Future<Object> request = threadPool.submit(new Callable<Object>()
{
@ -1277,7 +1278,7 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Type: text/plain\r\n" +
"Content-Length: " + content.length() + "\r\n" +
"\r\n" +
content).getBytes("UTF-8"));
content).getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@ -1309,7 +1310,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record);
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@ -1344,10 +1345,10 @@ public class SslBytesServerTest extends SslBytesTest
byte[] data1 = new byte[1024];
Arrays.fill(data1, (byte)'X');
String content1 = new String(data1, "UTF-8");
String content1 = new String(data1, StandardCharsets.UTF_8);
byte[] data2 = new byte[1024];
Arrays.fill(data2, (byte)'Y');
final String content2 = new String(data2, "UTF-8");
final String content2 = new String(data2, StandardCharsets.UTF_8);
// Write only part of the body
automaticProxyFlow = proxy.startAutomaticFlow();
@ -1357,7 +1358,7 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Type: text/plain\r\n" +
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
"\r\n" +
content1).getBytes("UTF-8"));
content1).getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
@ -1391,7 +1392,7 @@ public class SslBytesServerTest extends SslBytesTest
@Override
public Object call() throws Exception
{
clientOutput.write(content2.getBytes("UTF-8"));
clientOutput.write(content2.getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@ -1435,10 +1436,10 @@ public class SslBytesServerTest extends SslBytesTest
// Use a content that is larger than the TLS record which is 2^14 (around 16k)
byte[] data1 = new byte[80 * 1024];
Arrays.fill(data1, (byte)'X');
String content1 = new String(data1, "UTF-8");
String content1 = new String(data1, StandardCharsets.UTF_8);
byte[] data2 = new byte[48 * 1024];
Arrays.fill(data2, (byte)'Y');
final String content2 = new String(data2, "UTF-8");
final String content2 = new String(data2, StandardCharsets.UTF_8);
// Write only part of the body
automaticProxyFlow = proxy.startAutomaticFlow();
@ -1448,7 +1449,7 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Type: text/plain\r\n" +
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
"\r\n" +
content1).getBytes("UTF-8"));
content1).getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
@ -1513,7 +1514,7 @@ public class SslBytesServerTest extends SslBytesTest
@Override
public Object call() throws Exception
{
clientOutput.write(content2.getBytes("UTF-8"));
clientOutput.write(content2.getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@ -1535,7 +1536,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record);
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@ -1569,10 +1570,10 @@ public class SslBytesServerTest extends SslBytesTest
// Use a content that is larger than the TLS record which is 2^14 (around 16k)
byte[] data1 = new byte[80 * 1024];
Arrays.fill(data1, (byte)'X');
String content1 = new String(data1, "UTF-8");
String content1 = new String(data1, StandardCharsets.UTF_8);
byte[] data2 = new byte[48 * 1024];
Arrays.fill(data2, (byte)'Y');
final String content2 = new String(data2, "UTF-8");
final String content2 = new String(data2, StandardCharsets.UTF_8);
// Write only part of the body
automaticProxyFlow = proxy.startAutomaticFlow();
@ -1582,7 +1583,7 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Type: text/plain\r\n" +
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
"\r\n" +
content1).getBytes("UTF-8"));
content1).getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
@ -1665,7 +1666,7 @@ public class SslBytesServerTest extends SslBytesTest
@Override
public Object call() throws Exception
{
clientOutput.write(content2.getBytes("UTF-8"));
clientOutput.write(content2.getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@ -1697,7 +1698,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record);
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@ -1728,7 +1729,7 @@ public class SslBytesServerTest extends SslBytesTest
byte[] data = new byte[3 * 1024];
Arrays.fill(data, (byte)'Y');
String content = new String(data, "UTF-8");
String content = new String(data, StandardCharsets.UTF_8);
automaticProxyFlow = proxy.startAutomaticFlow();
clientOutput.write(("" +
"POST / HTTP/1.1\r\n" +
@ -1737,10 +1738,10 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Length: " + content.length() + "\r\n" +
"Connection: close\r\n" +
"\r\n" +
content).getBytes("UTF-8"));
content).getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@ -1786,7 +1787,7 @@ public class SslBytesServerTest extends SslBytesTest
});
// Instead of passing the Client Hello, we simulate plain text was passed in
proxy.flushToServer(0, "GET / HTTP/1.1\r\n".getBytes("UTF-8"));
proxy.flushToServer(0, "GET / HTTP/1.1\r\n".getBytes(StandardCharsets.UTF_8));
// We expect that the server closes the connection immediately
TLSRecord record = proxy.readFromServer();
@ -1820,7 +1821,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n").getBytes("UTF-8"));
"\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
latch.countDown();
}

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.http;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;
@ -176,7 +177,7 @@ public class HttpField
private static byte[] toSanitisedName(String s)
{
byte[] bytes = s.getBytes(StringUtil.__ISO_8859_1_CHARSET);
byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
for (int i=bytes.length;i-->0;)
{
switch(bytes[i])
@ -192,7 +193,7 @@ public class HttpField
private static byte[] toSanitisedValue(String s)
{
byte[] bytes = s.getBytes(StringUtil.__ISO_8859_1_CHARSET);
byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
for (int i=bytes.length;i-->0;)
{
switch(bytes[i])

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.http;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.http.HttpTokens.EndOfContent;
import org.eclipse.jetty.util.ArrayTernaryTrie;
@ -969,12 +970,12 @@ public class HttpParser
// Have to get the fields exactly from the buffer to match case
String fn=field.getName();
String fv=field.getValue();
n=BufferUtil.toString(buffer,buffer.position()-1,fn.length(),StringUtil.__US_ASCII_CHARSET);
n=BufferUtil.toString(buffer,buffer.position()-1,fn.length(),StandardCharsets.US_ASCII);
if (fv==null)
v=null;
else
{
v=BufferUtil.toString(buffer,buffer.position()+fn.length()+1,fv.length(),StringUtil.__ISO_8859_1_CHARSET);
v=BufferUtil.toString(buffer,buffer.position()+fn.length()+1,fv.length(),StandardCharsets.ISO_8859_1);
field=new HttpField(field.getHeader(),n,v);
}
}

View File

@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.http.HttpGenerator.RequestInfo;
import org.eclipse.jetty.http.HttpGenerator.ResponseInfo;
@ -346,7 +347,7 @@ public class HttpTester
String content_type=get(HttpHeader.CONTENT_TYPE);
String encoding=MimeTypes.getCharsetFromContentType(content_type);
Charset charset=encoding==null?StringUtil.__UTF8_CHARSET:Charset.forName(encoding);
Charset charset=encoding==null?StandardCharsets.UTF_8:Charset.forName(encoding);
return new String(bytes,charset);
}

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.http;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.MultiMap;
import org.eclipse.jetty.util.StringUtil;
@ -100,15 +101,7 @@ public class HttpURI
public HttpURI(String raw)
{
_rawString=raw;
byte[] b;
try
{
b = raw.getBytes(StringUtil.__UTF8);
}
catch (UnsupportedEncodingException e)
{
throw new RuntimeException(e.getMessage());
}
byte[] b = raw.getBytes(StandardCharsets.UTF_8);
parse(b,0,b.length);
_charset = URIUtil.__CHARSET;
}
@ -617,8 +610,13 @@ public class HttpURI
return StringUtil.toUTF8String(_raw, _path, _param-_path);
return utf8b.toString();
}
public String getDecodedPath(String encoding)
{
return getDecodedPath(Charset.forName(encoding));
}
public String getDecodedPath(Charset encoding)
{
if (_path==_param)
return null;
@ -678,9 +676,9 @@ public class HttpURI
if (bytes==null)
return StringUtil.toString(_raw,_path,_param-_path,encoding);
return new String(_raw,_path,_param-_path,encoding);
return StringUtil.toString(bytes,0,n,encoding);
return new String(bytes,0,n,encoding);
}
public String getPathAndParam()
@ -734,10 +732,10 @@ public class HttpURI
{
if (_query==_fragment)
return;
if (_charset==StringUtil.__UTF8_CHARSET)
if (_charset.equals(StandardCharsets.UTF_8))
UrlEncoded.decodeUtf8To(_raw,_query+1,_fragment-_query-1,parameters);
else
UrlEncoded.decodeTo(StringUtil.toString(_raw,_query+1,_fragment-_query-1,_charset.toString()),parameters,_charset.toString(),-1);
UrlEncoded.decodeTo(new String(_raw,_query+1,_fragment-_query-1,_charset),parameters,_charset,-1);
}
public void decodeQueryTo(MultiMap<String> parameters, String encoding) throws UnsupportedEncodingException
@ -751,6 +749,17 @@ public class HttpURI
UrlEncoded.decodeTo(StringUtil.toString(_raw,_query+1,_fragment-_query-1,encoding),parameters,encoding,-1);
}
public void decodeQueryTo(MultiMap<String> parameters, Charset encoding) throws UnsupportedEncodingException
{
if (_query==_fragment)
return;
if (encoding==null || StandardCharsets.UTF_8.equals(encoding))
UrlEncoded.decodeUtf8To(_raw,_query+1,_fragment-_query-1,parameters);
else
UrlEncoded.decodeTo(new String(_raw,_query+1,_fragment-_query-1,encoding),parameters,encoding,-1);
}
public void clear()
{
_scheme=_authority=_host=_port=_path=_param=_query=_fragment=_end=0;

View File

@ -24,6 +24,7 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@ -112,7 +113,7 @@ public class HttpParserTest
@Test
public void testLineParse3() throws Exception
{
ByteBuffer buffer= BufferUtil.toBuffer("POST /fo\u0690 HTTP/1.0\015\012" + "\015\012",StringUtil.__UTF8_CHARSET);
ByteBuffer buffer= BufferUtil.toBuffer("POST /fo\u0690 HTTP/1.0\015\012" + "\015\012",StandardCharsets.UTF_8);
HttpParser.RequestHandler<ByteBuffer> handler = new Handler();
HttpParser parser= new HttpParser(handler);
@ -126,7 +127,7 @@ public class HttpParserTest
@Test
public void testLineParse4() throws Exception
{
ByteBuffer buffer= BufferUtil.toBuffer("POST /foo?param=\u0690 HTTP/1.0\015\012" + "\015\012",StringUtil.__UTF8_CHARSET);
ByteBuffer buffer= BufferUtil.toBuffer("POST /foo?param=\u0690 HTTP/1.0\015\012" + "\015\012",StandardCharsets.UTF_8);
HttpParser.RequestHandler<ByteBuffer> handler = new Handler();
HttpParser parser= new HttpParser(handler);
@ -321,10 +322,10 @@ public class HttpParserTest
ByteBuffer buffer=BufferUtil.allocate(4096);
BufferUtil.flipToFill(buffer);
BufferUtil.put(BufferUtil.toBuffer("GET "),buffer);
buffer.put("/foo/\u0690/".getBytes(StringUtil.__UTF8_CHARSET));
buffer.put("/foo/\u0690/".getBytes(StandardCharsets.UTF_8));
BufferUtil.put(BufferUtil.toBuffer(" HTTP/1.0\r\n"),buffer);
BufferUtil.put(BufferUtil.toBuffer("Header1: "),buffer);
buffer.put("\u00e6 \u00e6".getBytes(StringUtil.__ISO_8859_1_CHARSET));
buffer.put("\u00e6 \u00e6".getBytes(StandardCharsets.ISO_8859_1));
BufferUtil.put(BufferUtil.toBuffer(" \r\n\r\n"),buffer);
BufferUtil.flipToFlush(buffer,0);
@ -1165,7 +1166,7 @@ public class HttpParserTest
{
if (_content==null)
_content="";
String c = BufferUtil.toString(ref,StringUtil.__UTF8_CHARSET);
String c = BufferUtil.toString(ref,StandardCharsets.UTF_8);
//System.err.println("content '"+c+"'");
_content= _content + c;
ref.position(ref.limit());

View File

@ -23,6 +23,7 @@ import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
@ -153,7 +154,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint
/* ------------------------------------------------------------ */
public void setInput(String s)
{
setInput(BufferUtil.toBuffer(s,StringUtil.__UTF8_CHARSET));
setInput(BufferUtil.toBuffer(s,StandardCharsets.UTF_8));
}
/* ------------------------------------------------------------ */
@ -177,7 +178,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint
*/
public String getOutputString()
{
return getOutputString(StringUtil.__UTF8_CHARSET);
return getOutputString(StandardCharsets.UTF_8);
}
/* ------------------------------------------------------------ */
@ -207,7 +208,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint
*/
public String takeOutputString()
{
return takeOutputString(StringUtil.__UTF8_CHARSET);
return takeOutputString(StandardCharsets.UTF_8);
}
/* ------------------------------------------------------------ */

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.io;
import java.io.Closeable;
import org.eclipse.jetty.util.Callback;
/**
@ -28,7 +30,7 @@ import org.eclipse.jetty.util.Callback;
* and when the {@link EndPoint} signals read readyness, this {@link Connection} can
* read bytes from the network and interpret them.</p>
*/
public interface Connection extends AutoCloseable
public interface Connection extends Closeable
{
public void addListener(Listener listener);

View File

@ -25,8 +25,6 @@ import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.nio.channels.CancelledKeyException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.ClosedSelectorException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
@ -229,7 +227,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
{
connection.onOpen();
}
catch (Exception x)
catch (Throwable x)
{
if (isRunning())
LOG.warn("Exception while notifying connection " + connection, x);
@ -249,9 +247,9 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
{
connection.onClose();
}
catch (Exception x)
catch (Throwable x)
{
LOG.info("Exception while notifying connection " + connection, x);
LOG.debug("Exception while notifying connection " + connection, x);
}
}
@ -406,8 +404,15 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
protected void runChange(Runnable change)
{
LOG.debug("Running change {}", change);
change.run();
try
{
LOG.debug("Running change {}", change);
change.run();
}
catch (Throwable x)
{
LOG.debug("Could not run change " + change, x);
}
}
@Override
@ -468,7 +473,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
}
selectedKeys.clear();
}
catch (Exception x)
catch (Throwable x)
{
if (isRunning())
LOG.warn(x);
@ -515,7 +520,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
if (attachment instanceof EndPoint)
((EndPoint)attachment).close();
}
catch (Exception x)
catch (Throwable x)
{
LOG.warn("Could not process key for channel " + key.channel(), x);
if (attachment instanceof EndPoint)
@ -525,10 +530,10 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
private void processConnect(SelectionKey key, Connect connect)
{
key.attach(connect.attachment);
SocketChannel channel = (SocketChannel)key.channel();
try
{
key.attach(connect.attachment);
boolean connected = finishConnect(channel);
if (connected)
{
@ -542,10 +547,9 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
throw new ConnectException();
}
}
catch (Exception x)
catch (Throwable x)
{
connect.failed(x);
closeNoExceptions(channel);
}
}
@ -555,7 +559,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
{
closeable.close();
}
catch (IOException x)
catch (Throwable x)
{
LOG.ignore(x);
}
@ -702,8 +706,9 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
EndPoint endpoint = createEndPoint(_channel, key);
key.attach(endpoint);
}
catch (IOException x)
catch (Throwable x)
{
closeNoExceptions(_channel);
LOG.debug(x);
}
}
@ -730,16 +735,20 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
{
channel.register(_selector, SelectionKey.OP_CONNECT, this);
}
catch (ClosedSelectorException | ClosedChannelException x)
catch (Throwable x)
{
LOG.debug(x);
failed(x);
}
}
protected void failed(Throwable failure)
{
if (failed.compareAndSet(false, true))
{
timeout.cancel();
closeNoExceptions(channel);
connectionFailed(channel, failure, attachment);
}
}
}
@ -759,19 +768,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
if (channel.isConnectionPending())
{
LOG.debug("Channel {} timed out while connecting, closing it", channel);
try
{
// This will unregister the channel from the selector
channel.close();
}
catch (IOException x)
{
LOG.ignore(x);
}
finally
{
connect.failed(new SocketTimeoutException());
}
connect.failed(new SocketTimeoutException());
}
}
}
@ -836,7 +833,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
{
try
{
endPoint.getConnection().close();
closeNoExceptions(endPoint.getConnection());
}
finally
{

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.io;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import java.nio.charset.Charset;
/* ------------------------------------------------------------ */
@ -33,14 +34,14 @@ import java.io.Writer;
public class WriterOutputStream extends OutputStream
{
protected final Writer _writer;
protected final String _encoding;
protected final Charset _encoding;
private final byte[] _buf=new byte[1];
/* ------------------------------------------------------------ */
public WriterOutputStream(Writer writer, String encoding)
{
_writer=writer;
_encoding=encoding;
_encoding=encoding==null?null:Charset.forName(encoding);
}
/* ------------------------------------------------------------ */

View File

@ -26,14 +26,17 @@ import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@ -389,42 +392,40 @@ public class IOTest
@Test
public void testReset() throws Exception
{
ServerSocket connector;
Socket client;
Socket server;
try (ServerSocket connector = new ServerSocket(0);
Socket client = new Socket("127.0.0.1", connector.getLocalPort());
Socket server = connector.accept();)
{
client.setTcpNoDelay(true);
client.setSoLinger(true, 0);
server.setTcpNoDelay(true);
server.setSoLinger(true, 0);
connector = new ServerSocket(0);
client = new Socket("127.0.0.1", connector.getLocalPort());
server = connector.accept();
client.setTcpNoDelay(true);
client.setSoLinger(true, 0);
server.setTcpNoDelay(true);
server.setSoLinger(true, 0);
client.getOutputStream().write(1);
assertEquals(1, server.getInputStream().read());
server.getOutputStream().write(1);
assertEquals(1, client.getInputStream().read());
client.getOutputStream().write(1);
assertEquals(1, server.getInputStream().read());
server.getOutputStream().write(1);
assertEquals(1, client.getInputStream().read());
// Server generator shutdowns output after non persistent sending response.
server.shutdownOutput();
// Server generator shutdowns output after non persistent sending response.
server.shutdownOutput();
// client endpoint reads EOF and shutdown input as result
assertEquals(-1, client.getInputStream().read());
client.shutdownInput();
// client endpoint reads EOF and shutdown input as result
assertEquals(-1, client.getInputStream().read());
client.shutdownInput();
// client connection see's EOF and shutsdown output as no more requests to be sent.
client.shutdownOutput();
// client connection see's EOF and shutsdown output as no more requests to be sent.
client.shutdownOutput();
// Since input already shutdown, client also closes socket.
client.close();
// Since input already shutdown, client also closes socket.
client.close();
// Server reads the EOF from client oshut and shut's down it's input
assertEquals(-1, server.getInputStream().read());
server.shutdownInput();
// Server reads the EOF from client oshut and shut's down it's input
assertEquals(-1, server.getInputStream().read());
server.shutdownInput();
// Since output was already shutdown, server closes
server.close();
// Since output was already shutdown, server closes
server.close();
}
}
@Test
@ -432,17 +433,19 @@ public class IOTest
{
AsynchronousServerSocketChannel connector = AsynchronousServerSocketChannel.open();
connector.bind(null);
InetSocketAddress addr=(InetSocketAddress)connector.getLocalAddress();
Future<AsynchronousSocketChannel> acceptor = connector.accept();
AsynchronousSocketChannel client = AsynchronousSocketChannel.open();
client.connect(connector.getLocalAddress()).get(5, TimeUnit.SECONDS);
client.connect(new InetSocketAddress("127.0.0.1",addr.getPort())).get(5, TimeUnit.SECONDS);
AsynchronousSocketChannel server = acceptor.get(5, TimeUnit.SECONDS);
ByteBuffer read = ByteBuffer.allocate(1024);
Future<Integer> reading = server.read(read);
byte[] data = "Testing 1 2 3".getBytes("UTF-8");
byte[] data = "Testing 1 2 3".getBytes(StandardCharsets.UTF_8);
ByteBuffer write = BufferUtil.toBuffer(data);
Future<Integer> writing = client.write(write);

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLEngineResult;
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
@ -170,7 +171,7 @@ public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest
if (debug) System.err.println("\nSay Hello");
// write a message
appOut.put("HelloWorld".getBytes("UTF-8"));
appOut.put("HelloWorld".getBytes(StandardCharsets.UTF_8));
appOut.flip();
SSLEngineResult result =engine.wrap(appOut,sslOut);
if (debug) System.err.println(result);

View File

@ -29,6 +29,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@ -228,7 +229,7 @@ public class SelectChannelEndPointTest
_manager.accept(server);
// Write client to server
client.getOutputStream().write("HelloWorld".getBytes("UTF-8"));
client.getOutputStream().write("HelloWorld".getBytes(StandardCharsets.UTF_8));
// Verify echo server to client
for (char c : "HelloWorld".toCharArray())
@ -253,7 +254,7 @@ public class SelectChannelEndPointTest
}
// write then shutdown
client.getOutputStream().write("Goodbye Cruel TLS".getBytes("UTF-8"));
client.getOutputStream().write("Goodbye Cruel TLS".getBytes(StandardCharsets.UTF_8));
// Verify echo server to client
for (char c : "Goodbye Cruel TLS".toCharArray())
@ -287,7 +288,7 @@ public class SelectChannelEndPointTest
_manager.accept(server);
// Write client to server
client.getOutputStream().write("HelloWorld".getBytes("UTF-8"));
client.getOutputStream().write("HelloWorld".getBytes(StandardCharsets.UTF_8));
// Verify echo server to client
for (char c : "HelloWorld".toCharArray())
@ -310,7 +311,7 @@ public class SelectChannelEndPointTest
}
// write then shutdown
client.getOutputStream().write("Goodbye Cruel TLS".getBytes("UTF-8"));
client.getOutputStream().write("Goodbye Cruel TLS".getBytes(StandardCharsets.UTF_8));
client.shutdownOutput();
// Verify echo server to client
@ -343,7 +344,7 @@ public class SelectChannelEndPointTest
// Write 8 and cause block waiting for 10
_blockAt = 10;
clientOutputStream.write("12345678".getBytes("UTF-8"));
clientOutputStream.write("12345678".getBytes(StandardCharsets.UTF_8));
clientOutputStream.flush();
Assert.assertTrue(_lastEndPointLatch.await(1, TimeUnit.SECONDS));
@ -363,7 +364,7 @@ public class SelectChannelEndPointTest
}
// write remaining characters
clientOutputStream.write("90ABCDEF".getBytes("UTF-8"));
clientOutputStream.write("90ABCDEF".getBytes(StandardCharsets.UTF_8));
clientOutputStream.flush();
// Verify echo server to client
@ -388,7 +389,7 @@ public class SelectChannelEndPointTest
_manager.accept(server);
// Write client to server
client.getOutputStream().write("HelloWorld".getBytes("UTF-8"));
client.getOutputStream().write("HelloWorld".getBytes(StandardCharsets.UTF_8));
// Verify echo server to client
for (char c : "HelloWorld".toCharArray())
@ -436,7 +437,7 @@ public class SelectChannelEndPointTest
_manager.accept(server);
// Write client to server
clientOutputStream.write("HelloWorld".getBytes("UTF-8"));
clientOutputStream.write("HelloWorld".getBytes(StandardCharsets.UTF_8));
// Verify echo server to client
for (char c : "HelloWorld".toCharArray())
@ -452,7 +453,7 @@ public class SelectChannelEndPointTest
// Write 8 and cause block waiting for 10
_blockAt = 10;
clientOutputStream.write("12345678".getBytes("UTF-8"));
clientOutputStream.write("12345678".getBytes(StandardCharsets.UTF_8));
clientOutputStream.flush();
// read until idle shutdown received
@ -493,8 +494,8 @@ public class SelectChannelEndPointTest
_manager.accept(server);
final int writes = 200000;
final byte[] bytes = "HelloWorld-".getBytes(StringUtil.__UTF8_CHARSET);
byte[] count = "0\n".getBytes(StringUtil.__UTF8_CHARSET);
final byte[] bytes = "HelloWorld-".getBytes(StandardCharsets.UTF_8);
byte[] count = "0\n".getBytes(StandardCharsets.UTF_8);
BufferedOutputStream out = new BufferedOutputStream(client.getOutputStream());
final CountDownLatch latch = new CountDownLatch(writes);
final InputStream in = new BufferedInputStream(client.getInputStream());
@ -561,7 +562,7 @@ public class SelectChannelEndPointTest
for (int i = 1; i < writes; i++)
{
out.write(bytes);
out.write(Integer.toString(i).getBytes(StringUtil.__ISO_8859_1_CHARSET));
out.write(Integer.toString(i).getBytes(StandardCharsets.ISO_8859_1));
out.write('\n');
if (i % 1000 == 0)
{
@ -599,7 +600,7 @@ public class SelectChannelEndPointTest
// Write client to server
_writeCount = 10000;
String data = "Now is the time for all good men to come to the aid of the party";
client.getOutputStream().write(data.getBytes("UTF-8"));
client.getOutputStream().write(data.getBytes(StandardCharsets.UTF_8));
BufferedInputStream in = new BufferedInputStream(client.getInputStream());
int byteNum = 0;

View File

@ -27,6 +27,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@ -234,14 +235,14 @@ public class SslConnectionTest
server.configureBlocking(false);
_manager.accept(server);
client.getOutputStream().write("Hello".getBytes("UTF-8"));
client.getOutputStream().write("Hello".getBytes(StandardCharsets.UTF_8));
byte[] buffer = new byte[1024];
int len=client.getInputStream().read(buffer);
Assert.assertEquals(5, len);
Assert.assertEquals("Hello",new String(buffer,0,len,StringUtil.__UTF8_CHARSET));
Assert.assertEquals("Hello",new String(buffer,0,len,StandardCharsets.UTF_8));
_dispatches.set(0);
client.getOutputStream().write("World".getBytes("UTF-8"));
client.getOutputStream().write("World".getBytes(StandardCharsets.UTF_8));
len=5;
while(len>0)
len-=client.getInputStream().read(buffer);
@ -266,7 +267,7 @@ public class SslConnectionTest
byte[] buffer = new byte[1024];
int len=client.getInputStream().read(buffer);
Assert.assertEquals("Hello Client",new String(buffer,0,len,StringUtil.__UTF8_CHARSET));
Assert.assertEquals("Hello Client",new String(buffer,0,len,StandardCharsets.UTF_8));
Assert.assertEquals(null,_writeCallback.get(100,TimeUnit.MILLISECONDS));
client.close();
}
@ -292,7 +293,7 @@ public class SslConnectionTest
{
try
{
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream(),StringUtil.__UTF8_CHARSET));
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream(),StandardCharsets.UTF_8));
while(count.getCount()>0)
{
String line=in.readLine();
@ -311,7 +312,7 @@ public class SslConnectionTest
for (int i=0;i<LINES;i++)
{
client.getOutputStream().write(("HelloWorld "+i+"\n").getBytes("UTF-8"));
client.getOutputStream().write(("HelloWorld "+i+"\n").getBytes(StandardCharsets.UTF_8));
// System.err.println("wrote");
if (i%1000==0)
{

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.security.jaspi.modules;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Set;
@ -119,7 +120,7 @@ public class BaseAuthModule implements ServerAuthModule, ServerAuthContext
throws IOException, UnsupportedCallbackException
{
credentials = credentials.substring(credentials.indexOf(' ')+1);
credentials = B64Code.decode(credentials,StringUtil.__ISO_8859_1);
credentials = B64Code.decode(credentials, StandardCharsets.ISO_8859_1);
int i = credentials.indexOf(':');
String userName = credentials.substring(0,i);
String password = credentials.substring(i+1);

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.security.jaspi.modules;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Map;
@ -306,18 +307,18 @@ public class DigestAuthModule extends BaseAuthModule
else
{
// calc A1 digest
md.update(username.getBytes(StringUtil.__ISO_8859_1));
md.update(username.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(realm.getBytes(StringUtil.__ISO_8859_1));
md.update(realm.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(password.getBytes(StringUtil.__ISO_8859_1));
md.update(password.getBytes(StandardCharsets.ISO_8859_1));
ha1 = md.digest();
}
// calc A2 digest
md.reset();
md.update(method.getBytes(StringUtil.__ISO_8859_1));
md.update(method.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(uri.getBytes(StringUtil.__ISO_8859_1));
md.update(uri.getBytes(StandardCharsets.ISO_8859_1));
byte[] ha2 = md.digest();
// calc digest
@ -327,17 +328,17 @@ public class DigestAuthModule extends BaseAuthModule
// request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2)
// ) > <">
md.update(TypeUtil.toString(ha1, 16).getBytes(StringUtil.__ISO_8859_1));
md.update(TypeUtil.toString(ha1, 16).getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(nonce.getBytes(StringUtil.__ISO_8859_1));
md.update(nonce.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(nc.getBytes(StringUtil.__ISO_8859_1));
md.update(nc.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(cnonce.getBytes(StringUtil.__ISO_8859_1));
md.update(cnonce.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(qop.getBytes(StringUtil.__ISO_8859_1));
md.update(qop.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(TypeUtil.toString(ha2, 16).getBytes(StringUtil.__ISO_8859_1));
md.update(TypeUtil.toString(ha2, 16).getBytes(StandardCharsets.ISO_8859_1));
byte[] digest = md.digest();
// check digest

View File

@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
@ -78,7 +79,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@ -98,7 +99,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
"GET /echo HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@ -121,7 +122,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@ -145,7 +146,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
"Content-Length: 5\r\n" +
"\r\n" +
"HELLO";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);

View File

@ -27,6 +27,7 @@ import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.concurrent.ConcurrentMap;
@ -71,7 +72,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@ -93,7 +94,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@ -104,7 +105,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@ -130,7 +131,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 403 from the CONNECT request
@ -151,7 +152,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 from the CONNECT request
@ -162,7 +163,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@ -188,7 +189,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 403 from the CONNECT request
@ -209,7 +210,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 from the CONNECT request
@ -220,7 +221,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" +
"Host: 127.0.0.1:" + port + "\r\n" +
"\r\n";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@ -245,7 +246,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
return false;
}
String b64 = proxyAuthorization.substring("Basic ".length());
String credentials = B64Code.decode(b64, "UTF-8");
String credentials = B64Code.decode(b64, StandardCharsets.UTF_8);
return "test:test".equals(credentials);
}
};
@ -265,7 +266,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 407 from the CONNECT request
@ -289,7 +290,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 from the CONNECT request
@ -300,7 +301,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@ -342,7 +343,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 500 OK from the CONNECT request
@ -368,7 +369,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@ -379,7 +380,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@ -404,7 +405,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@ -431,7 +432,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@ -444,7 +445,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@ -467,7 +468,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@ -478,7 +479,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@ -506,7 +507,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@ -517,7 +518,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /close HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
int read = input.read();
@ -538,7 +539,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@ -551,7 +552,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"Content-Length: 5\r\n" +
"\r\n" +
"HELLO";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@ -562,7 +563,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@ -585,7 +586,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@ -603,7 +604,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"Content-Length: " + body.length() + "\r\n" +
"\r\n" +
body;
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@ -649,7 +650,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@ -663,7 +664,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"Content-Length: " + body.length() + "\r\n" +
"\r\n" +
body;
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@ -688,7 +689,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
socket.shutdownOutput();
@ -716,7 +717,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@ -727,7 +728,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
socket.shutdownOutput();

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.rewrite.handler;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.util.MultiMap;
@ -87,7 +88,7 @@ public class RewriteRegexRuleTest extends AbstractRuleTestCase
if (test[5]!=null)
{
MultiMap<String> params=new MultiMap<String>();
UrlEncoded.decodeTo(test[5],params,StringUtil.__UTF8_CHARSET,-1);
UrlEncoded.decodeTo(test[5],params, StandardCharsets.UTF_8,-1);
for (String n:params.keySet())
assertEquals(params.getString(n),_request.getParameter(n));

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.security.authentication;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
@ -82,7 +83,7 @@ public class BasicAuthenticator extends LoginAuthenticator
if ("basic".equalsIgnoreCase(method))
{
credentials = credentials.substring(space+1);
credentials = B64Code.decode(credentials,StringUtil.__ISO_8859_1);
credentials = B64Code.decode(credentials, StandardCharsets.ISO_8859_1);
int i = credentials.indexOf(':');
if (i>0)
{

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.security.authentication;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.BitSet;
@ -367,18 +368,18 @@ public class DigestAuthenticator extends LoginAuthenticator
else
{
// calc A1 digest
md.update(username.getBytes(StringUtil.__ISO_8859_1));
md.update(username.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(realm.getBytes(StringUtil.__ISO_8859_1));
md.update(realm.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(password.getBytes(StringUtil.__ISO_8859_1));
md.update(password.getBytes(StandardCharsets.ISO_8859_1));
ha1 = md.digest();
}
// calc A2 digest
md.reset();
md.update(method.getBytes(StringUtil.__ISO_8859_1));
md.update(method.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(uri.getBytes(StringUtil.__ISO_8859_1));
md.update(uri.getBytes(StandardCharsets.ISO_8859_1));
byte[] ha2 = md.digest();
// calc digest
@ -388,17 +389,17 @@ public class DigestAuthenticator extends LoginAuthenticator
// request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2)
// ) > <">
md.update(TypeUtil.toString(ha1, 16).getBytes(StringUtil.__ISO_8859_1));
md.update(TypeUtil.toString(ha1, 16).getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(nonce.getBytes(StringUtil.__ISO_8859_1));
md.update(nonce.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(nc.getBytes(StringUtil.__ISO_8859_1));
md.update(nc.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(cnonce.getBytes(StringUtil.__ISO_8859_1));
md.update(cnonce.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(qop.getBytes(StringUtil.__ISO_8859_1));
md.update(qop.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(TypeUtil.toString(ha2, 16).getBytes(StringUtil.__ISO_8859_1));
md.update(TypeUtil.toString(ha2, 16).getBytes(StandardCharsets.ISO_8859_1));
byte[] digest = md.digest();
// check digest

View File

@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.matchers.JUnitMatchers.containsString;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Arrays;
@ -334,17 +335,17 @@ public class ConstraintTest
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] ha1;
// calc A1 digest
md.update(username.getBytes(StringUtil.__ISO_8859_1));
md.update(username.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update("TestRealm".getBytes(StringUtil.__ISO_8859_1));
md.update("TestRealm".getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(password.getBytes(StringUtil.__ISO_8859_1));
md.update(password.getBytes(StandardCharsets.ISO_8859_1));
ha1 = md.digest();
// calc A2 digest
md.reset();
md.update("GET".getBytes(StringUtil.__ISO_8859_1));
md.update("GET".getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(uri.getBytes(StringUtil.__ISO_8859_1));
md.update(uri.getBytes(StandardCharsets.ISO_8859_1));
byte[] ha2 = md.digest();
// calc digest
@ -354,17 +355,17 @@ public class ConstraintTest
// request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2)
// ) > <">
md.update(TypeUtil.toString(ha1, 16).getBytes(StringUtil.__ISO_8859_1));
md.update(TypeUtil.toString(ha1, 16).getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(nonce.getBytes(StringUtil.__ISO_8859_1));
md.update(nonce.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(nc.getBytes(StringUtil.__ISO_8859_1));
md.update(nc.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(CNONCE.getBytes(StringUtil.__ISO_8859_1));
md.update(CNONCE.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update("auth".getBytes(StringUtil.__ISO_8859_1));
md.update("auth".getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
md.update(TypeUtil.toString(ha2, 16).getBytes(StringUtil.__ISO_8859_1));
md.update(TypeUtil.toString(ha2, 16).getBytes(StandardCharsets.ISO_8859_1));
byte[] digest = md.digest();
// check digest

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@ -373,9 +374,12 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
{
try
{
_request.setAttribute(RequestDispatcher.ERROR_EXCEPTION,x);
_request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE,x.getClass());
if (_state.isSuspended())
{
HttpFields fields = new HttpFields();
fields.add(HttpHeader.CONNECTION,HttpHeaderValue.CLOSE);
ResponseInfo info = new ResponseInfo(_request.getHttpVersion(), fields, 0, HttpStatus.INTERNAL_SERVER_ERROR_500, null, _request.isHead());
boolean committed = sendResponse(info, null, true);
if (!committed)
@ -389,8 +393,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
}
else
{
_request.setAttribute(RequestDispatcher.ERROR_EXCEPTION,x);
_request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE,x.getClass());
_response.setHeader(HttpHeader.CONNECTION.asString(),HttpHeaderValue.CLOSE.asString());
_response.sendError(500, x.getMessage());
}
}
@ -449,7 +452,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
{
LOG.warn("Failed UTF-8 decode for request path, trying ISO-8859-1");
LOG.ignore(e);
path = _uri.getDecodedPath(StringUtil.__ISO_8859_1);
path = _uri.getDecodedPath(StandardCharsets.ISO_8859_1);
}
String info = URIUtil.canonicalPath(path);

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
import java.nio.channels.ClosedChannelException;
import java.util.concurrent.RejectedExecutionException;
@ -91,13 +92,29 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
_config = config;
_connector = connector;
_bufferPool = _connector.getByteBufferPool();
_generator = new HttpGenerator(_config.getSendServerVersion(),_config.getSendXPoweredBy());
_channel = new HttpChannelOverHttp(connector, config, endPoint, this, new Input());
_generator = newHttpGenerator();
HttpInput<ByteBuffer> input = newHttpInput();
_channel = newHttpChannel(input);
_parser = newHttpParser();
LOG.debug("New HTTP Connection {}", this);
}
protected HttpGenerator newHttpGenerator()
{
return new HttpGenerator(_config.getSendServerVersion(),_config.getSendXPoweredBy());
}
protected HttpInput<ByteBuffer> newHttpInput()
{
return new Input();
}
protected HttpChannelOverHttp newHttpChannel(HttpInput<ByteBuffer> httpInput)
{
return new HttpChannelOverHttp(_connector, _config, getEndPoint(), this, httpInput);
}
protected HttpParser newHttpParser()
{
return new HttpParser(newRequestHandler(), getHttpConfiguration().getRequestHeaderSize());
@ -421,7 +438,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
return _requestBuffer;
}
private class Input extends ByteBufferHttpInput
protected class Input extends ByteBufferHttpInput
{
@Override
protected void blockForContent() throws IOException
@ -541,7 +558,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
}
}
private class HttpChannelOverHttp extends HttpChannel<ByteBuffer>
protected class HttpChannelOverHttp extends HttpChannel<ByteBuffer>
{
public HttpChannelOverHttp(Connector connector, HttpConfiguration config, EndPoint endPoint, HttpTransport transport, HttpInput<ByteBuffer> input)
{

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
@ -100,8 +101,8 @@ public class LocalConnector extends AbstractConnector
*/
public String getResponses(String requests,long idleFor,TimeUnit units) throws Exception
{
ByteBuffer result = getResponses(BufferUtil.toBuffer(requests,StringUtil.__UTF8_CHARSET),idleFor,units);
return result==null?null:BufferUtil.toString(result,StringUtil.__UTF8_CHARSET);
ByteBuffer result = getResponses(BufferUtil.toBuffer(requests,StandardCharsets.UTF_8),idleFor,units);
return result==null?null:BufferUtil.toString(result,StandardCharsets.UTF_8);
}
/** Sends requests and get's responses based on thread activity.
@ -150,7 +151,7 @@ public class LocalConnector extends AbstractConnector
*/
public LocalEndPoint executeRequest(String rawRequest)
{
return executeRequest(BufferUtil.toBuffer(rawRequest,StringUtil.__UTF8_CHARSET));
return executeRequest(BufferUtil.toBuffer(rawRequest, StandardCharsets.UTF_8));
}
private LocalEndPoint executeRequest(ByteBuffer rawRequest)
@ -191,7 +192,7 @@ public class LocalConnector extends AbstractConnector
// TODO this is a busy wait
while(getIn()==null || BufferUtil.hasContent(getIn()))
Thread.yield();
setInput(BufferUtil.toBuffer(s, StringUtil.__UTF8_CHARSET));
setInput(BufferUtil.toBuffer(s, StandardCharsets.UTF_8));
}
@Override

View File

@ -18,12 +18,13 @@
package org.eclipse.jetty.server;
import java.io.Closeable;
import java.io.IOException;
/**
* <p>A {@link Connector} for TCP/IP network connectors</p>
*/
public interface NetworkConnector extends Connector, AutoCloseable
public interface NetworkConnector extends Connector, Closeable
{
/**
* <p>Performs the activities needed to open the network communication
@ -39,7 +40,6 @@ public interface NetworkConnector extends Connector, AutoCloseable
* (for example, to stop accepting network connections).</p>
* Once a connector has been closed, it cannot be opened again without first
* calling {@link #stop()} and it will not be active again until a subsequent call to {@link #start()}
* @throws IOException if this connector cannot be closed
*/
@Override
void close();

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.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
import java.security.Principal;
import java.util.ArrayList;
@ -1853,7 +1854,7 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* Set the character encoding used for the query string. This call will effect the return of getQueryString and getParamaters. It must be called before any
* geParameter methods.
* getParameter methods.
*
* The request attribute "org.eclipse.jetty.server.server.Request.queryEncoding" may be set as an alternate method of calling setQueryEncoding.
*
@ -2080,6 +2081,7 @@ public class Request implements HttpServletRequest
setAttribute(__MULTIPART_INPUT_STREAM, _multiPartInputStream);
setAttribute(__MULTIPART_CONTEXT, _context);
Collection<Part> parts = _multiPartInputStream.getParts(); //causes parsing
ByteArrayOutputStream os = null;
for (Part p:parts)
{
MultiPartInputStreamParser.MultiPart mp = (MultiPartInputStreamParser.MultiPart)p;
@ -2090,21 +2092,17 @@ public class Request implements HttpServletRequest
if (mp.getContentType() != null)
charset = MimeTypes.getCharsetFromContentType(mp.getContentType());
ByteArrayOutputStream os = null;
InputStream is = mp.getInputStream(); //get the bytes regardless of being in memory or in temp file
try
//get the bytes regardless of being in memory or in temp file
try (InputStream is = mp.getInputStream())
{
os = new ByteArrayOutputStream();
if (os == null)
os = new ByteArrayOutputStream();
IO.copy(is, os);
String content=new String(os.toByteArray(),charset==null?StringUtil.__UTF8:charset);
String content=new String(os.toByteArray(),charset==null?StandardCharsets.UTF_8:Charset.forName(charset));
getParameter(""); //cause params to be evaluated
getParameters().add(mp.getName(), content);
}
finally
{
IO.close(os);
IO.close(is);
}
os.reset();
}
}
}
@ -2149,7 +2147,7 @@ public class Request implements HttpServletRequest
{
// extract parameters from dispatch query
MultiMap<String> parameters = new MultiMap<>();
UrlEncoded.decodeTo(query,parameters, StringUtil.__UTF8_CHARSET,-1); //have to assume UTF-8 because we can't know otherwise
UrlEncoded.decodeTo(query,parameters, StandardCharsets.UTF_8,-1); //have to assume UTF-8 because we can't know otherwise
boolean merge_old_query = false;
@ -2174,7 +2172,7 @@ public class Request implements HttpServletRequest
MultiMap<String> overridden_new_query = new MultiMap<>();
UrlEncoded.decodeTo(query,overridden_new_query,StringUtil.__UTF8_CHARSET,-1); //have to assume utf8 as we cannot know otherwise
UrlEncoded.decodeTo(query,overridden_new_query,StandardCharsets.UTF_8,-1); //have to assume utf8 as we cannot know otherwise
for(String name: overridden_old_query.keySet())
{

View File

@ -25,6 +25,7 @@ import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
import org.eclipse.jetty.util.StringUtil;
@ -112,7 +113,7 @@ public class ShutdownMonitor
// Reply to client
debug("Informing client that we are stopped.");
out.write("Stopped\r\n".getBytes(StringUtil.__UTF8));
out.write("Stopped\r\n".getBytes(StandardCharsets.UTF_8));
out.flush();
// Shutdown Monitor
@ -131,7 +132,7 @@ public class ShutdownMonitor
else if ("status".equals(cmd))
{
// Reply to client
out.write("OK\r\n".getBytes(StringUtil.__UTF8));
out.write("OK\r\n".getBytes(StandardCharsets.UTF_8));
out.flush();
}
}

View File

@ -28,6 +28,7 @@ import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@ -75,7 +76,7 @@ public abstract class AbstractHttpTest
{
Socket socket = new Socket("localhost", connector.getLocalPort());
socket.setSoTimeout((int)connector.getIdleTimeout());
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
String request = "GET / " + httpVersion + "\r\n";

View File

@ -30,6 +30,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Exchanger;
@ -96,7 +97,7 @@ public class AsyncRequestReadTest
"Content-Length: "+content.length+"\r\n"+
"Content-Type: bytes\r\n"+
"\r\n";
byte[] h=header.getBytes(StringUtil.__ISO_8859_1);
byte[] h=header.getBytes(StandardCharsets.ISO_8859_1);
out.write(h);
out.write(content);
@ -108,7 +109,7 @@ public class AsyncRequestReadTest
"Content-Type: bytes\r\n"+
"Connection: close\r\n"+
"\r\n";
h=header.getBytes(StringUtil.__ISO_8859_1);
h=header.getBytes(StandardCharsets.ISO_8859_1);
out.write(h);
out.write(content);
out.flush();
@ -244,7 +245,7 @@ public class AsyncRequestReadTest
"Content-Length: "+content.length+"\r\n"+
"Content-Type: bytes\r\n"+
"\r\n";
byte[] h=header.getBytes(StringUtil.__ISO_8859_1);
byte[] h=header.getBytes(StandardCharsets.ISO_8859_1);
out.write(h);
out.write(content);
@ -254,7 +255,7 @@ public class AsyncRequestReadTest
"Content-Type: bytes\r\n"+
"Connection: close\r\n"+
"\r\n";
h=header.getBytes(StringUtil.__ISO_8859_1);
h=header.getBytes(StandardCharsets.ISO_8859_1);
out.write(h);
out.write(content);
out.flush();
@ -294,7 +295,7 @@ public class AsyncRequestReadTest
"Content-Length: "+content.length+"\r\n"+
"Content-Type: bytes\r\n"+
"\r\n";
byte[] h=header.getBytes(StringUtil.__ISO_8859_1);
byte[] h=header.getBytes(StandardCharsets.ISO_8859_1);
out.write(h);
out.write(content,0,4096);
out.flush();
@ -329,7 +330,7 @@ public class AsyncRequestReadTest
"Content-Length: "+content.length+"\r\n"+
"Content-Type: bytes\r\n"+
"\r\n";
byte[] h=header.getBytes(StringUtil.__ISO_8859_1);
byte[] h=header.getBytes(StandardCharsets.ISO_8859_1);
out.write(h);
out.write(content,0,4096);
out.flush();

View File

@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
@ -140,7 +141,7 @@ public class AsyncStressTest
"result: "+__paths[p][1]+"\r\n"+
((l+1<loops)?"":"Connection: close\r\n")+
"\r\n";
socket[i].getOutputStream().write(request.getBytes("UTF-8"));
socket[i].getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
socket[i].getOutputStream().flush();
}
if (l%80==0)
@ -155,7 +156,7 @@ public class AsyncStressTest
String[] results=new String[connections];
for (int i=0;i<connections;i++)
{
results[i]=IO.toString(socket[i].getInputStream(),"UTF-8");
results[i]=IO.toString(socket[i].getInputStream(),StandardCharsets.UTF_8);
if (i%80==0)
System.err.println();
System.err.print('-');

View File

@ -24,6 +24,7 @@ import java.io.IOException;
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.AtomicInteger;
@ -91,7 +92,7 @@ public class ConnectionOpenCloseTest extends AbstractHttpTest
"GET / HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"Connection: close\r\n" +
"\r\n").getBytes("UTF-8"));
"\r\n").getBytes(StandardCharsets.UTF_8));
output.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
@ -162,7 +163,7 @@ public class ConnectionOpenCloseTest extends AbstractHttpTest
"GET / HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"Connection: close\r\n" +
"\r\n").getBytes("UTF-8"));
"\r\n").getBytes(StandardCharsets.UTF_8));
output.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));

View File

@ -24,6 +24,7 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.Enumeration;
import javax.servlet.ServletException;
@ -97,7 +98,7 @@ public class DumpHandler extends AbstractHandler
OutputStream out = response.getOutputStream();
ByteArrayOutputStream buf = new ByteArrayOutputStream(2048);
Writer writer = new OutputStreamWriter(buf,StringUtil.__ISO_8859_1);
Writer writer = new OutputStreamWriter(buf,StandardCharsets.ISO_8859_1);
writer.write("<html><h1>"+label+"</h1>");
writer.write("<pre>\npathInfo="+request.getPathInfo()+"\n</pre>\n");
writer.write("<pre>\ncontentType="+request.getContentType()+"\n</pre>\n");

View File

@ -0,0 +1,160 @@
//
// ========================================================================
// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.SelectChannelEndPoint;
import org.eclipse.jetty.io.SelectorManager.ManagedSelector;
import org.eclipse.jetty.server.HttpServerTestFixture.HelloWorldHandler;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.thread.Scheduler;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
/**
* Extended Server Tester.
*/
public class ExtendedServerTest extends HttpServerTestBase
{
@Before
public void init() throws Exception
{
startServer(new ServerConnector(_server,new HttpConnectionFactory()
{
@Override
public Connection newConnection(Connector connector, EndPoint endPoint)
{
return configure(new ExtendedHttpConnection(getHttpConfiguration(), connector, endPoint), connector, endPoint);
}
})
{
@Override
protected SelectChannelEndPoint newEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey key) throws IOException
{
return new ExtendedEndPoint(channel,selectSet,key, getScheduler(), getIdleTimeout());
}
});
}
private static class ExtendedEndPoint extends SelectChannelEndPoint
{
private volatile long _lastSelected;
public ExtendedEndPoint(SocketChannel channel, ManagedSelector selector, SelectionKey key, Scheduler scheduler, long idleTimeout)
{
super(channel,selector,key,scheduler,idleTimeout);
}
@Override
public void onSelected()
{
_lastSelected=System.currentTimeMillis();
super.onSelected();
}
long getLastSelected()
{
return _lastSelected;
}
}
private static class ExtendedHttpConnection extends HttpConnection
{
public ExtendedHttpConnection(HttpConfiguration config, Connector connector, EndPoint endPoint)
{
super(config,connector,endPoint);
}
@Override
protected HttpChannelOverHttp newHttpChannel(HttpInput<ByteBuffer> httpInput)
{
return new HttpChannelOverHttp(getConnector(), getHttpConfiguration(), getEndPoint(), this, httpInput)
{
@Override
public boolean startRequest(HttpMethod httpMethod, String method, ByteBuffer uri, HttpVersion version)
{
getRequest().setAttribute("DispatchedAt",((ExtendedEndPoint)getEndPoint()).getLastSelected());
return super.startRequest(httpMethod,method,uri,version);
}
};
}
}
@Test
public void testExtended() throws Exception
{
configureServer(new DispatchedAtHandler());
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
long start=System.currentTimeMillis();
os.write("GET / HTTP/1.0\r\n".getBytes(StandardCharsets.ISO_8859_1));
os.flush();
Thread.sleep(200);
long end=System.currentTimeMillis();
os.write("\r\n".getBytes(StandardCharsets.ISO_8859_1));
// Read the response.
String response = readResponse(client);
Assert.assertThat(response, Matchers.containsString("HTTP/1.1 200 OK"));
Assert.assertThat(response, Matchers.containsString("DispatchedAt="));
String s=response.substring(response.indexOf("DispatchedAt=")+13);
s=s.substring(0,s.indexOf('\n'));
long dispatched=Long.valueOf(s);
Assert.assertThat(dispatched, Matchers.greaterThanOrEqualTo(start));
Assert.assertThat(dispatched, Matchers.lessThan(end));
}
}
protected static class DispatchedAtHandler extends AbstractHandler
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
baseRequest.setHandled(true);
response.setStatus(200);
response.getOutputStream().print("DispatchedAt="+request.getAttribute("DispatchedAt")+"\r\n");
}
}
}

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
import java.io.IOException;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
@ -76,7 +77,7 @@ public class GracefulStopTest
try(Socket socket = new Socket("localhost",server.getBean(NetworkConnector.class).getLocalPort());)
{
socket.getOutputStream().write("GET / HTTP/1.0\r\n\r\n".getBytes(StringUtil.__ISO_8859_1_CHARSET));
socket.getOutputStream().write("GET / HTTP/1.0\r\n\r\n".getBytes(StandardCharsets.ISO_8859_1));
String out = IO.toString(socket.getInputStream());
Assert.assertThat(out,Matchers.containsString("200 OK"));
}

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -71,10 +72,10 @@ public class HostHeaderCustomizerTest
String request = "" +
"GET / HTTP/1.0\r\n" +
"\r\n";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
SimpleHttpParser parser = new SimpleHttpParser();
SimpleHttpResponse response = parser.readResponse(input);

View File

@ -448,7 +448,7 @@ public class HttpConnectionTest
offset=0;
requests=
"GET /R1?read=1&error=500 HTTP/1.1\n"+
"GET /R1?read=1&error=499 HTTP/1.1\n"+
"Host: localhost\n"+
"Transfer-Encoding: chunked\n"+
"Content-Type: text/plain; charset=utf-8\n"+
@ -468,7 +468,7 @@ public class HttpConnectionTest
response=connector.getResponses(requests);
offset = checkContains(response,offset,"HTTP/1.1 500");
offset = checkContains(response,offset,"HTTP/1.1 499");
offset = checkContains(response,offset,"HTTP/1.1 200");
offset = checkContains(response,offset,"/R2");
offset = checkContains(response,offset,"encoding=UTF-8");

View File

@ -37,6 +37,7 @@ import java.io.OutputStream;
import java.net.Socket;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
@ -114,6 +115,26 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
"\n" +
RESPONSE2_CONTENT;
@Test
public void testSimple() throws Exception
{
configureServer(new HelloWorldHandler());
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
os.write("GET / HTTP/1.0\r\n\r\n".getBytes(StandardCharsets.ISO_8859_1));
os.flush();
// Read the response.
String response = readResponse(client);
Assert.assertThat(response, Matchers.containsString("HTTP/1.1 200 OK"));
Assert.assertThat(response, Matchers.containsString("Hello world"));
}
}
/*
* Feed a full header method
@ -966,12 +987,12 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
}
}
String in = new String(b, 0, i, "utf-8");
String in = new String(b, 0, i, StandardCharsets.UTF_8);
assertTrue(in.contains("123456789"));
assertTrue(in.contains("abcdefghZ"));
assertFalse(in.contains("Wibble"));
in = new String(b, i, b.length - i, "utf-16");
in = new String(b, i, b.length - i, StandardCharsets.UTF_16);
assertEquals("Wibble\n", in);
}
}
@ -1416,11 +1437,11 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
for (int i = 0; i < REQS; i++)
{
out.write("GET / HTTP/1.1\r\nHost: localhost\r\n".getBytes(StringUtil.__ISO_8859_1));
out.write(("Content-Length: " + bytes.length + "\r\n" + "\r\n").getBytes(StringUtil.__ISO_8859_1));
out.write("GET / HTTP/1.1\r\nHost: localhost\r\n".getBytes(StandardCharsets.ISO_8859_1));
out.write(("Content-Length: " + bytes.length + "\r\n" + "\r\n").getBytes(StandardCharsets.ISO_8859_1));
out.write(bytes, 0, bytes.length);
}
out.write("GET / HTTP/1.1\r\nHost: last\r\nConnection: close\r\n\r\n".getBytes(StringUtil.__ISO_8859_1));
out.write("GET / HTTP/1.1\r\nHost: last\r\nConnection: close\r\n\r\n".getBytes(StandardCharsets.ISO_8859_1));
out.flush();
}
catch (Exception e)

View File

@ -28,6 +28,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.util.MultiMap;
@ -330,7 +331,7 @@ public class HttpURITest
huri=new HttpURI(uri);
params = new MultiMap<>();
huri.decodeQueryTo(params,"UTF-8");
huri.decodeQueryTo(params,StandardCharsets.UTF_8);
assertEquals("data"+Utf8Appendable.REPLACEMENT+"here"+Utf8Appendable.REPLACEMENT,params.getValue("invalid",0));
}
@ -343,7 +344,7 @@ public class HttpURITest
HttpURI uri = new HttpURI("/path?value="+URLEncoder.encode(value,"UTF-8"));
MultiMap<String> parameters = new MultiMap<>();
uri.decodeQueryTo(parameters,"UTF-8");
uri.decodeQueryTo(parameters,StandardCharsets.UTF_8);
assertEquals(value,parameters.getString("value"));
}
}
@ -366,7 +367,7 @@ public class HttpURITest
{
try
{
byte[] buf = connect_tests[i][0].getBytes(StringUtil.__UTF8);
byte[] buf = connect_tests[i][0].getBytes(StandardCharsets.UTF_8);
uri.parseConnect(buf,2,buf.length-4);
assertEquals("path"+i,connect_tests[i][0].trim(),uri.getPath());
@ -384,13 +385,13 @@ public class HttpURITest
public void testNonURIAscii() throws Exception
{
String url = "http://www.foo.com/ma\u00F1ana";
byte[] asISO = url.getBytes("ISO-8859-1");
new String(asISO, "ISO-8859-1");
byte[] asISO = url.getBytes(StandardCharsets.ISO_8859_1);
new String(asISO, StandardCharsets.ISO_8859_1);
//use a non UTF-8 charset as the encoding and url-escape as per
//http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars
String s = URLEncoder.encode(url, "ISO-8859-1");
HttpURI uri = new HttpURI(Charset.forName("ISO-8859-1"));
HttpURI uri = new HttpURI(StandardCharsets.ISO_8859_1);
//parse it, using the same encoding
uri.parse(s);

View File

@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
@ -67,7 +68,7 @@ public class HttpWriterTest
{
HttpWriter _writer = new Utf8HttpWriter(_httpOut);
_writer.write("Now is the time");
assertArrayEquals("Now is the time".getBytes(StringUtil.__UTF8),BufferUtil.toArray(_bytes));
assertArrayEquals("Now is the time".getBytes(StandardCharsets.UTF_8),BufferUtil.toArray(_bytes));
}
@Test
@ -75,7 +76,7 @@ public class HttpWriterTest
{
HttpWriter _writer = new Utf8HttpWriter(_httpOut);
_writer.write("How now \uFF22rown cow");
assertArrayEquals("How now \uFF22rown cow".getBytes(StringUtil.__UTF8),BufferUtil.toArray(_bytes));
assertArrayEquals("How now \uFF22rown cow".getBytes(StandardCharsets.UTF_8),BufferUtil.toArray(_bytes));
}
@Test
@ -83,7 +84,7 @@ public class HttpWriterTest
{
HttpWriter _writer = new EncodingHttpWriter(_httpOut,StringUtil.__UTF16);
_writer.write("How now \uFF22rown cow");
assertArrayEquals("How now \uFF22rown cow".getBytes(StringUtil.__UTF16),BufferUtil.toArray(_bytes));
assertArrayEquals("How now \uFF22rown cow".getBytes(StandardCharsets.UTF_16),BufferUtil.toArray(_bytes));
}
@Test
@ -93,7 +94,7 @@ public class HttpWriterTest
String data="xxx\uD801\uDC00xxx";
_writer.write(data);
assertEquals("787878F0909080787878",TypeUtil.toHexString(BufferUtil.toArray(_bytes)));
assertArrayEquals(data.getBytes(StringUtil.__UTF8),BufferUtil.toArray(_bytes));
assertArrayEquals(data.getBytes(StandardCharsets.UTF_8),BufferUtil.toArray(_bytes));
assertEquals(3+4+3,_bytes.remaining());
Utf8StringBuilder buf = new Utf8StringBuilder();
@ -109,7 +110,7 @@ public class HttpWriterTest
final String multiByteDuplicateStr = "\uFF22";
int remainSize = 1;
int multiByteStrByteLength = multiByteDuplicateStr.getBytes("UTF-8").length;
int multiByteStrByteLength = multiByteDuplicateStr.getBytes(StandardCharsets.UTF_8).length;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < HttpWriter.MAX_OUTPUT_CHARS - multiByteStrByteLength; i++) {
sb.append(singleByteStr);
@ -125,7 +126,7 @@ public class HttpWriterTest
_writer.write(buf, 0, length);
assertEquals(sb.toString(),new String(BufferUtil.toArray(_bytes),StringUtil.__UTF8));
assertEquals(sb.toString(),new String(BufferUtil.toArray(_bytes),StandardCharsets.UTF_8));
}
@Test
@ -133,7 +134,7 @@ public class HttpWriterTest
{
HttpWriter _writer = new Iso88591HttpWriter(_httpOut);
_writer.write("How now \uFF22rown cow");
assertEquals("How now ?rown cow",new String(BufferUtil.toArray(_bytes),StringUtil.__ISO_8859_1));
assertEquals("How now ?rown cow",new String(BufferUtil.toArray(_bytes),StandardCharsets.ISO_8859_1));
}
@Test
@ -143,11 +144,11 @@ public class HttpWriterTest
String source = "\uD842\uDF9F";
byte[] bytes = source.getBytes(StringUtil.__UTF8);
byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
_writer.write(source.toCharArray(),0,source.toCharArray().length);
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
java.io.OutputStreamWriter osw = new java.io.OutputStreamWriter(baos ,StringUtil.__UTF8 );
java.io.OutputStreamWriter osw = new java.io.OutputStreamWriter(baos, StandardCharsets.UTF_8);
osw.write(source.toCharArray(),0,source.toCharArray().length);
osw.flush();
@ -181,11 +182,11 @@ public class HttpWriterTest
}
String source = sb.toString();
byte[] bytes = source.getBytes(StringUtil.__UTF8);
byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
_writer.write(source.toCharArray(),0,source.toCharArray().length);
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
java.io.OutputStreamWriter osw = new java.io.OutputStreamWriter(baos ,StringUtil.__UTF8);
java.io.OutputStreamWriter osw = new java.io.OutputStreamWriter(baos, StandardCharsets.UTF_8);
osw.write(source.toCharArray(),0,source.toCharArray().length);
osw.flush();
@ -219,11 +220,11 @@ public class HttpWriterTest
}
String source = sb.toString();
byte[] bytes = source.getBytes(StringUtil.__UTF8);
byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
_writer.write(source.toCharArray(),0,source.toCharArray().length);
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
java.io.OutputStreamWriter osw = new java.io.OutputStreamWriter(baos,StringUtil.__UTF8);
java.io.OutputStreamWriter osw = new java.io.OutputStreamWriter(baos,StandardCharsets.UTF_8);
osw.write(source.toCharArray(),0,source.toCharArray().length);
osw.flush();

View File

@ -24,6 +24,7 @@ import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
@ -161,7 +162,7 @@ public class LowResourcesMonitorTest
for (int i=0;i<socket.length;i++)
Assert.assertEquals(-1,socket[i].getInputStream().read());
newSocket.getOutputStream().write("GET / HTTP/1.0\r\n\r\n".getBytes(StringUtil.__UTF8_CHARSET));
newSocket.getOutputStream().write("GET / HTTP/1.0\r\n\r\n".getBytes(StandardCharsets.UTF_8));
Assert.assertEquals('H',newSocket.getInputStream().read());
}
@ -183,11 +184,11 @@ public class LowResourcesMonitorTest
Thread.sleep(1200);
Assert.assertTrue(_lowResourcesMonitor.isLowOnResources());
Assert.assertEquals(-1,socket0.getInputStream().read());
socket1.getOutputStream().write("G".getBytes(StringUtil.__UTF8_CHARSET));
socket1.getOutputStream().write("G".getBytes(StandardCharsets.UTF_8));
Thread.sleep(1200);
Assert.assertTrue(_lowResourcesMonitor.isLowOnResources());
socket1.getOutputStream().write("E".getBytes(StringUtil.__UTF8_CHARSET));
socket1.getOutputStream().write("E".getBytes(StandardCharsets.UTF_8));
Thread.sleep(1200);
Assert.assertTrue(_lowResourcesMonitor.isLowOnResources());

View File

@ -27,6 +27,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@ -130,14 +131,14 @@ public class NetworkTrafficListenerTest
@Override
public void incoming(Socket socket, ByteBuffer bytes)
{
incomingData.set(BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
incomingData.set(BufferUtil.toString(bytes,StandardCharsets.UTF_8));
incomingLatch.countDown();
}
@Override
public void outgoing(Socket socket, ByteBuffer bytes)
{
outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StandardCharsets.UTF_8));
outgoingLatch.countDown();
}
});
@ -155,7 +156,7 @@ public class NetworkTrafficListenerTest
Socket socket = new Socket("localhost", port);
OutputStream output = socket.getOutputStream();
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
@ -165,7 +166,7 @@ public class NetworkTrafficListenerTest
assertEquals(expectedResponse, outgoingData.get());
byte[] responseBytes = readResponse(socket);
String response = new String(responseBytes, "UTF-8");
String response = new String(responseBytes, StandardCharsets.UTF_8);
assertEquals(expectedResponse, response);
socket.close();
@ -181,7 +182,7 @@ public class NetworkTrafficListenerTest
{
request.setHandled(true);
ServletOutputStream output = servletResponse.getOutputStream();
output.write(responseContent.getBytes("UTF-8"));
output.write(responseContent.getBytes(StandardCharsets.UTF_8));
output.write(END_OF_CONTENT);
}
});
@ -194,13 +195,13 @@ public class NetworkTrafficListenerTest
{
public void incoming(Socket socket, ByteBuffer bytes)
{
incomingData.set(BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
incomingData.set(BufferUtil.toString(bytes,StandardCharsets.UTF_8));
incomingLatch.countDown();
}
public void outgoing(Socket socket, ByteBuffer bytes)
{
outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StandardCharsets.UTF_8));
outgoingLatch.countDown();
}
});
@ -218,7 +219,7 @@ public class NetworkTrafficListenerTest
Socket socket = new Socket("localhost", port);
OutputStream output = socket.getOutputStream();
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
@ -228,7 +229,7 @@ public class NetworkTrafficListenerTest
assertEquals(expectedResponse, outgoingData.get());
byte[] responseBytes = readResponse(socket);
String response = new String(responseBytes, "UTF-8");
String response = new String(responseBytes, StandardCharsets.UTF_8);
assertEquals(expectedResponse, response);
socket.close();
@ -246,9 +247,9 @@ public class NetworkTrafficListenerTest
{
request.setHandled(true);
ServletOutputStream output = servletResponse.getOutputStream();
output.write(responseChunk1.getBytes("UTF-8"));
output.write(responseChunk1.getBytes(StandardCharsets.UTF_8));
output.flush();
output.write(responseChunk2.getBytes("UTF-8"));
output.write(responseChunk2.getBytes(StandardCharsets.UTF_8));
output.flush();
}
});
@ -261,13 +262,13 @@ public class NetworkTrafficListenerTest
{
public void incoming(Socket socket, ByteBuffer bytes)
{
incomingData.set(BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
incomingData.set(BufferUtil.toString(bytes,StandardCharsets.UTF_8));
incomingLatch.countDown();
}
public void outgoing(Socket socket, ByteBuffer bytes)
{
outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StandardCharsets.UTF_8));
outgoingLatch.countDown();
}
});
@ -290,7 +291,7 @@ public class NetworkTrafficListenerTest
Socket socket = new Socket("localhost", port);
OutputStream output = socket.getOutputStream();
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
@ -300,7 +301,7 @@ public class NetworkTrafficListenerTest
assertEquals(expectedResponse, outgoingData.get());
byte[] responseBytes = readResponse(socket);
String response = new String(responseBytes, "UTF-8");
String response = new String(responseBytes, StandardCharsets.UTF_8);
assertEquals(expectedResponse, response);
socket.close();
@ -327,13 +328,13 @@ public class NetworkTrafficListenerTest
{
public void incoming(Socket socket, ByteBuffer bytes)
{
incomingData.set(BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
incomingData.set(BufferUtil.toString(bytes,StandardCharsets.UTF_8));
incomingLatch.countDown();
}
public void outgoing(Socket socket, ByteBuffer bytes)
{
outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StandardCharsets.UTF_8));
outgoingLatch.countDown();
}
});
@ -355,7 +356,7 @@ public class NetworkTrafficListenerTest
Socket socket = new Socket("localhost", port);
OutputStream output = socket.getOutputStream();
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
@ -365,7 +366,7 @@ public class NetworkTrafficListenerTest
assertEquals(expectedResponse, outgoingData.get());
byte[] responseBytes = readResponse(socket);
String response = new String(responseBytes, "UTF-8");
String response = new String(responseBytes, StandardCharsets.UTF_8);
assertEquals(expectedResponse, response);
socket.close();
@ -400,12 +401,12 @@ public class NetworkTrafficListenerTest
{
public void incoming(Socket socket, ByteBuffer bytes)
{
incomingData.set(incomingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
incomingData.set(incomingData.get() + BufferUtil.toString(bytes,StandardCharsets.UTF_8));
}
public void outgoing(Socket socket, ByteBuffer bytes)
{
outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StandardCharsets.UTF_8));
outgoingLatch.countDown();
}
});
@ -429,14 +430,14 @@ public class NetworkTrafficListenerTest
Socket socket = new Socket("localhost", port);
OutputStream output = socket.getOutputStream();
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
assertTrue(outgoingLatch.await(1, TimeUnit.SECONDS));
assertEquals(expectedResponse, outgoingData.get());
byte[] responseBytes = readResponse(socket);
String response = new String(responseBytes, "UTF-8");
String response = new String(responseBytes, StandardCharsets.UTF_8);
assertEquals(expectedResponse, response);
assertEquals(request, incomingData.get());

View File

@ -25,6 +25,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
@ -553,7 +554,7 @@ public class RequestTest
{
baseRequest.setHandled(true);
Reader reader=request.getReader();
byte[] b=("read="+reader.read()+"\n").getBytes(StringUtil.__UTF8);
byte[] b=("read="+reader.read()+"\n").getBytes(StandardCharsets.UTF_8);
response.setContentLength(b.length);
response.getOutputStream().write(b);
response.flushBuffer();
@ -602,7 +603,7 @@ public class RequestTest
String in = IO.toString(reader);
String param = request.getParameter("param");
byte[] b=("read='"+in+"' param="+param+"\n").getBytes(StringUtil.__UTF8);
byte[] b=("read='"+in+"' param="+param+"\n").getBytes(StandardCharsets.UTF_8);
response.setContentLength(b.length);
response.getOutputStream().write(b);
response.flushBuffer();
@ -637,7 +638,7 @@ public class RequestTest
{
baseRequest.setHandled(true);
InputStream in=request.getInputStream();
byte[] b=("read="+in.read()+"\n").getBytes(StringUtil.__UTF8);
byte[] b=("read="+in.read()+"\n").getBytes(StandardCharsets.UTF_8);
response.setContentLength(b.length);
response.getOutputStream().write(b);
response.flushBuffer();

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.server;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.IO;
@ -35,7 +36,7 @@ public class SelectChannelAsyncContextTest extends LocalAsyncContextTest
{
ServerConnector connector = (ServerConnector)_connector;
Socket socket = new Socket((String)null,connector.getLocalPort());
socket.getOutputStream().write(request.getBytes("UTF-8"));
socket.getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
return IO.toString(socket.getInputStream());
}
}

View File

@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import org.eclipse.jetty.server.session.SessionHandler;
@ -101,7 +102,7 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest
ServerConnector connector = (ServerConnector)_connector;
Socket socket = new Socket((String)null,connector.getLocalPort());
socket.setSoTimeout(10 * MAX_IDLE_TIME);
socket.getOutputStream().write(request.getBytes("UTF-8"));
socket.getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
InputStream inputStream = socket.getInputStream();
long start = System.currentTimeMillis();
String response = IO.toString(inputStream);

View File

@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
@ -118,7 +119,7 @@ public class SlowClientWithPipelinedRequestTest
"GET /content HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"\r\n" +
"").getBytes("UTF-8"));
"").getBytes(StandardCharsets.UTF_8));
output.flush();
InputStream input = client.getInputStream();
@ -131,7 +132,7 @@ public class SlowClientWithPipelinedRequestTest
"GET /pipelined HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"\r\n" +
"").getBytes("UTF-8"));
"").getBytes(StandardCharsets.UTF_8));
output.flush();
// Simulate a slow reader

View File

@ -27,6 +27,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
@ -124,7 +125,7 @@ public class IPAccessHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
Response response = readResponse(input);

View File

@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import javax.net.ssl.SSLContext;
import javax.servlet.ServletException;
@ -105,7 +106,7 @@ public class SSLCloseTest
// data=data+data+data+data+data+data+data+data+data+data+data+data+data;
// data=data+data+data+data+data+data+data+data+data+data+data+data+data;
data=data+data+data+data;
byte[] bytes=data.getBytes("UTF-8");
byte[] bytes=data.getBytes(StandardCharsets.UTF_8);
for (int i=0;i<2;i++)
{

View File

@ -49,6 +49,8 @@ import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpHeaderValue;
import org.eclipse.jetty.http.PathMap;
import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.io.RuntimeIOException;
@ -492,7 +494,7 @@ public class ServletHandler extends ScopedHandler
}
LOG.debug("chain={}",chain);
Throwable th=null;
try
{
if (servlet_holder==null)
@ -540,7 +542,7 @@ public class ServletHandler extends ScopedHandler
}
// unwrap cause
Throwable th=e;
th=e;
if (th instanceof ServletException)
{
if (th instanceof QuietServletException)
@ -573,6 +575,7 @@ public class ServletHandler extends ScopedHandler
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION,th);
if (!response.isCommitted())
{
baseRequest.getResponse().getHttpFields().put(HttpHeader.CONNECTION,HttpHeaderValue.CLOSE);
if (th instanceof UnavailableException)
{
UnavailableException ue = (UnavailableException)th;
@ -586,33 +589,34 @@ public class ServletHandler extends ScopedHandler
}
else
LOG.debug("Response already committed for handling "+th);
// Complete async requests
if (request.isAsyncStarted())
request.getAsyncContext().complete();
}
catch(Error e)
{
if ("ContinuationThrowable".equals(e.getClass().getSimpleName()))
throw e;
th=e;
if (!(DispatcherType.REQUEST.equals(type) || DispatcherType.ASYNC.equals(type)))
throw e;
LOG.warn("Error for "+request.getRequestURI(),e);
if(LOG.isDebugEnabled())LOG.debug(request.toString());
if(LOG.isDebugEnabled())
LOG.debug(request.toString());
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE,e.getClass());
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION,e);
if (!response.isCommitted())
{
baseRequest.getResponse().getHttpFields().put(HttpHeader.CONNECTION,HttpHeaderValue.CLOSE);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
else
LOG.debug("Response already committed for handling ",e);
// Complete async requests
if (request.isAsyncStarted())
request.getAsyncContext().complete();
}
finally
{
// Complete async errored requests
if (th!=null && request.isAsyncStarted())
request.getAsyncContext().complete();
if (servlet_holder!=null)
baseRequest.setHandled(true);
}

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.AsyncContext;
import javax.servlet.AsyncEvent;
@ -109,10 +110,10 @@ public class AsyncContextListenersTest
"GET " + path + " HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
SimpleHttpParser parser = new SimpleHttpParser();
SimpleHttpResponse response = parser.readResponse(reader);
Assert.assertEquals("200", response.getCode());
@ -120,7 +121,7 @@ public class AsyncContextListenersTest
// Send a second request
completes.set(0);
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = parser.readResponse(reader);
@ -180,10 +181,10 @@ public class AsyncContextListenersTest
"GET " + path + " HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
SimpleHttpParser parser = new SimpleHttpParser();
SimpleHttpResponse response = parser.readResponse(reader);
Assert.assertEquals("200", response.getCode());
@ -191,7 +192,7 @@ public class AsyncContextListenersTest
// Send a second request
completes.set(0);
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = parser.readResponse(reader);
@ -258,10 +259,10 @@ public class AsyncContextListenersTest
"GET " + path + "/one HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n";
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
SimpleHttpParser parser = new SimpleHttpParser();
SimpleHttpResponse response = parser.readResponse(reader);
Assert.assertEquals("200", response.getCode());
@ -269,7 +270,7 @@ public class AsyncContextListenersTest
// Send a second request
completes.set(0);
output.write(request.getBytes("UTF-8"));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = parser.readResponse(reader);

View File

@ -23,6 +23,7 @@ import java.io.IOException;
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 javax.servlet.AsyncContext;
@ -122,7 +123,7 @@ public class AsyncServletLongPollTest
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"\r\n";
OutputStream output1 = socket1.getOutputStream();
output1.write(request1.getBytes("UTF-8"));
output1.write(request1.getBytes(StandardCharsets.UTF_8));
output1.flush();
Assert.assertTrue(asyncLatch.await(5, TimeUnit.SECONDS));
@ -134,18 +135,18 @@ public class AsyncServletLongPollTest
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"\r\n";
OutputStream output2 = socket2.getOutputStream();
output2.write(request2.getBytes("UTF-8"));
output2.write(request2.getBytes(StandardCharsets.UTF_8));
output2.flush();
SimpleHttpParser parser2 = new SimpleHttpParser();
BufferedReader input2 = new BufferedReader(new InputStreamReader(socket2.getInputStream(), "UTF-8"));
BufferedReader input2 = new BufferedReader(new InputStreamReader(socket2.getInputStream(), StandardCharsets.UTF_8));
SimpleHttpResponse response2 = parser2.readResponse(input2);
Assert.assertEquals("200", response2.getCode());
}
socket1.setSoTimeout(2 * wait);
SimpleHttpParser parser1 = new SimpleHttpParser();
BufferedReader input1 = new BufferedReader(new InputStreamReader(socket1.getInputStream(), "UTF-8"));
BufferedReader input1 = new BufferedReader(new InputStreamReader(socket1.getInputStream(), StandardCharsets.UTF_8));
SimpleHttpResponse response1 = parser1.readResponse(input1);
Assert.assertEquals(error, response1.getCode());
@ -154,7 +155,7 @@ public class AsyncServletLongPollTest
String request3 = "GET " + uri + " HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"\r\n";
output1.write(request3.getBytes("UTF-8"));
output1.write(request3.getBytes(StandardCharsets.UTF_8));
output1.flush();
SimpleHttpResponse response3 = parser1.readResponse(input1);

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.servlet;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
@ -416,7 +417,7 @@ public class AsyncServletTest
try (Socket socket = new Socket("localhost",port))
{
socket.setSoTimeout(1000000);
socket.getOutputStream().write(request.getBytes("UTF-8"));
socket.getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
return IO.toString(socket.getInputStream());
}
catch(Exception e)

View File

@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.LocalConnector;
@ -220,7 +221,7 @@ public class DefaultServletRangesTest
try
{
out = new FileOutputStream(file);
out.write(str.getBytes(StringUtil.__UTF8));
out.write(str.getBytes(StandardCharsets.UTF_8));
out.flush();
}
finally

View File

@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.EnumSet;
import java.util.regex.Matcher;
@ -882,7 +883,7 @@ public class DefaultServletTest
try
{
out = new FileOutputStream(file);
out.write(str.getBytes(StringUtil.__UTF8));
out.write(str.getBytes(StandardCharsets.UTF_8));
out.flush();
}
finally

View File

@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@ -109,7 +110,7 @@ public class RequestHeadersTest
try (InputStream in = http.getInputStream())
{
String resp = IO.toString(in, "UTF-8");
String resp = IO.toString(in, StandardCharsets.UTF_8);
Assert.assertThat("Response", resp, is("X-Camel-Type = bactrian"));
}
}

View File

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

View File

@ -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);

View File

@ -41,13 +41,15 @@ public class GzipOutputStream extends DeflaterOutputStream
out.write(GZIP_HEADER);
}
@Override
public synchronized void write(byte[] buf, int off, int len) throws IOException
{
super.write(buf,off,len);
_crc.update(buf,off,len);
}
public void finish() throws IOException
@Override
public synchronized void finish() throws IOException
{
if (!def.finished())
{
@ -58,6 +60,14 @@ public class GzipOutputStream extends DeflaterOutputStream
out.write(trailer);
}
}
@Override
public synchronized void close() throws IOException
{
super.close();
}
private void writeInt(int i, byte[] buf, int offset)
{

View File

@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.EnumSet;
import javax.servlet.DispatcherType;
@ -117,14 +118,14 @@ public abstract class AbstractDoSFilterTest
for (int i=loops;i-->0;)
{
socket.getOutputStream().write(loopRequests.getBytes("UTF-8"));
socket.getOutputStream().write(loopRequests.getBytes(StandardCharsets.UTF_8));
socket.getOutputStream().flush();
if (i>0 && pauseBetweenLoops>0)
Thread.sleep(pauseBetweenLoops);
}
if (pauseBeforeLast>0)
Thread.sleep(pauseBeforeLast);
socket.getOutputStream().write(lastRequest.getBytes("UTF-8"));
socket.getOutputStream().write(lastRequest.getBytes(StandardCharsets.UTF_8));
socket.getOutputStream().flush();
@ -133,11 +134,11 @@ public abstract class AbstractDoSFilterTest
{
// don't read in anything, forcing the request to time out
Thread.sleep(_requestMaxTime * 2);
response = IO.toString(socket.getInputStream(),"UTF-8");
response = IO.toString(socket.getInputStream(),StandardCharsets.UTF_8);
}
else
{
response = IO.toString(socket.getInputStream(),"UTF-8");
response = IO.toString(socket.getInputStream(),StandardCharsets.UTF_8);
}
socket.close();
return response;

View File

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

View File

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

View File

@ -208,9 +208,20 @@ public abstract class DataInfo extends Info
* @return a String with the content of this {@link DataInfo}
*/
public String asString(String charset, boolean consume)
{
return asString(Charset.forName(charset), consume);
}
/**
*
* @param charset the charset used to convert the bytes
* @param consume whether to consume the content
* @return a String with the content of this {@link DataInfo}
*/
public String asString(Charset charset, boolean consume)
{
ByteBuffer buffer = asByteBuffer(consume);
return Charset.forName(charset).decode(buffer).toString();
return charset.decode(buffer).toString();
}
/**

View File

@ -18,7 +18,7 @@
package org.eclipse.jetty.spdy.api;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
/**
@ -28,11 +28,11 @@ public class StringDataInfo extends BytesDataInfo
{
public StringDataInfo(String string, boolean close)
{
super(string.getBytes(Charset.forName("UTF-8")), close);
super(string.getBytes(StandardCharsets.UTF_8), close);
}
public StringDataInfo(long timeout, TimeUnit unit, String string, boolean close)
{
super(timeout, unit, string.getBytes(Charset.forName("UTF-8")), close);
super(timeout, unit, string.getBytes(StandardCharsets.UTF_8), close);
}
}

View File

@ -20,7 +20,7 @@ package org.eclipse.jetty.spdy.generator;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import org.eclipse.jetty.spdy.CompressionDictionary;
@ -41,25 +41,24 @@ public class HeadersBlockGenerator
public ByteBuffer generate(short version, Fields headers)
{
// TODO: ByteArrayOutputStream is quite inefficient, but grows on demand; optimize using ByteBuffer ?
Charset iso1 = Charset.forName("ISO-8859-1");
ByteArrayOutputStream buffer = new ByteArrayOutputStream(headers.size() * 64);
writeCount(version, buffer, headers.size());
for (Fields.Field header : headers)
{
String name = header.name().toLowerCase(Locale.ENGLISH);
byte[] nameBytes = name.getBytes(iso1);
byte[] nameBytes = name.getBytes(StandardCharsets.ISO_8859_1);
writeNameLength(version, buffer, nameBytes.length);
buffer.write(nameBytes, 0, nameBytes.length);
// Most common path first
String value = header.value();
byte[] valueBytes = value.getBytes(iso1);
byte[] valueBytes = value.getBytes(StandardCharsets.ISO_8859_1);
if (header.hasMultipleValues())
{
String[] values = header.values();
for (int i = 1; i < values.length; ++i)
{
byte[] moreValueBytes = values[i].getBytes(iso1);
byte[] moreValueBytes = values[i].getBytes(StandardCharsets.ISO_8859_1);
byte[] newValueBytes = new byte[valueBytes.length + 1 + moreValueBytes.length];
System.arraycopy(valueBytes, 0, newValueBytes, 0, valueBytes.length);
newValueBytes[valueBytes.length] = 0;

View File

@ -19,7 +19,7 @@
package org.eclipse.jetty.spdy.parser;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.zip.ZipException;
import org.eclipse.jetty.spdy.CompressionDictionary;
@ -57,8 +57,6 @@ public abstract class HeadersBlockParser
data = null;
ByteBuffer decompressedHeaders = decompress(version, compressedHeaders);
Charset iso1 = Charset.forName("ISO-8859-1");
// We know the decoded bytes contain the full headers,
// so optimize instead of looping byte by byte
int count = readCount(version, decompressedHeaders);
@ -69,14 +67,14 @@ public abstract class HeadersBlockParser
throw new StreamException(streamId, StreamStatus.PROTOCOL_ERROR, "Invalid header name length");
byte[] nameBytes = new byte[nameLength];
decompressedHeaders.get(nameBytes);
String name = new String(nameBytes, iso1);
String name = new String(nameBytes, StandardCharsets.ISO_8859_1);
int valueLength = readValueLength(version, decompressedHeaders);
if (valueLength == 0)
throw new StreamException(streamId, StreamStatus.PROTOCOL_ERROR, "Invalid header value length");
byte[] valueBytes = new byte[valueLength];
decompressedHeaders.get(valueBytes);
String value = new String(valueBytes, iso1);
String value = new String(valueBytes, StandardCharsets.ISO_8859_1);
// Multi valued headers are separate by NUL
String[] values = value.split("\u0000");
// Check if there are multiple NULs (section 2.6.9)

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.spdy.api;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -242,7 +243,7 @@ public class ClientUsageTest
public void onData(Stream stream, DataInfo dataInfo)
{
StringBuilder builder = (StringBuilder)stream.getAttribute("builder");
builder.append(dataInfo.asString("UTF-8", true));
builder.append(dataInfo.asString(StandardCharsets.UTF_8, true));
}
}, new Promise.Adapter<Stream>()
@ -250,9 +251,9 @@ public class ClientUsageTest
@Override
public void succeeded(Stream stream)
{
stream.data(new BytesDataInfo("wee".getBytes(Charset.forName("UTF-8")), false), new Callback.Adapter());
stream.data(new BytesDataInfo("wee".getBytes(StandardCharsets.UTF_8), false), new Callback.Adapter());
stream.data(new StringDataInfo("foo", false), new Callback.Adapter());
stream.data(new ByteBufferDataInfo(Charset.forName("UTF-8").encode("bar"), true), new Callback.Adapter());
stream.data(new ByteBufferDataInfo(StandardCharsets.UTF_8.encode("bar"), true), new Callback.Adapter());
}
}
);

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.spdy.parser;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ -43,8 +44,7 @@ public class ParseVersusCacheBenchmarkTest
String name = "Content-Type";
String value = "application/octect-stream";
Charset charset = Charset.forName("ISO-8859-1");
ByteBuffer buffer = ByteBuffer.wrap((name + value).getBytes(charset));
ByteBuffer buffer = ByteBuffer.wrap((name + value).getBytes(StandardCharsets.ISO_8859_1));
int iterations = 100_000_000;
long begin = System.nanoTime();
@ -52,12 +52,12 @@ public class ParseVersusCacheBenchmarkTest
{
byte[] nameBytes = new byte[name.length()];
buffer.get(nameBytes);
String name2 = new String(nameBytes, charset);
String name2 = new String(nameBytes, StandardCharsets.ISO_8859_1);
Assert.assertEquals(name2, name);
byte[] valueBytes = new byte[value.length()];
buffer.get(valueBytes);
String value2 = new String(valueBytes, charset);
String value2 = new String(valueBytes, StandardCharsets.ISO_8859_1);
Assert.assertEquals(value2, value);
buffer.flip();
@ -66,8 +66,8 @@ public class ParseVersusCacheBenchmarkTest
System.err.printf("parse time: %d%n", TimeUnit.NANOSECONDS.toMillis(end - begin));
Map<ByteBuffer, String> map = new HashMap<>();
map.put(ByteBuffer.wrap(name.getBytes(charset)), name);
map.put(ByteBuffer.wrap(value.getBytes(charset)), value);
map.put(ByteBuffer.wrap(name.getBytes(StandardCharsets.ISO_8859_1)), name);
map.put(ByteBuffer.wrap(value.getBytes(StandardCharsets.ISO_8859_1)), value);
final Map<ByteBuffer, String> cache = Collections.unmodifiableMap(map);
begin = System.nanoTime();

View File

@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.List;
import javax.net.ssl.SSLContext;
@ -129,11 +130,11 @@ public class ProtocolNegotiationTest
"GET / HTTP/1.1\r\n" +
"Host: localhost:" + address.getPort() + "\r\n" +
"\r\n" +
"").getBytes("UTF-8"));
"").getBytes(StandardCharsets.UTF_8));
output.flush();
InputStream input = client.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.contains(" 404 "));
@ -188,11 +189,11 @@ public class ProtocolNegotiationTest
"GET / HTTP/1.1\r\n" +
"Host: localhost:" + address.getPort() + "\r\n" +
"\r\n" +
"").getBytes("UTF-8"));
"").getBytes(StandardCharsets.UTF_8));
output.flush();
InputStream input = client.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.contains(" 404 "));
@ -241,11 +242,11 @@ public class ProtocolNegotiationTest
"GET / HTTP/1.1\r\n" +
"Host: localhost:" + address.getPort() + "\r\n" +
"\r\n" +
"").getBytes("UTF-8"));
"").getBytes(StandardCharsets.UTF_8));
output.flush();
InputStream input = client.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.contains(" 404 "));

View File

@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@ -432,7 +433,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
request.setHandled(true);
httpResponse.setStatus(HttpServletResponse.SC_OK);
ServletOutputStream output = httpResponse.getOutputStream();
output.write(data.getBytes("UTF-8"));
output.write(data.getBytes(StandardCharsets.UTF_8));
handlerLatch.countDown();
}
}), null);
@ -455,7 +456,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onData(Stream stream, DataInfo dataInfo)
{
assertTrue(dataInfo.isClose());
assertEquals(data, dataInfo.asString("UTF-8", true));
assertEquals(data, dataInfo.asString(StandardCharsets.UTF_8, true));
dataLatch.countDown();
}
});
@ -527,9 +528,9 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
request.setHandled(true);
httpResponse.setStatus(HttpServletResponse.SC_OK);
ServletOutputStream output = httpResponse.getOutputStream();
output.write(data1.getBytes("UTF-8"));
output.write(data1.getBytes(StandardCharsets.UTF_8));
output.flush();
output.write(data2.getBytes("UTF-8"));
output.write(data2.getBytes(StandardCharsets.UTF_8));
handlerLatch.countDown();
}
}), null);
@ -558,9 +559,9 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
int data = dataFrames.incrementAndGet();
assertTrue(data >= 1 && data <= 2);
if (data == 1)
assertEquals(data1, dataInfo.asString("UTF8", true));
assertEquals(data1, dataInfo.asString(StandardCharsets.UTF_8, true));
else
assertEquals(data2, dataInfo.asString("UTF8", true));
assertEquals(data2, dataInfo.asString(StandardCharsets.UTF_8, true));
dataLatch.countDown();
}
});
@ -744,7 +745,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
request.setHandled(true);
httpResponse.setStatus(HttpServletResponse.SC_OK);
ServletOutputStream output = httpResponse.getOutputStream();
output.write(data.getBytes("UTF-8"));
output.write(data.getBytes(StandardCharsets.UTF_8));
output.flush();
output.close();
handlerLatch.countDown();
@ -775,7 +776,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
buffer.write(byteBuffer.get());
if (dataInfo.isClose())
{
assertEquals(data, new String(buffer.toByteArray(), Charset.forName("UTF-8")));
assertEquals(data, new String(buffer.toByteArray(), StandardCharsets.UTF_8));
dataLatch.countDown();
}
}
@ -801,10 +802,10 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
httpResponse.setStatus(HttpServletResponse.SC_OK);
ServletOutputStream output = httpResponse.getOutputStream();
// Write some
output.write(data1.getBytes("UTF-8"));
output.write(data1.getBytes(StandardCharsets.UTF_8));
// But then change your mind and reset the buffer
httpResponse.resetBuffer();
output.write(data2.getBytes("UTF-8"));
output.write(data2.getBytes(StandardCharsets.UTF_8));
handlerLatch.countDown();
}
}), null);
@ -833,7 +834,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
buffer.write(byteBuffer.get());
if (dataInfo.isClose())
{
assertEquals(data2, new String(buffer.toByteArray(), Charset.forName("UTF-8")));
assertEquals(data2, new String(buffer.toByteArray(), StandardCharsets.UTF_8));
dataLatch.countDown();
}
}
@ -990,10 +991,10 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
request.setHandled(true);
httpResponse.setHeader("Transfer-Encoding", "chunked");
ServletOutputStream output = httpResponse.getOutputStream();
output.write(pangram1.getBytes("UTF-8"));
output.write(pangram1.getBytes(StandardCharsets.UTF_8));
httpResponse.setHeader("EXTRA", "X");
output.flush();
output.write(pangram2.getBytes("UTF-8"));
output.write(pangram2.getBytes(StandardCharsets.UTF_8));
handlerLatch.countDown();
}
}), null);
@ -1024,12 +1025,12 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
if (count == 1)
{
Assert.assertFalse(dataInfo.isClose());
assertEquals(pangram1, dataInfo.asString("UTF-8", true));
assertEquals(pangram1, dataInfo.asString(StandardCharsets.UTF_8, true));
}
else if (count == 2)
{
assertTrue(dataInfo.isClose());
assertEquals(pangram2, dataInfo.asString("UTF-8", true));
assertEquals(pangram2, dataInfo.asString(StandardCharsets.UTF_8, true));
}
dataLatch.countDown();
}

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.spdy.server.proxy;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.CountDownLatch;
@ -251,7 +252,7 @@ public class ProxyHTTPToSPDYTest
@Test
public void testGETThenSmallResponseContent() throws Exception
{
final byte[] data = "0123456789ABCDEF".getBytes("UTF-8");
final byte[] data = "0123456789ABCDEF".getBytes(StandardCharsets.UTF_8);
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{
@Override
@ -328,7 +329,7 @@ public class ProxyHTTPToSPDYTest
public void testPOSTWithSmallRequestContentThenSmallResponseContent() throws Exception
{
String dataString = "0123456789ABCDEF";
final byte[] data = dataString.getBytes("UTF-8");
final byte[] data = dataString.getBytes(StandardCharsets.UTF_8);
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{
@Override
@ -370,7 +371,7 @@ public class ProxyHTTPToSPDYTest
@Test
public void testGETThenSPDYPushIsIgnored() throws Exception
{
final byte[] data = "0123456789ABCDEF".getBytes("UTF-8");
final byte[] data = "0123456789ABCDEF".getBytes(StandardCharsets.UTF_8);
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{
@Override

View File

@ -22,6 +22,7 @@ import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.CountDownLatch;
@ -197,7 +198,7 @@ public class ProxySPDYToHTTPTest
@Test
public void testSYNThenREPLYAndDATA() throws Exception
{
final byte[] data = "0123456789ABCDEF".getBytes("UTF-8");
final byte[] data = "0123456789ABCDEF".getBytes(StandardCharsets.UTF_8);
final String header = "foo";
InetSocketAddress proxyAddress = startProxy(startServer(new TestServerHandler(header, data)), 30000, 30000);

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.spdy.server.proxy;
import java.io.ByteArrayOutputStream;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.CountDownLatch;
@ -227,7 +228,7 @@ public class ProxySPDYToSPDYTest
@Test
public void testSYNThenREPLYAndDATA() throws Exception
{
final byte[] data = "0123456789ABCDEF".getBytes("UTF-8");
final byte[] data = "0123456789ABCDEF".getBytes(StandardCharsets.UTF_8);
final String header = "foo";
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{
@ -287,7 +288,7 @@ public class ProxySPDYToSPDYTest
@Test
public void testSYNThenSPDYPushIsReceived() throws Exception
{
final byte[] data = "0123456789ABCDEF".getBytes("UTF-8");
final byte[] data = "0123456789ABCDEF".getBytes(StandardCharsets.UTF_8);
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{
@Override
@ -368,7 +369,7 @@ public class ProxySPDYToSPDYTest
@Test
public void testSYNThenSPDYNestedPushIsReceived() throws Exception
{
final byte[] data = "0123456789ABCDEF".getBytes("UTF-8");
final byte[] data = "0123456789ABCDEF".getBytes(StandardCharsets.UTF_8);
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{
@Override

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.spdy.server;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@ -118,7 +119,7 @@ public class SynReplyTest extends AbstractTest
@Test
public void testSynDataReply() throws Exception
{
final byte[] dataBytes = "foo".getBytes(Charset.forName("UTF-8"));
final byte[] dataBytes = "foo".getBytes(StandardCharsets.UTF_8);
final CountDownLatch synLatch = new CountDownLatch(1);
final CountDownLatch dataLatch = new CountDownLatch(1);
@ -235,13 +236,13 @@ public class SynReplyTest extends AbstractTest
int dataCount = this.dataCount.incrementAndGet();
if (dataCount == 1)
{
String chunk1 = dataInfo.asString("UTF-8", true);
String chunk1 = dataInfo.asString(StandardCharsets.UTF_8, true);
Assert.assertEquals(data1, chunk1);
dataLatch1.countDown();
}
else if (dataCount == 2)
{
String chunk2 = dataInfo.asString("UTF-8", true);
String chunk2 = dataInfo.asString(StandardCharsets.UTF_8, true);
Assert.assertEquals(data2, chunk2);
dataLatch2.countDown();
}
@ -277,7 +278,7 @@ public class SynReplyTest extends AbstractTest
@Override
public void onData(Stream stream, DataInfo dataInfo)
{
String data = dataInfo.asString("UTF-8", true);
String data = dataInfo.asString(StandardCharsets.UTF_8, true);
Assert.assertEquals(clientData, data);
clientDataLatch.countDown();
}
@ -311,7 +312,7 @@ public class SynReplyTest extends AbstractTest
public void onData(Stream stream, DataInfo dataInfo)
{
ByteBuffer buffer = dataInfo.asByteBuffer(false);
String data = Charset.forName("UTF-8").decode(buffer).toString();
String data = StandardCharsets.UTF_8.decode(buffer).toString();
Assert.assertEquals(serverData, data);
serverDataLatch.countDown();
}
@ -361,7 +362,7 @@ public class SynReplyTest extends AbstractTest
@Override
public void onData(Stream stream, DataInfo dataInfo)
{
String chunk = dataInfo.asString("UTF-8", true);
String chunk = dataInfo.asString(StandardCharsets.UTF_8, true);
Assert.assertEquals(data, chunk);
dataLatch.countDown();
}

View File

@ -20,6 +20,7 @@
package org.eclipse.jetty.spring;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Map;
import java.util.ServiceLoader;
@ -80,7 +81,7 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor
: new ByteArrayResource(("" +
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">" +
config).getBytes("UTF-8"));
config).getBytes(StandardCharsets.UTF_8));
_beanFactory = new DefaultListableBeanFactory()
{

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.util;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
/* ------------------------------------------------------------ */
@ -72,7 +73,7 @@ public abstract class AbstractTrie<V> implements Trie<V>
@Override
public V getBest(byte[] b, int offset, int len)
{
return getBest(new String(b,offset,len,StringUtil.__ISO_8859_1_CHARSET));
return getBest(new String(b,offset,len,StandardCharsets.ISO_8859_1));
}
@Override

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
@ -65,7 +66,7 @@ public class B64Code
*/
public static String encode(String s)
{
return encode(s,null);
return encode(s, (Charset)null);
}
/**
@ -80,12 +81,25 @@ public class B64Code
{
byte[] bytes;
if (charEncoding==null)
bytes=s.getBytes(Charset.forName(StringUtil.__ISO_8859_1));
bytes=s.getBytes(StandardCharsets.ISO_8859_1);
else
bytes=s.getBytes(Charset.forName(charEncoding));
return new String(encode(bytes));
}
/**
* Base 64 encode as described in RFC 1421.
* <p>Does not insert whitespace as described in RFC 1521.
* @param s String to encode.
* @param charEncoding The character encoding of the provided input String.
* @return String containing the encoded form of the input.
*/
public static String encode(String s, Charset charEncoding)
{
byte[] bytes=s.getBytes(charEncoding==null ? StandardCharsets.ISO_8859_1 : charEncoding);
return new String(encode(bytes));
}
/**
* Fast Base 64 encode as described in RFC 1421.
* <p>Does not insert whitespace as described in RFC 1521.
@ -236,6 +250,24 @@ public class B64Code
return new String(decoded,Charset.forName(charEncoding));
}
/**
* Base 64 decode as described in RFC 2045.
* <p>Unlike {@link #decode(char[])}, extra whitespace is ignored.
* @param encoded String to decode.
* @param charEncoding Character encoding
* used to map the decoded bytes into a String.
* @return String decoded byte array.
* @throws IllegalArgumentException if the input is not a valid
* B64 encoding.
*/
public static String decode(String encoded, Charset charEncoding)
{
byte[] decoded=decode(encoded);
if (charEncoding==null)
return new String(decoded);
return new String(decoded, charEncoding);
}
/**
* Fast Base 64 decode as described in RFC 1421.
*

View File

@ -29,6 +29,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
/* ------------------------------------------------------------------------------- */
@ -454,7 +455,7 @@ public class BufferUtil
*/
public static String toString(ByteBuffer buffer)
{
return toString(buffer, StringUtil.__ISO_8859_1_CHARSET);
return toString(buffer, StandardCharsets.ISO_8859_1);
}
/* ------------------------------------------------------------ */
@ -464,7 +465,7 @@ public class BufferUtil
*/
public static String toUTF8String(ByteBuffer buffer)
{
return toString(buffer, StringUtil.__UTF8_CHARSET);
return toString(buffer, StandardCharsets.UTF_8);
}
/* ------------------------------------------------------------ */
@ -733,12 +734,12 @@ public class BufferUtil
public static ByteBuffer toBuffer(String s)
{
return ByteBuffer.wrap(s.getBytes(StringUtil.__ISO_8859_1_CHARSET));
return ByteBuffer.wrap(s.getBytes(StandardCharsets.ISO_8859_1));
}
public static ByteBuffer toDirectBuffer(String s)
{
byte[] bytes = s.getBytes(StringUtil.__ISO_8859_1_CHARSET);
byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
ByteBuffer buf = ByteBuffer.allocateDirect(bytes.length);
buf.put(bytes);
buf.flip();

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
/* ------------------------------------------------------------ */
@ -211,7 +212,7 @@ public class ByteArrayISO8859Writer extends Writer
if (_bout==null)
{
_bout = new ByteArrayOutputStream2(2*length);
_writer = new OutputStreamWriter(_bout,StringUtil.__ISO_8859_1);
_writer = new OutputStreamWriter(_bout,StandardCharsets.ISO_8859_1);
}
else
_bout.reset();

View File

@ -29,6 +29,7 @@ import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -311,7 +312,7 @@ public class IO
public static String toString(InputStream in)
throws IOException
{
return toString(in,null);
return toString(in,(Charset)null);
}
/* ------------------------------------------------------------ */
@ -319,14 +320,22 @@ public class IO
*/
public static String toString(InputStream in,String encoding)
throws IOException
{
return toString(in, encoding==null?null:Charset.forName(encoding));
}
/** Read input stream to string.
*/
public static String toString(InputStream in, Charset encoding)
throws IOException
{
StringWriter writer=new StringWriter();
InputStreamReader reader = encoding==null?new InputStreamReader(in):new InputStreamReader(in,encoding);
copy(reader,writer);
return writer.toString();
}
/* ------------------------------------------------------------ */
/** Read input stream to string.
*/

View File

@ -29,6 +29,7 @@ import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -475,7 +476,7 @@ public class MultiPartInputStreamParser
}
String boundary="--"+contentTypeBoundary;
byte[] byteBoundary=(boundary+"--").getBytes(StringUtil.__ISO_8859_1);
byte[] byteBoundary=(boundary+"--").getBytes(StandardCharsets.ISO_8859_1);
// Get first boundary
String line = null;

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.util;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
/* ================================================================ */
@ -53,7 +54,7 @@ public class MultiPartOutputStream extends FilterOutputStream
boundary = "jetty"+System.identityHashCode(this)+
Long.toString(System.currentTimeMillis(),36);
boundaryBytes=boundary.getBytes(StringUtil.__ISO_8859_1);
boundaryBytes=boundary.getBytes(StandardCharsets.ISO_8859_1);
}
public MultiPartOutputStream(OutputStream out, String boundary)
@ -62,7 +63,7 @@ public class MultiPartOutputStream extends FilterOutputStream
super(out);
this.boundary = boundary;
boundaryBytes=boundary.getBytes(StringUtil.__ISO_8859_1);
boundaryBytes=boundary.getBytes(StandardCharsets.ISO_8859_1);
}
/* ------------------------------------------------------------ */
@ -110,7 +111,7 @@ public class MultiPartOutputStream extends FilterOutputStream
out.write(boundaryBytes);
out.write(__CRLF);
if (contentType != null)
out.write(("Content-Type: "+contentType).getBytes(StringUtil.__ISO_8859_1));
out.write(("Content-Type: "+contentType).getBytes(StandardCharsets.ISO_8859_1));
out.write(__CRLF);
out.write(__CRLF);
}
@ -128,11 +129,11 @@ public class MultiPartOutputStream extends FilterOutputStream
out.write(boundaryBytes);
out.write(__CRLF);
if (contentType != null)
out.write(("Content-Type: "+contentType).getBytes(StringUtil.__ISO_8859_1));
out.write(("Content-Type: "+contentType).getBytes(StandardCharsets.ISO_8859_1));
out.write(__CRLF);
for (int i=0;headers!=null && i<headers.length;i++)
{
out.write(headers[i].getBytes(StringUtil.__ISO_8859_1));
out.write(headers[i].getBytes(StandardCharsets.ISO_8859_1));
out.write(__CRLF);
}
out.write(__CRLF);

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.util;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
/**
* ReadLineInputStream
@ -58,7 +59,7 @@ public class ReadLineInputStream extends BufferedInputStream
int m=markpos;
markpos=-1;
if (pos>m)
return new String(buf,m,pos-m,StringUtil.__UTF8_CHARSET);
return new String(buf,m,pos-m, StandardCharsets.UTF_8);
return null;
}
@ -77,7 +78,7 @@ public class ReadLineInputStream extends BufferedInputStream
_skipLF=true;
int m=markpos;
markpos=-1;
return new String(buf,m,p-m-1,StringUtil.__UTF8_CHARSET);
return new String(buf,m,p-m-1,StandardCharsets.UTF_8);
}
if (b=='\n')
@ -91,7 +92,7 @@ public class ReadLineInputStream extends BufferedInputStream
}
int m=markpos;
markpos=-1;
return new String(buf,m,pos-m-1,StringUtil.__UTF8_CHARSET);
return new String(buf,m,pos-m-1,StandardCharsets.UTF_8);
}
}
}

View File

@ -21,13 +21,14 @@ package org.eclipse.jetty.util;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/** Fast String Utilities.
*
* These string utilities provide both conveniance methods and
* These string utilities provide both convenience methods and
* performance improvements over most standard library versions. The
* main aim of the optimizations is to avoid object creation unless
* absolutely required.
@ -49,19 +50,30 @@ public class StringUtil
public static final String __ISO_8859_1="ISO-8859-1";
public final static String __UTF8="UTF-8";
public final static String __UTF16="UTF-16";
public final static Charset __UTF8_CHARSET;
public final static Charset __ISO_8859_1_CHARSET;
public final static Charset __UTF16_CHARSET;
public final static Charset __US_ASCII_CHARSET;
/**
* @deprecated Use {@link StandardCharsets#UTF_8}
*/
@Deprecated
public final static Charset __UTF8_CHARSET=StandardCharsets.UTF_8;
/**
* @deprecated Use {@link StandardCharsets#ISO_8859_1}
*/
@Deprecated
public final static Charset __ISO_8859_1_CHARSET=StandardCharsets.ISO_8859_1;
/**
* @deprecated Use {@link StandardCharsets#UTF_16}
*/
@Deprecated
public final static Charset __UTF16_CHARSET=StandardCharsets.UTF_16;
/**
* @deprecated Use {@link StandardCharsets#US_ASCII}
*/
@Deprecated
public final static Charset __US_ASCII_CHARSET=StandardCharsets.US_ASCII;
static
{
__UTF8_CHARSET=Charset.forName(__UTF8);
__ISO_8859_1_CHARSET=Charset.forName(__ISO_8859_1);
__UTF16_CHARSET=Charset.forName(__UTF16);
__US_ASCII_CHARSET=Charset.forName("US-ASCII");
CHARSETS.put("UTF-8",__UTF8);
CHARSETS.put("UTF8",__UTF8);
CHARSETS.put("UTF-16",__UTF16);
@ -343,7 +355,7 @@ public class StringUtil
/* ------------------------------------------------------------ */
public static String toUTF8String(byte[] b,int offset,int length)
{
return new String(b,offset,length,__UTF8_CHARSET);
return new String(b,offset,length,StandardCharsets.UTF_8);
}
/* ------------------------------------------------------------ */
@ -481,12 +493,12 @@ public class StringUtil
public static byte[] getBytes(String s)
{
return s.getBytes(__ISO_8859_1_CHARSET);
return s.getBytes(StandardCharsets.ISO_8859_1);
}
public static byte[] getUtf8Bytes(String s)
{
return s.getBytes(__UTF8_CHARSET);
return s.getBytes(StandardCharsets.UTF_8);
}
public static byte[] getBytes(String s,String charset)

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.util;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@ -215,7 +216,7 @@ public class TreeTrie<V> extends AbstractTrie<V>
public V getBest(String s, int offset, int len)
{
// TODO inefficient
byte[] b=s.substring(offset,offset+len).getBytes(StringUtil.__ISO_8859_1_CHARSET);
byte[] b=s.substring(offset,offset+len).getBytes(StandardCharsets.ISO_8859_1);
return getBest(b,0,b.length);
}

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.util;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
@ -43,8 +44,14 @@ public class URIUtil
public static final String HTTPS_COLON="https:";
// Use UTF-8 as per http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars
public static final Charset __CHARSET=Charset.forName(System.getProperty("org.eclipse.jetty.util.URI.charset",StringUtil.__UTF8));
public static final Charset __CHARSET;
static
{
String charset = System.getProperty("org.eclipse.jetty.util.URI.charset");
__CHARSET = charset == null ? StandardCharsets.UTF_8 : Charset.forName(charset);
}
private URIUtil()
{}

View File

@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
@ -59,15 +60,16 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
public static final Charset ENCODING;
static
{
Charset encoding=null;
Charset encoding;
try
{
encoding=Charset.forName(System.getProperty("org.eclipse.jetty.util.UrlEncoding.charset",StringUtil.__UTF8));
String charset = System.getProperty("org.eclipse.jetty.util.UrlEncoding.charset");
encoding = charset == null ? StandardCharsets.UTF_8 : Charset.forName(charset);
}
catch(Exception e)
{
LOG.warn(e);
encoding=StringUtil.__UTF8_CHARSET;
encoding=StandardCharsets.UTF_8;
}
ENCODING=encoding;
}
@ -269,7 +271,6 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
* @param offset the offset within raw to decode from
* @param length the length of the section to decode
* @param map the {@link MultiMap} to populate
* @param buffer the buffer to decode into
*/
public static void decodeUtf8To(byte[] raw,int offset, int length, MultiMap<String> map)
{
@ -594,11 +595,11 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
/* -------------------------------------------------------------- */
public static void decodeUtf16To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys) throws IOException
{
InputStreamReader input = new InputStreamReader(in,StringUtil.__UTF16);
InputStreamReader input = new InputStreamReader(in,StandardCharsets.UTF_16);
StringWriter buf = new StringWriter(8192);
IO.copy(input,buf,maxLength);
decodeTo(buf.getBuffer().toString(),map,StringUtil.__UTF16,maxKeys);
decodeTo(buf.getBuffer().toString(),map,StandardCharsets.UTF_16,maxKeys);
}
/* -------------------------------------------------------------- */
@ -610,7 +611,7 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
{
if (charset==null)
{
if (ENCODING==StringUtil.__UTF8_CHARSET)
if (ENCODING.equals(StandardCharsets.UTF_8))
decodeUtf8To(in,map,maxLength,maxKeys);
else
decodeTo(in,map,ENCODING,maxLength,maxKeys);
@ -636,19 +637,19 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
if (charset==null)
charset=ENCODING;
if (StringUtil.__UTF8_CHARSET.equals(charset))
if (StandardCharsets.UTF_8.equals(charset))
{
decodeUtf8To(in,map,maxLength,maxKeys);
return;
}
if (StringUtil.__ISO_8859_1_CHARSET.equals(charset))
if (StandardCharsets.ISO_8859_1.equals(charset))
{
decode88591To(in,map,maxLength,maxKeys);
return;
}
if (StringUtil.__UTF16_CHARSET.equals(charset)) // Should be all 2 byte encodings
if (StandardCharsets.UTF_16.equals(charset)) // Should be all 2 byte encodings
{
decodeUtf16To(in,map,maxLength,maxKeys);
return;
@ -753,7 +754,7 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
*/
public static String decodeString(String encoded,int offset,int length,Charset charset)
{
if (charset==null || StringUtil.__UTF8_CHARSET.equals(charset))
if (charset==null || StandardCharsets.UTF_8.equals(charset))
{
Utf8StringBuffer buffer=null;

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.util.security;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import org.eclipse.jetty.util.StringUtil;
@ -156,7 +157,7 @@ public abstract class Credential implements Serializable
{
if (__md == null) __md = MessageDigest.getInstance("MD5");
__md.reset();
__md.update(credentials.toString().getBytes(StringUtil.__ISO_8859_1));
__md.update(credentials.toString().getBytes(StandardCharsets.ISO_8859_1));
digest = __md.digest();
}
if (digest == null || digest.length != _digest.length) return false;
@ -213,7 +214,7 @@ public abstract class Credential implements Serializable
}
__md.reset();
__md.update(password.getBytes(StringUtil.__ISO_8859_1));
__md.update(password.getBytes(StandardCharsets.ISO_8859_1));
digest = __md.digest();
}

Some files were not shown because too many files have changed in this diff Show More