Merge branch 'master' into release-9
This commit is contained in:
commit
ebe5e04f7b
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.client;
|
package org.eclipse.jetty.client;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.charset.UnsupportedCharsetException;
|
import java.nio.charset.UnsupportedCharsetException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -92,15 +93,22 @@ public class HttpContentResponse implements ContentResponse
|
||||||
public String getContentAsString()
|
public String getContentAsString()
|
||||||
{
|
{
|
||||||
String encoding = this.encoding;
|
String encoding = this.encoding;
|
||||||
|
if (encoding == null)
|
||||||
|
{
|
||||||
|
return new String(getContent(), StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new String(getContent(), encoding == null ? "UTF-8" : encoding);
|
return new String(getContent(), encoding);
|
||||||
}
|
}
|
||||||
catch (UnsupportedEncodingException e)
|
catch (UnsupportedEncodingException e)
|
||||||
{
|
{
|
||||||
throw new UnsupportedCharsetException(encoding);
|
throw new UnsupportedCharsetException(encoding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.client.util;
|
package org.eclipse.jetty.client.util;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.eclipse.jetty.client.HttpClient;
|
import org.eclipse.jetty.client.HttpClient;
|
||||||
import org.eclipse.jetty.client.api.Authentication;
|
import org.eclipse.jetty.client.api.Authentication;
|
||||||
|
@ -73,8 +74,7 @@ public class BasicAuthentication implements Authentication
|
||||||
@Override
|
@Override
|
||||||
public Result authenticate(Request request, ContentResponse response, HeaderInfo headerInfo, Attributes context)
|
public Result authenticate(Request request, ContentResponse response, HeaderInfo headerInfo, Attributes context)
|
||||||
{
|
{
|
||||||
String encoding = StringUtil.__ISO_8859_1;
|
String value = "Basic " + B64Code.encode(user + ":" + password, StandardCharsets.ISO_8859_1);
|
||||||
String value = "Basic " + B64Code.encode(user + ":" + password, encoding);
|
|
||||||
return new BasicResult(headerInfo.getHeader(), uri, value);
|
return new BasicResult(headerInfo.getHeader(), uri, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ package org.eclipse.jetty.client.util;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.charset.UnsupportedCharsetException;
|
import java.nio.charset.UnsupportedCharsetException;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@ -130,7 +132,7 @@ public abstract class BufferingResponseListener extends Response.Listener.Empty
|
||||||
{
|
{
|
||||||
String encoding = this.encoding;
|
String encoding = this.encoding;
|
||||||
if (encoding == null)
|
if (encoding == null)
|
||||||
encoding = "UTF-8";
|
return getContentAsString(StandardCharsets.UTF_8);
|
||||||
return getContentAsString(encoding);
|
return getContentAsString(encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,4 +152,14 @@ public abstract class BufferingResponseListener extends Response.Listener.Empty
|
||||||
throw new UnsupportedCharsetException(encoding);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.client.util;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -217,14 +218,13 @@ public class DigestAuthentication implements Authentication
|
||||||
if (digester == null)
|
if (digester == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Charset charset = Charset.forName("ISO-8859-1");
|
|
||||||
String A1 = user + ":" + realm + ":" + password;
|
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();
|
String A2 = request.method() + ":" + request.getURI();
|
||||||
if ("auth-int".equals(qop))
|
if ("auth-int".equals(qop))
|
||||||
A2 += ":" + toHexString(digester.digest(content));
|
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 nonceCount;
|
||||||
String clientNonce;
|
String clientNonce;
|
||||||
|
@ -241,7 +241,7 @@ public class DigestAuthentication implements Authentication
|
||||||
clientNonce = null;
|
clientNonce = null;
|
||||||
A3 = hashA1 + ":" + nonce + ":" + hashA2;
|
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");
|
StringBuilder value = new StringBuilder("Digest");
|
||||||
value.append(" username=\"").append(user).append("\"");
|
value.append(" username=\"").append(user).append("\"");
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.client.util;
|
package org.eclipse.jetty.client.util;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.eclipse.jetty.client.api.ContentProvider;
|
import org.eclipse.jetty.client.api.ContentProvider;
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ public class StringContentProvider extends BytesContentProvider
|
||||||
{
|
{
|
||||||
public StringContentProvider(String content)
|
public StringContentProvider(String content)
|
||||||
{
|
{
|
||||||
this(content, "UTF-8");
|
this(content, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringContentProvider(String content, String encoding)
|
public StringContentProvider(String content, String encoding)
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ public class GZIPContentDecoderTest
|
||||||
data += data;
|
data += data;
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
GZIPOutputStream output = new GZIPOutputStream(baos);
|
GZIPOutputStream output = new GZIPOutputStream(baos);
|
||||||
output.write(data.getBytes("UTF-8"));
|
output.write(data.getBytes(StandardCharsets.UTF_8));
|
||||||
output.close();
|
output.close();
|
||||||
byte[] bytes = baos.toByteArray();
|
byte[] bytes = baos.toByteArray();
|
||||||
|
|
||||||
|
@ -68,7 +69,7 @@ public class GZIPContentDecoderTest
|
||||||
int read;
|
int read;
|
||||||
while ((read = input.read()) >= 0)
|
while ((read = input.read()) >= 0)
|
||||||
baos.write(read);
|
baos.write(read);
|
||||||
assertEquals(data, new String(baos.toByteArray(), "UTF-8"));
|
assertEquals(data, new String(baos.toByteArray(), StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -91,13 +92,13 @@ public class GZIPContentDecoderTest
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
GZIPOutputStream output = new GZIPOutputStream(baos);
|
GZIPOutputStream output = new GZIPOutputStream(baos);
|
||||||
output.write(data.getBytes("UTF-8"));
|
output.write(data.getBytes(StandardCharsets.UTF_8));
|
||||||
output.close();
|
output.close();
|
||||||
byte[] bytes = baos.toByteArray();
|
byte[] bytes = baos.toByteArray();
|
||||||
|
|
||||||
GZIPContentDecoder decoder = new GZIPContentDecoder();
|
GZIPContentDecoder decoder = new GZIPContentDecoder();
|
||||||
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes));
|
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
|
@Test
|
||||||
|
@ -107,7 +108,7 @@ public class GZIPContentDecoderTest
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
GZIPOutputStream output = new GZIPOutputStream(baos);
|
GZIPOutputStream output = new GZIPOutputStream(baos);
|
||||||
output.write(data.getBytes("UTF-8"));
|
output.write(data.getBytes(StandardCharsets.UTF_8));
|
||||||
output.close();
|
output.close();
|
||||||
byte[] bytes = baos.toByteArray();
|
byte[] bytes = baos.toByteArray();
|
||||||
|
|
||||||
|
@ -121,7 +122,7 @@ public class GZIPContentDecoderTest
|
||||||
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1));
|
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1));
|
||||||
assertEquals(0, decoded.capacity());
|
assertEquals(0, decoded.capacity());
|
||||||
decoded = decoder.decode(ByteBuffer.wrap(bytes2));
|
decoded = decoder.decode(ByteBuffer.wrap(bytes2));
|
||||||
assertEquals(data, Charset.forName("UTF-8").decode(decoded).toString());
|
assertEquals(data, StandardCharsets.UTF_8.decode(decoded).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -131,7 +132,7 @@ public class GZIPContentDecoderTest
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
GZIPOutputStream output = new GZIPOutputStream(baos);
|
GZIPOutputStream output = new GZIPOutputStream(baos);
|
||||||
output.write(data.getBytes("UTF-8"));
|
output.write(data.getBytes(StandardCharsets.UTF_8));
|
||||||
output.close();
|
output.close();
|
||||||
byte[] bytes = baos.toByteArray();
|
byte[] bytes = baos.toByteArray();
|
||||||
|
|
||||||
|
@ -143,7 +144,7 @@ public class GZIPContentDecoderTest
|
||||||
|
|
||||||
GZIPContentDecoder decoder = new GZIPContentDecoder();
|
GZIPContentDecoder decoder = new GZIPContentDecoder();
|
||||||
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1));
|
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());
|
assertFalse(decoder.isFinished());
|
||||||
decoded = decoder.decode(ByteBuffer.wrap(bytes2));
|
decoded = decoder.decode(ByteBuffer.wrap(bytes2));
|
||||||
assertEquals(0, decoded.remaining());
|
assertEquals(0, decoded.remaining());
|
||||||
|
@ -157,7 +158,7 @@ public class GZIPContentDecoderTest
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
GZIPOutputStream output = new GZIPOutputStream(baos);
|
GZIPOutputStream output = new GZIPOutputStream(baos);
|
||||||
output.write(data.getBytes("UTF-8"));
|
output.write(data.getBytes(StandardCharsets.UTF_8));
|
||||||
output.close();
|
output.close();
|
||||||
byte[] bytes = baos.toByteArray();
|
byte[] bytes = baos.toByteArray();
|
||||||
|
|
||||||
|
@ -171,7 +172,7 @@ public class GZIPContentDecoderTest
|
||||||
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1));
|
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1));
|
||||||
assertEquals(0, decoded.capacity());
|
assertEquals(0, decoded.capacity());
|
||||||
decoded = decoder.decode(ByteBuffer.wrap(bytes2));
|
decoded = decoder.decode(ByteBuffer.wrap(bytes2));
|
||||||
assertEquals(data, Charset.forName("UTF-8").decode(decoded).toString());
|
assertEquals(data, StandardCharsets.UTF_8.decode(decoded).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -180,14 +181,14 @@ public class GZIPContentDecoderTest
|
||||||
String data1 = "0";
|
String data1 = "0";
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
GZIPOutputStream output = new GZIPOutputStream(baos);
|
GZIPOutputStream output = new GZIPOutputStream(baos);
|
||||||
output.write(data1.getBytes("UTF-8"));
|
output.write(data1.getBytes(StandardCharsets.UTF_8));
|
||||||
output.close();
|
output.close();
|
||||||
byte[] bytes1 = baos.toByteArray();
|
byte[] bytes1 = baos.toByteArray();
|
||||||
|
|
||||||
String data2 = "1";
|
String data2 = "1";
|
||||||
baos = new ByteArrayOutputStream();
|
baos = new ByteArrayOutputStream();
|
||||||
output = new GZIPOutputStream(baos);
|
output = new GZIPOutputStream(baos);
|
||||||
output.write(data2.getBytes("UTF-8"));
|
output.write(data2.getBytes(StandardCharsets.UTF_8));
|
||||||
output.close();
|
output.close();
|
||||||
byte[] bytes2 = baos.toByteArray();
|
byte[] bytes2 = baos.toByteArray();
|
||||||
|
|
||||||
|
@ -198,11 +199,11 @@ public class GZIPContentDecoderTest
|
||||||
GZIPContentDecoder decoder = new GZIPContentDecoder();
|
GZIPContentDecoder decoder = new GZIPContentDecoder();
|
||||||
ByteBuffer buffer = ByteBuffer.wrap(bytes);
|
ByteBuffer buffer = ByteBuffer.wrap(bytes);
|
||||||
ByteBuffer decoded = decoder.decode(buffer);
|
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(decoder.isFinished());
|
||||||
assertTrue(buffer.hasRemaining());
|
assertTrue(buffer.hasRemaining());
|
||||||
decoded = decoder.decode(buffer);
|
decoded = decoder.decode(buffer);
|
||||||
assertEquals(data2, Charset.forName("UTF-8").decode(decoded).toString());
|
assertEquals(data2, StandardCharsets.UTF_8.decode(decoded).toString());
|
||||||
assertTrue(decoder.isFinished());
|
assertTrue(decoder.isFinished());
|
||||||
assertFalse(buffer.hasRemaining());
|
assertFalse(buffer.hasRemaining());
|
||||||
}
|
}
|
||||||
|
@ -215,7 +216,7 @@ public class GZIPContentDecoderTest
|
||||||
data += data;
|
data += data;
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
GZIPOutputStream output = new GZIPOutputStream(baos);
|
GZIPOutputStream output = new GZIPOutputStream(baos);
|
||||||
output.write(data.getBytes("UTF-8"));
|
output.write(data.getBytes(StandardCharsets.UTF_8));
|
||||||
output.close();
|
output.close();
|
||||||
byte[] bytes = baos.toByteArray();
|
byte[] bytes = baos.toByteArray();
|
||||||
|
|
||||||
|
@ -225,7 +226,7 @@ public class GZIPContentDecoderTest
|
||||||
while (buffer.hasRemaining())
|
while (buffer.hasRemaining())
|
||||||
{
|
{
|
||||||
ByteBuffer decoded = decoder.decode(buffer);
|
ByteBuffer decoded = decoder.decode(buffer);
|
||||||
result += Charset.forName("UTF-8").decode(decoded).toString();
|
result += StandardCharsets.UTF_8.decode(decoded).toString();
|
||||||
}
|
}
|
||||||
assertEquals(data, result);
|
assertEquals(data, result);
|
||||||
}
|
}
|
||||||
|
@ -238,7 +239,7 @@ public class GZIPContentDecoderTest
|
||||||
data += data;
|
data += data;
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
GZIPOutputStream output = new GZIPOutputStream(baos);
|
GZIPOutputStream output = new GZIPOutputStream(baos);
|
||||||
output.write(data.getBytes("UTF-8"));
|
output.write(data.getBytes(StandardCharsets.UTF_8));
|
||||||
output.close();
|
output.close();
|
||||||
byte[] bytes = baos.toByteArray();
|
byte[] bytes = baos.toByteArray();
|
||||||
|
|
||||||
|
@ -249,7 +250,7 @@ public class GZIPContentDecoderTest
|
||||||
{
|
{
|
||||||
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(new byte[]{buffer.get()}));
|
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(new byte[]{buffer.get()}));
|
||||||
if (decoded.hasRemaining())
|
if (decoded.hasRemaining())
|
||||||
result += Charset.forName("UTF-8").decode(decoded).toString();
|
result += StandardCharsets.UTF_8.decode(decoded).toString();
|
||||||
}
|
}
|
||||||
assertEquals(data, result);
|
assertEquals(data, result);
|
||||||
assertTrue(decoder.isFinished());
|
assertTrue(decoder.isFinished());
|
||||||
|
@ -263,12 +264,12 @@ public class GZIPContentDecoderTest
|
||||||
data1 += data1;
|
data1 += data1;
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
GZIPOutputStream output = new GZIPOutputStream(baos);
|
GZIPOutputStream output = new GZIPOutputStream(baos);
|
||||||
output.write(data1.getBytes("UTF-8"));
|
output.write(data1.getBytes(StandardCharsets.UTF_8));
|
||||||
output.close();
|
output.close();
|
||||||
byte[] bytes1 = baos.toByteArray();
|
byte[] bytes1 = baos.toByteArray();
|
||||||
|
|
||||||
String data2 = "HELLO";
|
String data2 = "HELLO";
|
||||||
byte[] bytes2 = data2.getBytes("UTF-8");
|
byte[] bytes2 = data2.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
byte[] bytes = new byte[bytes1.length + bytes2.length];
|
byte[] bytes = new byte[bytes1.length + bytes2.length];
|
||||||
System.arraycopy(bytes1, 0, bytes, 0, bytes1.length);
|
System.arraycopy(bytes1, 0, bytes, 0, bytes1.length);
|
||||||
|
@ -281,12 +282,12 @@ public class GZIPContentDecoderTest
|
||||||
{
|
{
|
||||||
ByteBuffer decoded = decoder.decode(buffer);
|
ByteBuffer decoded = decoder.decode(buffer);
|
||||||
if (decoded.hasRemaining())
|
if (decoded.hasRemaining())
|
||||||
result += Charset.forName("UTF-8").decode(decoded).toString();
|
result += StandardCharsets.UTF_8.decode(decoded).toString();
|
||||||
if (decoder.isFinished())
|
if (decoder.isFinished())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
assertEquals(data1, result);
|
assertEquals(data1, result);
|
||||||
assertTrue(buffer.hasRemaining());
|
assertTrue(buffer.hasRemaining());
|
||||||
assertEquals(data2, Charset.forName("UTF-8").decode(buffer).toString());
|
assertEquals(data2, StandardCharsets.UTF_8.decode(buffer).toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.client;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
@ -60,13 +61,13 @@ public class HttpClientContinueTest extends AbstractHttpClientServerTest
|
||||||
@Test
|
@Test
|
||||||
public void test_Expect100Continue_WithOneContent_Respond100Continue() throws Exception
|
public void test_Expect100Continue_WithOneContent_Respond100Continue() throws Exception
|
||||||
{
|
{
|
||||||
test_Expect100Continue_Respond100Continue("data1".getBytes("UTF-8"));
|
test_Expect100Continue_Respond100Continue("data1".getBytes(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_Expect100Continue_WithMultipleContents_Respond100Continue() throws Exception
|
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
|
private void test_Expect100Continue_Respond100Continue(byte[]... contents) throws Exception
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.client;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
@ -83,7 +84,7 @@ public class HttpClientProxyTest extends AbstractHttpClientServerTest
|
||||||
{
|
{
|
||||||
final String user = "foo";
|
final String user = "foo";
|
||||||
final String password = "bar";
|
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 serverHost = "server";
|
||||||
final String realm = "test_realm";
|
final String realm = "test_realm";
|
||||||
final int status = HttpStatus.NO_CONTENT_204;
|
final int status = HttpStatus.NO_CONTENT_204;
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.net.URI;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.UnresolvedAddressException;
|
import java.nio.channels.UnresolvedAddressException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
@ -171,10 +172,10 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
||||||
response.setCharacterEncoding("UTF-8");
|
response.setCharacterEncoding("UTF-8");
|
||||||
ServletOutputStream output = response.getOutputStream();
|
ServletOutputStream output = response.getOutputStream();
|
||||||
String paramValue1 = request.getParameter(paramName1);
|
String paramValue1 = request.getParameter(paramName1);
|
||||||
output.write(paramValue1.getBytes("UTF-8"));
|
output.write(paramValue1.getBytes(StandardCharsets.UTF_8));
|
||||||
String paramValue2 = request.getParameter(paramName2);
|
String paramValue2 = request.getParameter(paramName2);
|
||||||
Assert.assertEquals("", paramValue2);
|
Assert.assertEquals("", paramValue2);
|
||||||
output.write("empty".getBytes("UTF-8"));
|
output.write("empty".getBytes(StandardCharsets.UTF_8));
|
||||||
baseRequest.setHandled(true);
|
baseRequest.setHandled(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -186,7 +187,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
||||||
|
|
||||||
Assert.assertNotNull(response);
|
Assert.assertNotNull(response);
|
||||||
Assert.assertEquals(200, response.getStatus());
|
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);
|
Assert.assertEquals(value1 + "empty", content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,9 +205,9 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
||||||
ServletOutputStream output = response.getOutputStream();
|
ServletOutputStream output = response.getOutputStream();
|
||||||
String[] paramValues1 = request.getParameterValues(paramName1);
|
String[] paramValues1 = request.getParameterValues(paramName1);
|
||||||
for (String paramValue : paramValues1)
|
for (String paramValue : paramValues1)
|
||||||
output.write(paramValue.getBytes("UTF-8"));
|
output.write(paramValue.getBytes(StandardCharsets.UTF_8));
|
||||||
String paramValue2 = request.getParameter(paramName2);
|
String paramValue2 = request.getParameter(paramName2);
|
||||||
output.write(paramValue2.getBytes("UTF-8"));
|
output.write(paramValue2.getBytes(StandardCharsets.UTF_8));
|
||||||
baseRequest.setHandled(true);
|
baseRequest.setHandled(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -222,7 +223,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
||||||
|
|
||||||
Assert.assertNotNull(response);
|
Assert.assertNotNull(response);
|
||||||
Assert.assertEquals(200, response.getStatus());
|
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);
|
Assert.assertEquals(value11 + value12 + value2, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +255,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
||||||
|
|
||||||
Assert.assertNotNull(response);
|
Assert.assertNotNull(response);
|
||||||
Assert.assertEquals(200, response.getStatus());
|
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
|
@Test
|
||||||
|
@ -286,7 +287,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
||||||
|
|
||||||
Assert.assertNotNull(response);
|
Assert.assertNotNull(response);
|
||||||
Assert.assertEquals(200, response.getStatus());
|
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
|
@Test
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -126,7 +127,7 @@ public class HttpReceiverTest
|
||||||
Assert.assertNotNull(headers);
|
Assert.assertNotNull(headers);
|
||||||
Assert.assertEquals(1, headers.size());
|
Assert.assertEquals(1, headers.size());
|
||||||
Assert.assertEquals(String.valueOf(content.length()), headers.get(HttpHeader.CONTENT_LENGTH));
|
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);
|
Assert.assertEquals(content, received);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.client;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -191,7 +192,7 @@ public class HttpSenderTest
|
||||||
HttpConnection connection = new HttpConnection(client, endPoint, destination);
|
HttpConnection connection = new HttpConnection(client, endPoint, destination);
|
||||||
Request request = client.newRequest(URI.create("http://localhost/"));
|
Request request = client.newRequest(URI.create("http://localhost/"));
|
||||||
String content = "abcdef";
|
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 headersLatch = new CountDownLatch(1);
|
||||||
final CountDownLatch successLatch = new CountDownLatch(1);
|
final CountDownLatch successLatch = new CountDownLatch(1);
|
||||||
request.listener(new Request.Listener.Empty()
|
request.listener(new Request.Listener.Empty()
|
||||||
|
@ -226,7 +227,7 @@ public class HttpSenderTest
|
||||||
Request request = client.newRequest(URI.create("http://localhost/"));
|
Request request = client.newRequest(URI.create("http://localhost/"));
|
||||||
String content1 = "0123456789";
|
String content1 = "0123456789";
|
||||||
String content2 = "abcdef";
|
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 headersLatch = new CountDownLatch(1);
|
||||||
final CountDownLatch successLatch = new CountDownLatch(1);
|
final CountDownLatch successLatch = new CountDownLatch(1);
|
||||||
request.listener(new Request.Listener.Empty()
|
request.listener(new Request.Listener.Empty()
|
||||||
|
@ -261,7 +262,7 @@ public class HttpSenderTest
|
||||||
Request request = client.newRequest(URI.create("http://localhost/"));
|
Request request = client.newRequest(URI.create("http://localhost/"));
|
||||||
String content1 = "0123456789";
|
String content1 = "0123456789";
|
||||||
String content2 = "ABCDEF";
|
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
|
@Override
|
||||||
public long getLength()
|
public long getLength()
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.OutputStream;
|
||||||
import java.net.HttpCookie;
|
import java.net.HttpCookie;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -269,7 +270,7 @@ public class Usage
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new HttpClient();
|
||||||
client.start();
|
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)
|
ContentResponse response = client.newRequest("localhost", 8080)
|
||||||
// Provide the content as InputStream
|
// Provide the content as InputStream
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
@ -151,7 +152,7 @@ public class SslBytesClientTest extends SslBytesTest
|
||||||
|
|
||||||
SimpleProxy.AutomaticFlow automaticProxyFlow = proxy.startAutomaticFlow();
|
SimpleProxy.AutomaticFlow automaticProxyFlow = proxy.startAutomaticFlow();
|
||||||
// Read request
|
// 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();
|
String line = reader.readLine();
|
||||||
Assert.assertTrue(line.startsWith("GET"));
|
Assert.assertTrue(line.startsWith("GET"));
|
||||||
while (line.length() > 0)
|
while (line.length() > 0)
|
||||||
|
@ -161,7 +162,7 @@ public class SslBytesClientTest extends SslBytesTest
|
||||||
OutputStream output = server.getOutputStream();
|
OutputStream output = server.getOutputStream();
|
||||||
output.write(("HTTP/1.1 200 OK\r\n" +
|
output.write(("HTTP/1.1 200 OK\r\n" +
|
||||||
"Content-Length: 0\r\n" +
|
"Content-Length: 0\r\n" +
|
||||||
"\r\n").getBytes("UTF-8"));
|
"\r\n").getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
|
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
|
||||||
|
|
||||||
|
@ -197,7 +198,7 @@ public class SslBytesClientTest extends SslBytesTest
|
||||||
|
|
||||||
// Read request
|
// Read request
|
||||||
InputStream serverInput = server.getInputStream();
|
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();
|
String line = reader.readLine();
|
||||||
Assert.assertTrue(line.startsWith("GET"));
|
Assert.assertTrue(line.startsWith("GET"));
|
||||||
while (line.length() > 0)
|
while (line.length() > 0)
|
||||||
|
@ -206,16 +207,16 @@ public class SslBytesClientTest extends SslBytesTest
|
||||||
OutputStream serverOutput = server.getOutputStream();
|
OutputStream serverOutput = server.getOutputStream();
|
||||||
byte[] data1 = new byte[1024];
|
byte[] data1 = new byte[1024];
|
||||||
Arrays.fill(data1, (byte)'X');
|
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];
|
byte[] data2 = new byte[1024];
|
||||||
Arrays.fill(data2, (byte)'Y');
|
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
|
// Write first part of the response
|
||||||
serverOutput.write(("HTTP/1.1 200 OK\r\n" +
|
serverOutput.write(("HTTP/1.1 200 OK\r\n" +
|
||||||
"Content-Type: text/plain\r\n" +
|
"Content-Type: text/plain\r\n" +
|
||||||
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
|
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
content1).getBytes("UTF-8"));
|
content1).getBytes(StandardCharsets.UTF_8));
|
||||||
serverOutput.flush();
|
serverOutput.flush();
|
||||||
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
|
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
|
||||||
|
|
||||||
|
@ -319,7 +320,7 @@ public class SslBytesClientTest extends SslBytesTest
|
||||||
|
|
||||||
// Read request
|
// Read request
|
||||||
InputStream serverInput = server.getInputStream();
|
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();
|
String line = reader.readLine();
|
||||||
Assert.assertTrue(line.startsWith("GET"));
|
Assert.assertTrue(line.startsWith("GET"));
|
||||||
while (line.length() > 0)
|
while (line.length() > 0)
|
||||||
|
@ -328,16 +329,16 @@ public class SslBytesClientTest extends SslBytesTest
|
||||||
OutputStream serverOutput = server.getOutputStream();
|
OutputStream serverOutput = server.getOutputStream();
|
||||||
byte[] data1 = new byte[1024];
|
byte[] data1 = new byte[1024];
|
||||||
Arrays.fill(data1, (byte)'X');
|
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];
|
byte[] data2 = new byte[1024];
|
||||||
Arrays.fill(data2, (byte)'Y');
|
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
|
// Write first part of the response
|
||||||
serverOutput.write(("HTTP/1.1 200 OK\r\n" +
|
serverOutput.write(("HTTP/1.1 200 OK\r\n" +
|
||||||
"Content-Type: text/plain\r\n" +
|
"Content-Type: text/plain\r\n" +
|
||||||
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
|
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
content1).getBytes("UTF-8"));
|
content1).getBytes(StandardCharsets.UTF_8));
|
||||||
serverOutput.flush();
|
serverOutput.flush();
|
||||||
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
|
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.net.SocketTimeoutException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.SelectionKey;
|
import java.nio.channels.SelectionKey;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
@ -575,7 +576,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
clientOutput.write(("" +
|
clientOutput.write(("" +
|
||||||
"GET / HTTP/1.1\r\n" +
|
"GET / HTTP/1.1\r\n" +
|
||||||
"Host: localhost\r\n" +
|
"Host: localhost\r\n" +
|
||||||
"\r\n").getBytes("UTF-8"));
|
"\r\n").getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -617,7 +618,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
clientOutput.write(("" +
|
clientOutput.write(("" +
|
||||||
"GET / HTTP/1.1\r\n" +
|
"GET / HTTP/1.1\r\n" +
|
||||||
"Host: localhost\r\n" +
|
"Host: localhost\r\n" +
|
||||||
"\r\n").getBytes("UTF-8"));
|
"\r\n").getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -633,7 +634,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
|
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
|
||||||
proxy.flushToClient(record);
|
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();
|
String line = reader.readLine();
|
||||||
Assert.assertNotNull(line);
|
Assert.assertNotNull(line);
|
||||||
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
|
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
|
||||||
|
@ -710,7 +711,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
clientOutput.write(("" +
|
clientOutput.write(("" +
|
||||||
"GET / HTTP/1.1\r\n" +
|
"GET / HTTP/1.1\r\n" +
|
||||||
"Host: localhost\r\n" +
|
"Host: localhost\r\n" +
|
||||||
"\r\n").getBytes("UTF-8"));
|
"\r\n").getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -727,7 +728,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
|
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
|
||||||
proxy.flushToClient(record);
|
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();
|
String line = reader.readLine();
|
||||||
Assert.assertNotNull(line);
|
Assert.assertNotNull(line);
|
||||||
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
|
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
|
||||||
|
@ -782,7 +783,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
clientOutput.write(("" +
|
clientOutput.write(("" +
|
||||||
"GET / HTTP/1.1\r\n" +
|
"GET / HTTP/1.1\r\n" +
|
||||||
"Host: localhost\r\n" +
|
"Host: localhost\r\n" +
|
||||||
"\r\n").getBytes("UTF-8"));
|
"\r\n").getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -850,7 +851,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
clientOutput.write(("" +
|
clientOutput.write(("" +
|
||||||
"GET / HTTP/1.1\r\n" +
|
"GET / HTTP/1.1\r\n" +
|
||||||
"Host: localhost\r\n" +
|
"Host: localhost\r\n" +
|
||||||
"\r\n").getBytes("UTF-8"));
|
"\r\n").getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -913,7 +914,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
clientOutput.write(("" +
|
clientOutput.write(("" +
|
||||||
"GET / HTTP/1.1\r\n" +
|
"GET / HTTP/1.1\r\n" +
|
||||||
"Host: localhost\r\n" +
|
"Host: localhost\r\n" +
|
||||||
"\r\n").getBytes("UTF-8"));
|
"\r\n").getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -964,7 +965,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
clientOutput.write(("" +
|
clientOutput.write(("" +
|
||||||
"GET / HTTP/1.1\r\n" +
|
"GET / HTTP/1.1\r\n" +
|
||||||
"Host: localhost\r\n" +
|
"Host: localhost\r\n" +
|
||||||
"\r\n").getBytes("UTF-8"));
|
"\r\n").getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1007,7 +1008,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
|
|
||||||
byte[] data = new byte[128 * 1024];
|
byte[] data = new byte[128 * 1024];
|
||||||
Arrays.fill(data, (byte)'X');
|
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>()
|
Future<Object> request = threadPool.submit(new Callable<Object>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -1019,7 +1020,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
"Host: localhost\r\n" +
|
"Host: localhost\r\n" +
|
||||||
"Content-Length: " + content.length() + "\r\n" +
|
"Content-Length: " + content.length() + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
content).getBytes("UTF-8"));
|
content).getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1065,7 +1066,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
|
|
||||||
byte[] data = new byte[128 * 1024];
|
byte[] data = new byte[128 * 1024];
|
||||||
Arrays.fill(data, (byte)'X');
|
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>()
|
Future<Object> request = threadPool.submit(new Callable<Object>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -1077,7 +1078,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
"Host: localhost\r\n" +
|
"Host: localhost\r\n" +
|
||||||
"Content-Length: " + content.length() + "\r\n" +
|
"Content-Length: " + content.length() + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
content).getBytes("UTF-8"));
|
content).getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1139,7 +1140,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
clientOutput.write(("" +
|
clientOutput.write(("" +
|
||||||
"GET / HTTP/1.1\r\n" +
|
"GET / HTTP/1.1\r\n" +
|
||||||
"Host: localhost\r\n" +
|
"Host: localhost\r\n" +
|
||||||
"\r\n").getBytes("UTF-8"));
|
"\r\n").getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1211,7 +1212,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
"Content-Type: text/plain\r\n" +
|
"Content-Type: text/plain\r\n" +
|
||||||
"Content-Length: " + content.length() + "\r\n" +
|
"Content-Length: " + content.length() + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
content).getBytes("UTF-8"));
|
content).getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1232,7 +1233,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
|
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
|
||||||
proxy.flushToClient(record);
|
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();
|
String line = reader.readLine();
|
||||||
Assert.assertNotNull(line);
|
Assert.assertNotNull(line);
|
||||||
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
|
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)
|
// Use a content that is larger than the TLS record which is 2^14 (around 16k)
|
||||||
byte[] data = new byte[128 * 1024];
|
byte[] data = new byte[128 * 1024];
|
||||||
Arrays.fill(data, (byte)'X');
|
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>()
|
Future<Object> request = threadPool.submit(new Callable<Object>()
|
||||||
{
|
{
|
||||||
|
@ -1277,7 +1278,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
"Content-Type: text/plain\r\n" +
|
"Content-Type: text/plain\r\n" +
|
||||||
"Content-Length: " + content.length() + "\r\n" +
|
"Content-Length: " + content.length() + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
content).getBytes("UTF-8"));
|
content).getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1309,7 +1310,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
|
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
|
||||||
proxy.flushToClient(record);
|
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();
|
String line = reader.readLine();
|
||||||
Assert.assertNotNull(line);
|
Assert.assertNotNull(line);
|
||||||
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
|
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
|
||||||
|
@ -1344,10 +1345,10 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
|
|
||||||
byte[] data1 = new byte[1024];
|
byte[] data1 = new byte[1024];
|
||||||
Arrays.fill(data1, (byte)'X');
|
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];
|
byte[] data2 = new byte[1024];
|
||||||
Arrays.fill(data2, (byte)'Y');
|
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
|
// Write only part of the body
|
||||||
automaticProxyFlow = proxy.startAutomaticFlow();
|
automaticProxyFlow = proxy.startAutomaticFlow();
|
||||||
|
@ -1357,7 +1358,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
"Content-Type: text/plain\r\n" +
|
"Content-Type: text/plain\r\n" +
|
||||||
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
|
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
content1).getBytes("UTF-8"));
|
content1).getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
|
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
|
||||||
|
|
||||||
|
@ -1391,7 +1392,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
@Override
|
@Override
|
||||||
public Object call() throws Exception
|
public Object call() throws Exception
|
||||||
{
|
{
|
||||||
clientOutput.write(content2.getBytes("UTF-8"));
|
clientOutput.write(content2.getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
return null;
|
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)
|
// Use a content that is larger than the TLS record which is 2^14 (around 16k)
|
||||||
byte[] data1 = new byte[80 * 1024];
|
byte[] data1 = new byte[80 * 1024];
|
||||||
Arrays.fill(data1, (byte)'X');
|
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];
|
byte[] data2 = new byte[48 * 1024];
|
||||||
Arrays.fill(data2, (byte)'Y');
|
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
|
// Write only part of the body
|
||||||
automaticProxyFlow = proxy.startAutomaticFlow();
|
automaticProxyFlow = proxy.startAutomaticFlow();
|
||||||
|
@ -1448,7 +1449,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
"Content-Type: text/plain\r\n" +
|
"Content-Type: text/plain\r\n" +
|
||||||
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
|
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
content1).getBytes("UTF-8"));
|
content1).getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
|
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
|
||||||
|
|
||||||
|
@ -1513,7 +1514,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
@Override
|
@Override
|
||||||
public Object call() throws Exception
|
public Object call() throws Exception
|
||||||
{
|
{
|
||||||
clientOutput.write(content2.getBytes("UTF-8"));
|
clientOutput.write(content2.getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1535,7 +1536,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
|
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
|
||||||
proxy.flushToClient(record);
|
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();
|
String line = reader.readLine();
|
||||||
Assert.assertNotNull(line);
|
Assert.assertNotNull(line);
|
||||||
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
|
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)
|
// Use a content that is larger than the TLS record which is 2^14 (around 16k)
|
||||||
byte[] data1 = new byte[80 * 1024];
|
byte[] data1 = new byte[80 * 1024];
|
||||||
Arrays.fill(data1, (byte)'X');
|
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];
|
byte[] data2 = new byte[48 * 1024];
|
||||||
Arrays.fill(data2, (byte)'Y');
|
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
|
// Write only part of the body
|
||||||
automaticProxyFlow = proxy.startAutomaticFlow();
|
automaticProxyFlow = proxy.startAutomaticFlow();
|
||||||
|
@ -1582,7 +1583,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
"Content-Type: text/plain\r\n" +
|
"Content-Type: text/plain\r\n" +
|
||||||
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
|
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
content1).getBytes("UTF-8"));
|
content1).getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
|
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
|
||||||
|
|
||||||
|
@ -1665,7 +1666,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
@Override
|
@Override
|
||||||
public Object call() throws Exception
|
public Object call() throws Exception
|
||||||
{
|
{
|
||||||
clientOutput.write(content2.getBytes("UTF-8"));
|
clientOutput.write(content2.getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1697,7 +1698,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
|
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
|
||||||
proxy.flushToClient(record);
|
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();
|
String line = reader.readLine();
|
||||||
Assert.assertNotNull(line);
|
Assert.assertNotNull(line);
|
||||||
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
|
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
|
||||||
|
@ -1728,7 +1729,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
|
|
||||||
byte[] data = new byte[3 * 1024];
|
byte[] data = new byte[3 * 1024];
|
||||||
Arrays.fill(data, (byte)'Y');
|
Arrays.fill(data, (byte)'Y');
|
||||||
String content = new String(data, "UTF-8");
|
String content = new String(data, StandardCharsets.UTF_8);
|
||||||
automaticProxyFlow = proxy.startAutomaticFlow();
|
automaticProxyFlow = proxy.startAutomaticFlow();
|
||||||
clientOutput.write(("" +
|
clientOutput.write(("" +
|
||||||
"POST / HTTP/1.1\r\n" +
|
"POST / HTTP/1.1\r\n" +
|
||||||
|
@ -1737,10 +1738,10 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
"Content-Length: " + content.length() + "\r\n" +
|
"Content-Length: " + content.length() + "\r\n" +
|
||||||
"Connection: close\r\n" +
|
"Connection: close\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
content).getBytes("UTF-8"));
|
content).getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
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();
|
String line = reader.readLine();
|
||||||
Assert.assertNotNull(line);
|
Assert.assertNotNull(line);
|
||||||
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
|
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
|
// 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
|
// We expect that the server closes the connection immediately
|
||||||
TLSRecord record = proxy.readFromServer();
|
TLSRecord record = proxy.readFromServer();
|
||||||
|
@ -1820,7 +1821,7 @@ public class SslBytesServerTest extends SslBytesTest
|
||||||
clientOutput.write(("" +
|
clientOutput.write(("" +
|
||||||
"GET / HTTP/1.1\r\n" +
|
"GET / HTTP/1.1\r\n" +
|
||||||
"Host: localhost\r\n" +
|
"Host: localhost\r\n" +
|
||||||
"\r\n").getBytes("UTF-8"));
|
"\r\n").getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutput.flush();
|
clientOutput.flush();
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.http;
|
package org.eclipse.jetty.http;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -176,7 +177,7 @@ public class HttpField
|
||||||
|
|
||||||
private static byte[] toSanitisedName(String s)
|
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;)
|
for (int i=bytes.length;i-->0;)
|
||||||
{
|
{
|
||||||
switch(bytes[i])
|
switch(bytes[i])
|
||||||
|
@ -192,7 +193,7 @@ public class HttpField
|
||||||
|
|
||||||
private static byte[] toSanitisedValue(String s)
|
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;)
|
for (int i=bytes.length;i-->0;)
|
||||||
{
|
{
|
||||||
switch(bytes[i])
|
switch(bytes[i])
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.http;
|
package org.eclipse.jetty.http;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.eclipse.jetty.http.HttpTokens.EndOfContent;
|
import org.eclipse.jetty.http.HttpTokens.EndOfContent;
|
||||||
import org.eclipse.jetty.util.ArrayTernaryTrie;
|
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
|
// Have to get the fields exactly from the buffer to match case
|
||||||
String fn=field.getName();
|
String fn=field.getName();
|
||||||
String fv=field.getValue();
|
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)
|
if (fv==null)
|
||||||
v=null;
|
v=null;
|
||||||
else
|
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);
|
field=new HttpField(field.getHeader(),n,v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.eclipse.jetty.http.HttpGenerator.RequestInfo;
|
import org.eclipse.jetty.http.HttpGenerator.RequestInfo;
|
||||||
import org.eclipse.jetty.http.HttpGenerator.ResponseInfo;
|
import org.eclipse.jetty.http.HttpGenerator.ResponseInfo;
|
||||||
|
@ -346,7 +347,7 @@ public class HttpTester
|
||||||
|
|
||||||
String content_type=get(HttpHeader.CONTENT_TYPE);
|
String content_type=get(HttpHeader.CONTENT_TYPE);
|
||||||
String encoding=MimeTypes.getCharsetFromContentType(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);
|
return new String(bytes,charset);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.http;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.MultiMap;
|
import org.eclipse.jetty.util.MultiMap;
|
||||||
import org.eclipse.jetty.util.StringUtil;
|
import org.eclipse.jetty.util.StringUtil;
|
||||||
|
@ -100,15 +101,7 @@ public class HttpURI
|
||||||
public HttpURI(String raw)
|
public HttpURI(String raw)
|
||||||
{
|
{
|
||||||
_rawString=raw;
|
_rawString=raw;
|
||||||
byte[] b;
|
byte[] b = raw.getBytes(StandardCharsets.UTF_8);
|
||||||
try
|
|
||||||
{
|
|
||||||
b = raw.getBytes(StringUtil.__UTF8);
|
|
||||||
}
|
|
||||||
catch (UnsupportedEncodingException e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(e.getMessage());
|
|
||||||
}
|
|
||||||
parse(b,0,b.length);
|
parse(b,0,b.length);
|
||||||
_charset = URIUtil.__CHARSET;
|
_charset = URIUtil.__CHARSET;
|
||||||
}
|
}
|
||||||
|
@ -619,6 +612,11 @@ public class HttpURI
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDecodedPath(String encoding)
|
public String getDecodedPath(String encoding)
|
||||||
|
{
|
||||||
|
return getDecodedPath(Charset.forName(encoding));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDecodedPath(Charset encoding)
|
||||||
{
|
{
|
||||||
if (_path==_param)
|
if (_path==_param)
|
||||||
return null;
|
return null;
|
||||||
|
@ -678,9 +676,9 @@ public class HttpURI
|
||||||
|
|
||||||
|
|
||||||
if (bytes==null)
|
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()
|
public String getPathAndParam()
|
||||||
|
@ -734,10 +732,10 @@ public class HttpURI
|
||||||
{
|
{
|
||||||
if (_query==_fragment)
|
if (_query==_fragment)
|
||||||
return;
|
return;
|
||||||
if (_charset==StringUtil.__UTF8_CHARSET)
|
if (_charset.equals(StandardCharsets.UTF_8))
|
||||||
UrlEncoded.decodeUtf8To(_raw,_query+1,_fragment-_query-1,parameters);
|
UrlEncoded.decodeUtf8To(_raw,_query+1,_fragment-_query-1,parameters);
|
||||||
else
|
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
|
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);
|
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()
|
public void clear()
|
||||||
{
|
{
|
||||||
_scheme=_authority=_host=_port=_path=_param=_query=_fragment=_end=0;
|
_scheme=_authority=_host=_port=_path=_param=_query=_fragment=_end=0;
|
||||||
|
|
|
@ -24,6 +24,7 @@ import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -112,7 +113,7 @@ public class HttpParserTest
|
||||||
@Test
|
@Test
|
||||||
public void testLineParse3() throws Exception
|
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.RequestHandler<ByteBuffer> handler = new Handler();
|
||||||
HttpParser parser= new HttpParser(handler);
|
HttpParser parser= new HttpParser(handler);
|
||||||
|
@ -126,7 +127,7 @@ public class HttpParserTest
|
||||||
@Test
|
@Test
|
||||||
public void testLineParse4() throws Exception
|
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.RequestHandler<ByteBuffer> handler = new Handler();
|
||||||
HttpParser parser= new HttpParser(handler);
|
HttpParser parser= new HttpParser(handler);
|
||||||
|
@ -321,10 +322,10 @@ public class HttpParserTest
|
||||||
ByteBuffer buffer=BufferUtil.allocate(4096);
|
ByteBuffer buffer=BufferUtil.allocate(4096);
|
||||||
BufferUtil.flipToFill(buffer);
|
BufferUtil.flipToFill(buffer);
|
||||||
BufferUtil.put(BufferUtil.toBuffer("GET "),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(" HTTP/1.0\r\n"),buffer);
|
||||||
BufferUtil.put(BufferUtil.toBuffer("Header1: "),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.put(BufferUtil.toBuffer(" \r\n\r\n"),buffer);
|
||||||
BufferUtil.flipToFlush(buffer,0);
|
BufferUtil.flipToFlush(buffer,0);
|
||||||
|
|
||||||
|
@ -1165,7 +1166,7 @@ public class HttpParserTest
|
||||||
{
|
{
|
||||||
if (_content==null)
|
if (_content==null)
|
||||||
_content="";
|
_content="";
|
||||||
String c = BufferUtil.toString(ref,StringUtil.__UTF8_CHARSET);
|
String c = BufferUtil.toString(ref,StandardCharsets.UTF_8);
|
||||||
//System.err.println("content '"+c+"'");
|
//System.err.println("content '"+c+"'");
|
||||||
_content= _content + c;
|
_content= _content + c;
|
||||||
ref.position(ref.limit());
|
ref.position(ref.limit());
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.net.InetSocketAddress;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.ClosedChannelException;
|
import java.nio.channels.ClosedChannelException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.BufferUtil;
|
import org.eclipse.jetty.util.BufferUtil;
|
||||||
import org.eclipse.jetty.util.StringUtil;
|
import org.eclipse.jetty.util.StringUtil;
|
||||||
|
@ -153,7 +154,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
public void setInput(String s)
|
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()
|
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()
|
public String takeOutputString()
|
||||||
{
|
{
|
||||||
return takeOutputString(StringUtil.__UTF8_CHARSET);
|
return takeOutputString(StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.io;
|
package org.eclipse.jetty.io;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.Callback;
|
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
|
* and when the {@link EndPoint} signals read readyness, this {@link Connection} can
|
||||||
* read bytes from the network and interpret them.</p>
|
* read bytes from the network and interpret them.</p>
|
||||||
*/
|
*/
|
||||||
public interface Connection extends AutoCloseable
|
public interface Connection extends Closeable
|
||||||
{
|
{
|
||||||
public void addListener(Listener listener);
|
public void addListener(Listener listener);
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,6 @@ import java.net.Socket;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.nio.channels.CancelledKeyException;
|
import java.nio.channels.CancelledKeyException;
|
||||||
import java.nio.channels.ClosedChannelException;
|
|
||||||
import java.nio.channels.ClosedSelectorException;
|
|
||||||
import java.nio.channels.SelectionKey;
|
import java.nio.channels.SelectionKey;
|
||||||
import java.nio.channels.Selector;
|
import java.nio.channels.Selector;
|
||||||
import java.nio.channels.ServerSocketChannel;
|
import java.nio.channels.ServerSocketChannel;
|
||||||
|
@ -229,7 +227,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
||||||
{
|
{
|
||||||
connection.onOpen();
|
connection.onOpen();
|
||||||
}
|
}
|
||||||
catch (Exception x)
|
catch (Throwable x)
|
||||||
{
|
{
|
||||||
if (isRunning())
|
if (isRunning())
|
||||||
LOG.warn("Exception while notifying connection " + connection, x);
|
LOG.warn("Exception while notifying connection " + connection, x);
|
||||||
|
@ -249,9 +247,9 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
||||||
{
|
{
|
||||||
connection.onClose();
|
connection.onClose();
|
||||||
}
|
}
|
||||||
catch (Exception x)
|
catch (Throwable x)
|
||||||
{
|
{
|
||||||
LOG.info("Exception while notifying connection " + connection, x);
|
LOG.debug("Exception while notifying connection " + connection, x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,10 +403,17 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void runChange(Runnable change)
|
protected void runChange(Runnable change)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
LOG.debug("Running change {}", change);
|
LOG.debug("Running change {}", change);
|
||||||
change.run();
|
change.run();
|
||||||
}
|
}
|
||||||
|
catch (Throwable x)
|
||||||
|
{
|
||||||
|
LOG.debug("Could not run change " + change, x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
|
@ -468,7 +473,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
||||||
}
|
}
|
||||||
selectedKeys.clear();
|
selectedKeys.clear();
|
||||||
}
|
}
|
||||||
catch (Exception x)
|
catch (Throwable x)
|
||||||
{
|
{
|
||||||
if (isRunning())
|
if (isRunning())
|
||||||
LOG.warn(x);
|
LOG.warn(x);
|
||||||
|
@ -515,7 +520,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
||||||
if (attachment instanceof EndPoint)
|
if (attachment instanceof EndPoint)
|
||||||
((EndPoint)attachment).close();
|
((EndPoint)attachment).close();
|
||||||
}
|
}
|
||||||
catch (Exception x)
|
catch (Throwable x)
|
||||||
{
|
{
|
||||||
LOG.warn("Could not process key for channel " + key.channel(), x);
|
LOG.warn("Could not process key for channel " + key.channel(), x);
|
||||||
if (attachment instanceof EndPoint)
|
if (attachment instanceof EndPoint)
|
||||||
|
@ -525,10 +530,10 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
||||||
|
|
||||||
private void processConnect(SelectionKey key, Connect connect)
|
private void processConnect(SelectionKey key, Connect connect)
|
||||||
{
|
{
|
||||||
key.attach(connect.attachment);
|
|
||||||
SocketChannel channel = (SocketChannel)key.channel();
|
SocketChannel channel = (SocketChannel)key.channel();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
key.attach(connect.attachment);
|
||||||
boolean connected = finishConnect(channel);
|
boolean connected = finishConnect(channel);
|
||||||
if (connected)
|
if (connected)
|
||||||
{
|
{
|
||||||
|
@ -542,10 +547,9 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
||||||
throw new ConnectException();
|
throw new ConnectException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception x)
|
catch (Throwable x)
|
||||||
{
|
{
|
||||||
connect.failed(x);
|
connect.failed(x);
|
||||||
closeNoExceptions(channel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -555,7 +559,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
||||||
{
|
{
|
||||||
closeable.close();
|
closeable.close();
|
||||||
}
|
}
|
||||||
catch (IOException x)
|
catch (Throwable x)
|
||||||
{
|
{
|
||||||
LOG.ignore(x);
|
LOG.ignore(x);
|
||||||
}
|
}
|
||||||
|
@ -702,8 +706,9 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
||||||
EndPoint endpoint = createEndPoint(_channel, key);
|
EndPoint endpoint = createEndPoint(_channel, key);
|
||||||
key.attach(endpoint);
|
key.attach(endpoint);
|
||||||
}
|
}
|
||||||
catch (IOException x)
|
catch (Throwable x)
|
||||||
{
|
{
|
||||||
|
closeNoExceptions(_channel);
|
||||||
LOG.debug(x);
|
LOG.debug(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -730,18 +735,22 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
||||||
{
|
{
|
||||||
channel.register(_selector, SelectionKey.OP_CONNECT, this);
|
channel.register(_selector, SelectionKey.OP_CONNECT, this);
|
||||||
}
|
}
|
||||||
catch (ClosedSelectorException | ClosedChannelException x)
|
catch (Throwable x)
|
||||||
{
|
{
|
||||||
LOG.debug(x);
|
failed(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void failed(Throwable failure)
|
protected void failed(Throwable failure)
|
||||||
{
|
{
|
||||||
if (failed.compareAndSet(false, true))
|
if (failed.compareAndSet(false, true))
|
||||||
|
{
|
||||||
|
timeout.cancel();
|
||||||
|
closeNoExceptions(channel);
|
||||||
connectionFailed(channel, failure, attachment);
|
connectionFailed(channel, failure, attachment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class ConnectTimeout implements Runnable
|
private class ConnectTimeout implements Runnable
|
||||||
{
|
{
|
||||||
|
@ -759,22 +768,10 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
||||||
if (channel.isConnectionPending())
|
if (channel.isConnectionPending())
|
||||||
{
|
{
|
||||||
LOG.debug("Channel {} timed out while connecting, closing it", channel);
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private class Stop implements Runnable
|
private class Stop implements Runnable
|
||||||
{
|
{
|
||||||
|
@ -836,7 +833,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
endPoint.getConnection().close();
|
closeNoExceptions(endPoint.getConnection());
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.io;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
@ -33,14 +34,14 @@ import java.io.Writer;
|
||||||
public class WriterOutputStream extends OutputStream
|
public class WriterOutputStream extends OutputStream
|
||||||
{
|
{
|
||||||
protected final Writer _writer;
|
protected final Writer _writer;
|
||||||
protected final String _encoding;
|
protected final Charset _encoding;
|
||||||
private final byte[] _buf=new byte[1];
|
private final byte[] _buf=new byte[1];
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
public WriterOutputStream(Writer writer, String encoding)
|
public WriterOutputStream(Writer writer, String encoding)
|
||||||
{
|
{
|
||||||
_writer=writer;
|
_writer=writer;
|
||||||
_encoding=encoding;
|
_encoding=encoding==null?null:Charset.forName(encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
|
|
@ -26,14 +26,17 @@ import static org.junit.Assert.fail;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.net.SocketAddress;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.AsynchronousServerSocketChannel;
|
import java.nio.channels.AsynchronousServerSocketChannel;
|
||||||
import java.nio.channels.AsynchronousSocketChannel;
|
import java.nio.channels.AsynchronousSocketChannel;
|
||||||
import java.nio.channels.ServerSocketChannel;
|
import java.nio.channels.ServerSocketChannel;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -389,13 +392,10 @@ public class IOTest
|
||||||
@Test
|
@Test
|
||||||
public void testReset() throws Exception
|
public void testReset() throws Exception
|
||||||
{
|
{
|
||||||
ServerSocket connector;
|
try (ServerSocket connector = new ServerSocket(0);
|
||||||
Socket client;
|
Socket client = new Socket("127.0.0.1", connector.getLocalPort());
|
||||||
Socket server;
|
Socket server = connector.accept();)
|
||||||
|
{
|
||||||
connector = new ServerSocket(0);
|
|
||||||
client = new Socket("127.0.0.1", connector.getLocalPort());
|
|
||||||
server = connector.accept();
|
|
||||||
client.setTcpNoDelay(true);
|
client.setTcpNoDelay(true);
|
||||||
client.setSoLinger(true, 0);
|
client.setSoLinger(true, 0);
|
||||||
server.setTcpNoDelay(true);
|
server.setTcpNoDelay(true);
|
||||||
|
@ -426,23 +426,26 @@ public class IOTest
|
||||||
// Since output was already shutdown, server closes
|
// Since output was already shutdown, server closes
|
||||||
server.close();
|
server.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAsyncSocketChannel() throws Exception
|
public void testAsyncSocketChannel() throws Exception
|
||||||
{
|
{
|
||||||
AsynchronousServerSocketChannel connector = AsynchronousServerSocketChannel.open();
|
AsynchronousServerSocketChannel connector = AsynchronousServerSocketChannel.open();
|
||||||
connector.bind(null);
|
connector.bind(null);
|
||||||
|
InetSocketAddress addr=(InetSocketAddress)connector.getLocalAddress();
|
||||||
Future<AsynchronousSocketChannel> acceptor = connector.accept();
|
Future<AsynchronousSocketChannel> acceptor = connector.accept();
|
||||||
|
|
||||||
AsynchronousSocketChannel client = AsynchronousSocketChannel.open();
|
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);
|
AsynchronousSocketChannel server = acceptor.get(5, TimeUnit.SECONDS);
|
||||||
|
|
||||||
ByteBuffer read = ByteBuffer.allocate(1024);
|
ByteBuffer read = ByteBuffer.allocate(1024);
|
||||||
Future<Integer> reading = server.read(read);
|
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);
|
ByteBuffer write = BufferUtil.toBuffer(data);
|
||||||
Future<Integer> writing = client.write(write);
|
Future<Integer> writing = client.write(write);
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import javax.net.ssl.SSLEngine;
|
import javax.net.ssl.SSLEngine;
|
||||||
import javax.net.ssl.SSLEngineResult;
|
import javax.net.ssl.SSLEngineResult;
|
||||||
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
|
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
|
||||||
|
@ -170,7 +171,7 @@ public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest
|
||||||
if (debug) System.err.println("\nSay Hello");
|
if (debug) System.err.println("\nSay Hello");
|
||||||
|
|
||||||
// write a message
|
// write a message
|
||||||
appOut.put("HelloWorld".getBytes("UTF-8"));
|
appOut.put("HelloWorld".getBytes(StandardCharsets.UTF_8));
|
||||||
appOut.flip();
|
appOut.flip();
|
||||||
SSLEngineResult result =engine.wrap(appOut,sslOut);
|
SSLEngineResult result =engine.wrap(appOut,sslOut);
|
||||||
if (debug) System.err.println(result);
|
if (debug) System.err.println(result);
|
||||||
|
|
|
@ -29,6 +29,7 @@ import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.SelectionKey;
|
import java.nio.channels.SelectionKey;
|
||||||
import java.nio.channels.ServerSocketChannel;
|
import java.nio.channels.ServerSocketChannel;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -228,7 +229,7 @@ public class SelectChannelEndPointTest
|
||||||
_manager.accept(server);
|
_manager.accept(server);
|
||||||
|
|
||||||
// Write client to 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
|
// Verify echo server to client
|
||||||
for (char c : "HelloWorld".toCharArray())
|
for (char c : "HelloWorld".toCharArray())
|
||||||
|
@ -253,7 +254,7 @@ public class SelectChannelEndPointTest
|
||||||
}
|
}
|
||||||
|
|
||||||
// write then shutdown
|
// 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
|
// Verify echo server to client
|
||||||
for (char c : "Goodbye Cruel TLS".toCharArray())
|
for (char c : "Goodbye Cruel TLS".toCharArray())
|
||||||
|
@ -287,7 +288,7 @@ public class SelectChannelEndPointTest
|
||||||
_manager.accept(server);
|
_manager.accept(server);
|
||||||
|
|
||||||
// Write client to 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
|
// Verify echo server to client
|
||||||
for (char c : "HelloWorld".toCharArray())
|
for (char c : "HelloWorld".toCharArray())
|
||||||
|
@ -310,7 +311,7 @@ public class SelectChannelEndPointTest
|
||||||
}
|
}
|
||||||
|
|
||||||
// write then shutdown
|
// write then shutdown
|
||||||
client.getOutputStream().write("Goodbye Cruel TLS".getBytes("UTF-8"));
|
client.getOutputStream().write("Goodbye Cruel TLS".getBytes(StandardCharsets.UTF_8));
|
||||||
client.shutdownOutput();
|
client.shutdownOutput();
|
||||||
|
|
||||||
// Verify echo server to client
|
// Verify echo server to client
|
||||||
|
@ -343,7 +344,7 @@ public class SelectChannelEndPointTest
|
||||||
|
|
||||||
// Write 8 and cause block waiting for 10
|
// Write 8 and cause block waiting for 10
|
||||||
_blockAt = 10;
|
_blockAt = 10;
|
||||||
clientOutputStream.write("12345678".getBytes("UTF-8"));
|
clientOutputStream.write("12345678".getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutputStream.flush();
|
clientOutputStream.flush();
|
||||||
|
|
||||||
Assert.assertTrue(_lastEndPointLatch.await(1, TimeUnit.SECONDS));
|
Assert.assertTrue(_lastEndPointLatch.await(1, TimeUnit.SECONDS));
|
||||||
|
@ -363,7 +364,7 @@ public class SelectChannelEndPointTest
|
||||||
}
|
}
|
||||||
|
|
||||||
// write remaining characters
|
// write remaining characters
|
||||||
clientOutputStream.write("90ABCDEF".getBytes("UTF-8"));
|
clientOutputStream.write("90ABCDEF".getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutputStream.flush();
|
clientOutputStream.flush();
|
||||||
|
|
||||||
// Verify echo server to client
|
// Verify echo server to client
|
||||||
|
@ -388,7 +389,7 @@ public class SelectChannelEndPointTest
|
||||||
_manager.accept(server);
|
_manager.accept(server);
|
||||||
|
|
||||||
// Write client to 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
|
// Verify echo server to client
|
||||||
for (char c : "HelloWorld".toCharArray())
|
for (char c : "HelloWorld".toCharArray())
|
||||||
|
@ -436,7 +437,7 @@ public class SelectChannelEndPointTest
|
||||||
_manager.accept(server);
|
_manager.accept(server);
|
||||||
|
|
||||||
// Write client to server
|
// Write client to server
|
||||||
clientOutputStream.write("HelloWorld".getBytes("UTF-8"));
|
clientOutputStream.write("HelloWorld".getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
// Verify echo server to client
|
// Verify echo server to client
|
||||||
for (char c : "HelloWorld".toCharArray())
|
for (char c : "HelloWorld".toCharArray())
|
||||||
|
@ -452,7 +453,7 @@ public class SelectChannelEndPointTest
|
||||||
|
|
||||||
// Write 8 and cause block waiting for 10
|
// Write 8 and cause block waiting for 10
|
||||||
_blockAt = 10;
|
_blockAt = 10;
|
||||||
clientOutputStream.write("12345678".getBytes("UTF-8"));
|
clientOutputStream.write("12345678".getBytes(StandardCharsets.UTF_8));
|
||||||
clientOutputStream.flush();
|
clientOutputStream.flush();
|
||||||
|
|
||||||
// read until idle shutdown received
|
// read until idle shutdown received
|
||||||
|
@ -493,8 +494,8 @@ public class SelectChannelEndPointTest
|
||||||
_manager.accept(server);
|
_manager.accept(server);
|
||||||
final int writes = 200000;
|
final int writes = 200000;
|
||||||
|
|
||||||
final byte[] bytes = "HelloWorld-".getBytes(StringUtil.__UTF8_CHARSET);
|
final byte[] bytes = "HelloWorld-".getBytes(StandardCharsets.UTF_8);
|
||||||
byte[] count = "0\n".getBytes(StringUtil.__UTF8_CHARSET);
|
byte[] count = "0\n".getBytes(StandardCharsets.UTF_8);
|
||||||
BufferedOutputStream out = new BufferedOutputStream(client.getOutputStream());
|
BufferedOutputStream out = new BufferedOutputStream(client.getOutputStream());
|
||||||
final CountDownLatch latch = new CountDownLatch(writes);
|
final CountDownLatch latch = new CountDownLatch(writes);
|
||||||
final InputStream in = new BufferedInputStream(client.getInputStream());
|
final InputStream in = new BufferedInputStream(client.getInputStream());
|
||||||
|
@ -561,7 +562,7 @@ public class SelectChannelEndPointTest
|
||||||
for (int i = 1; i < writes; i++)
|
for (int i = 1; i < writes; i++)
|
||||||
{
|
{
|
||||||
out.write(bytes);
|
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');
|
out.write('\n');
|
||||||
if (i % 1000 == 0)
|
if (i % 1000 == 0)
|
||||||
{
|
{
|
||||||
|
@ -599,7 +600,7 @@ public class SelectChannelEndPointTest
|
||||||
// Write client to server
|
// Write client to server
|
||||||
_writeCount = 10000;
|
_writeCount = 10000;
|
||||||
String data = "Now is the time for all good men to come to the aid of the party";
|
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());
|
BufferedInputStream in = new BufferedInputStream(client.getInputStream());
|
||||||
|
|
||||||
int byteNum = 0;
|
int byteNum = 0;
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.SelectionKey;
|
import java.nio.channels.SelectionKey;
|
||||||
import java.nio.channels.ServerSocketChannel;
|
import java.nio.channels.ServerSocketChannel;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
@ -234,14 +235,14 @@ public class SslConnectionTest
|
||||||
server.configureBlocking(false);
|
server.configureBlocking(false);
|
||||||
_manager.accept(server);
|
_manager.accept(server);
|
||||||
|
|
||||||
client.getOutputStream().write("Hello".getBytes("UTF-8"));
|
client.getOutputStream().write("Hello".getBytes(StandardCharsets.UTF_8));
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
int len=client.getInputStream().read(buffer);
|
int len=client.getInputStream().read(buffer);
|
||||||
Assert.assertEquals(5, len);
|
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);
|
_dispatches.set(0);
|
||||||
client.getOutputStream().write("World".getBytes("UTF-8"));
|
client.getOutputStream().write("World".getBytes(StandardCharsets.UTF_8));
|
||||||
len=5;
|
len=5;
|
||||||
while(len>0)
|
while(len>0)
|
||||||
len-=client.getInputStream().read(buffer);
|
len-=client.getInputStream().read(buffer);
|
||||||
|
@ -266,7 +267,7 @@ public class SslConnectionTest
|
||||||
|
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
int len=client.getInputStream().read(buffer);
|
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));
|
Assert.assertEquals(null,_writeCallback.get(100,TimeUnit.MILLISECONDS));
|
||||||
client.close();
|
client.close();
|
||||||
}
|
}
|
||||||
|
@ -292,7 +293,7 @@ public class SslConnectionTest
|
||||||
{
|
{
|
||||||
try
|
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)
|
while(count.getCount()>0)
|
||||||
{
|
{
|
||||||
String line=in.readLine();
|
String line=in.readLine();
|
||||||
|
@ -311,7 +312,7 @@ public class SslConnectionTest
|
||||||
|
|
||||||
for (int i=0;i<LINES;i++)
|
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");
|
// System.err.println("wrote");
|
||||||
if (i%1000==0)
|
if (i%1000==0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.security.jaspi.modules;
|
package org.eclipse.jetty.security.jaspi.modules;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -119,7 +120,7 @@ public class BaseAuthModule implements ServerAuthModule, ServerAuthContext
|
||||||
throws IOException, UnsupportedCallbackException
|
throws IOException, UnsupportedCallbackException
|
||||||
{
|
{
|
||||||
credentials = credentials.substring(credentials.indexOf(' ')+1);
|
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(':');
|
int i = credentials.indexOf(':');
|
||||||
String userName = credentials.substring(0,i);
|
String userName = credentials.substring(0,i);
|
||||||
String password = credentials.substring(i+1);
|
String password = credentials.substring(i+1);
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.security.jaspi.modules;
|
package org.eclipse.jetty.security.jaspi.modules;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -306,18 +307,18 @@ public class DigestAuthModule extends BaseAuthModule
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// calc A1 digest
|
// calc A1 digest
|
||||||
md.update(username.getBytes(StringUtil.__ISO_8859_1));
|
md.update(username.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update(realm.getBytes(StringUtil.__ISO_8859_1));
|
md.update(realm.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update(password.getBytes(StringUtil.__ISO_8859_1));
|
md.update(password.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
ha1 = md.digest();
|
ha1 = md.digest();
|
||||||
}
|
}
|
||||||
// calc A2 digest
|
// calc A2 digest
|
||||||
md.reset();
|
md.reset();
|
||||||
md.update(method.getBytes(StringUtil.__ISO_8859_1));
|
md.update(method.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update(uri.getBytes(StringUtil.__ISO_8859_1));
|
md.update(uri.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
byte[] ha2 = md.digest();
|
byte[] ha2 = md.digest();
|
||||||
|
|
||||||
// calc digest
|
// calc digest
|
||||||
|
@ -327,17 +328,17 @@ public class DigestAuthModule extends BaseAuthModule
|
||||||
// request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2)
|
// 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((byte) ':');
|
||||||
md.update(nonce.getBytes(StringUtil.__ISO_8859_1));
|
md.update(nonce.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update(nc.getBytes(StringUtil.__ISO_8859_1));
|
md.update(nc.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update(cnonce.getBytes(StringUtil.__ISO_8859_1));
|
md.update(cnonce.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update(qop.getBytes(StringUtil.__ISO_8859_1));
|
md.update(qop.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
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();
|
byte[] digest = md.digest();
|
||||||
|
|
||||||
// check digest
|
// check digest
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.SSLSocket;
|
import javax.net.ssl.SSLSocket;
|
||||||
|
@ -78,7 +79,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 200 OK from the CONNECT request
|
// Expect 200 OK from the CONNECT request
|
||||||
|
@ -98,7 +99,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
|
||||||
"GET /echo HTTP/1.1\r\n" +
|
"GET /echo HTTP/1.1\r\n" +
|
||||||
"Host: " + hostPort + "\r\n" +
|
"Host: " + hostPort + "\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = readResponse(input);
|
response = readResponse(input);
|
||||||
|
@ -121,7 +122,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 200 OK from the CONNECT request
|
// Expect 200 OK from the CONNECT request
|
||||||
|
@ -145,7 +146,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
|
||||||
"Content-Length: 5\r\n" +
|
"Content-Length: 5\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
"HELLO";
|
"HELLO";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = readResponse(input);
|
response = readResponse(input);
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.io.OutputStream;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 200 OK from the CONNECT request
|
// Expect 200 OK from the CONNECT request
|
||||||
|
@ -93,7 +94,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 200 OK from the CONNECT request
|
// Expect 200 OK from the CONNECT request
|
||||||
|
@ -104,7 +105,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
"GET /echo" + " HTTP/1.1\r\n" +
|
"GET /echo" + " HTTP/1.1\r\n" +
|
||||||
"Host: " + hostPort + "\r\n" +
|
"Host: " + hostPort + "\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = readResponse(input);
|
response = readResponse(input);
|
||||||
|
@ -130,7 +131,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 403 from the CONNECT request
|
// Expect 403 from the CONNECT request
|
||||||
|
@ -151,7 +152,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 200 from the CONNECT request
|
// Expect 200 from the CONNECT request
|
||||||
|
@ -162,7 +163,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
"GET /echo" + " HTTP/1.1\r\n" +
|
"GET /echo" + " HTTP/1.1\r\n" +
|
||||||
"Host: " + hostPort + "\r\n" +
|
"Host: " + hostPort + "\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = readResponse(input);
|
response = readResponse(input);
|
||||||
|
@ -188,7 +189,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 403 from the CONNECT request
|
// Expect 403 from the CONNECT request
|
||||||
|
@ -209,7 +210,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 200 from the CONNECT request
|
// Expect 200 from the CONNECT request
|
||||||
|
@ -220,7 +221,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
"GET /echo" + " HTTP/1.1\r\n" +
|
"GET /echo" + " HTTP/1.1\r\n" +
|
||||||
"Host: 127.0.0.1:" + port + "\r\n" +
|
"Host: 127.0.0.1:" + port + "\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = readResponse(input);
|
response = readResponse(input);
|
||||||
|
@ -245,7 +246,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String b64 = proxyAuthorization.substring("Basic ".length());
|
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);
|
return "test:test".equals(credentials);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -265,7 +266,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 407 from the CONNECT request
|
// Expect 407 from the CONNECT request
|
||||||
|
@ -289,7 +290,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 200 from the CONNECT request
|
// Expect 200 from the CONNECT request
|
||||||
|
@ -300,7 +301,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
"GET /echo" + " HTTP/1.1\r\n" +
|
"GET /echo" + " HTTP/1.1\r\n" +
|
||||||
"Host: " + hostPort + "\r\n" +
|
"Host: " + hostPort + "\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = readResponse(input);
|
response = readResponse(input);
|
||||||
|
@ -342,7 +343,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 500 OK from the CONNECT request
|
// Expect 500 OK from the CONNECT request
|
||||||
|
@ -368,7 +369,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 200 OK from the CONNECT request
|
// Expect 200 OK from the CONNECT request
|
||||||
|
@ -379,7 +380,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
"GET /echo" + " HTTP/1.1\r\n" +
|
"GET /echo" + " HTTP/1.1\r\n" +
|
||||||
"Host: " + hostPort + "\r\n" +
|
"Host: " + hostPort + "\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = readResponse(input);
|
response = readResponse(input);
|
||||||
|
@ -404,7 +405,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 200 OK from the CONNECT request
|
// Expect 200 OK from the CONNECT request
|
||||||
|
@ -431,7 +432,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 200 OK from the CONNECT request
|
// Expect 200 OK from the CONNECT request
|
||||||
|
@ -444,7 +445,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
"GET /echo" + " HTTP/1.1\r\n" +
|
"GET /echo" + " HTTP/1.1\r\n" +
|
||||||
"Host: " + hostPort + "\r\n" +
|
"Host: " + hostPort + "\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = readResponse(input);
|
response = readResponse(input);
|
||||||
|
@ -467,7 +468,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 200 OK from the CONNECT request
|
// Expect 200 OK from the CONNECT request
|
||||||
|
@ -478,7 +479,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
"GET /echo HTTP/1.1\r\n" +
|
"GET /echo HTTP/1.1\r\n" +
|
||||||
"Host: " + hostPort + "\r\n" +
|
"Host: " + hostPort + "\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = readResponse(input);
|
response = readResponse(input);
|
||||||
|
@ -506,7 +507,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 200 OK from the CONNECT request
|
// Expect 200 OK from the CONNECT request
|
||||||
|
@ -517,7 +518,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
"GET /close HTTP/1.1\r\n" +
|
"GET /close HTTP/1.1\r\n" +
|
||||||
"Host: " + hostPort + "\r\n" +
|
"Host: " + hostPort + "\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
int read = input.read();
|
int read = input.read();
|
||||||
|
@ -538,7 +539,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 200 OK from the CONNECT request
|
// Expect 200 OK from the CONNECT request
|
||||||
|
@ -551,7 +552,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
"Content-Length: 5\r\n" +
|
"Content-Length: 5\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
"HELLO";
|
"HELLO";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = readResponse(input);
|
response = readResponse(input);
|
||||||
|
@ -562,7 +563,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
"GET /echo" + " HTTP/1.1\r\n" +
|
"GET /echo" + " HTTP/1.1\r\n" +
|
||||||
"Host: " + hostPort + "\r\n" +
|
"Host: " + hostPort + "\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = readResponse(input);
|
response = readResponse(input);
|
||||||
|
@ -585,7 +586,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 200 OK from the CONNECT request
|
// Expect 200 OK from the CONNECT request
|
||||||
|
@ -603,7 +604,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
"Content-Length: " + body.length() + "\r\n" +
|
"Content-Length: " + body.length() + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
body;
|
body;
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = readResponse(input);
|
response = readResponse(input);
|
||||||
|
@ -649,7 +650,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 200 OK from the CONNECT request
|
// Expect 200 OK from the CONNECT request
|
||||||
|
@ -663,7 +664,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
"Content-Length: " + body.length() + "\r\n" +
|
"Content-Length: " + body.length() + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
body;
|
body;
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = readResponse(input);
|
response = readResponse(input);
|
||||||
|
@ -688,7 +689,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
socket.shutdownOutput();
|
socket.shutdownOutput();
|
||||||
|
|
||||||
|
@ -716,7 +717,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Expect 200 OK from the CONNECT request
|
// Expect 200 OK from the CONNECT request
|
||||||
|
@ -727,7 +728,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
||||||
"GET /echo" + " HTTP/1.1\r\n" +
|
"GET /echo" + " HTTP/1.1\r\n" +
|
||||||
"Host: " + hostPort + "\r\n" +
|
"Host: " + hostPort + "\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
socket.shutdownOutput();
|
socket.shutdownOutput();
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.rewrite.handler;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.eclipse.jetty.http.HttpURI;
|
import org.eclipse.jetty.http.HttpURI;
|
||||||
import org.eclipse.jetty.util.MultiMap;
|
import org.eclipse.jetty.util.MultiMap;
|
||||||
|
@ -87,7 +88,7 @@ public class RewriteRegexRuleTest extends AbstractRuleTestCase
|
||||||
if (test[5]!=null)
|
if (test[5]!=null)
|
||||||
{
|
{
|
||||||
MultiMap<String> params=new MultiMap<String>();
|
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())
|
for (String n:params.keySet())
|
||||||
assertEquals(params.getString(n),_request.getParameter(n));
|
assertEquals(params.getString(n),_request.getParameter(n));
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.security.authentication;
|
package org.eclipse.jetty.security.authentication;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.ServletResponse;
|
import javax.servlet.ServletResponse;
|
||||||
|
@ -82,7 +83,7 @@ public class BasicAuthenticator extends LoginAuthenticator
|
||||||
if ("basic".equalsIgnoreCase(method))
|
if ("basic".equalsIgnoreCase(method))
|
||||||
{
|
{
|
||||||
credentials = credentials.substring(space+1);
|
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(':');
|
int i = credentials.indexOf(':');
|
||||||
if (i>0)
|
if (i>0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.security.authentication;
|
package org.eclipse.jetty.security.authentication;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
@ -367,18 +368,18 @@ public class DigestAuthenticator extends LoginAuthenticator
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// calc A1 digest
|
// calc A1 digest
|
||||||
md.update(username.getBytes(StringUtil.__ISO_8859_1));
|
md.update(username.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update(realm.getBytes(StringUtil.__ISO_8859_1));
|
md.update(realm.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update(password.getBytes(StringUtil.__ISO_8859_1));
|
md.update(password.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
ha1 = md.digest();
|
ha1 = md.digest();
|
||||||
}
|
}
|
||||||
// calc A2 digest
|
// calc A2 digest
|
||||||
md.reset();
|
md.reset();
|
||||||
md.update(method.getBytes(StringUtil.__ISO_8859_1));
|
md.update(method.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update(uri.getBytes(StringUtil.__ISO_8859_1));
|
md.update(uri.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
byte[] ha2 = md.digest();
|
byte[] ha2 = md.digest();
|
||||||
|
|
||||||
// calc digest
|
// calc digest
|
||||||
|
@ -388,17 +389,17 @@ public class DigestAuthenticator extends LoginAuthenticator
|
||||||
// request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2)
|
// 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((byte) ':');
|
||||||
md.update(nonce.getBytes(StringUtil.__ISO_8859_1));
|
md.update(nonce.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update(nc.getBytes(StringUtil.__ISO_8859_1));
|
md.update(nc.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update(cnonce.getBytes(StringUtil.__ISO_8859_1));
|
md.update(cnonce.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update(qop.getBytes(StringUtil.__ISO_8859_1));
|
md.update(qop.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
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();
|
byte[] digest = md.digest();
|
||||||
|
|
||||||
// check digest
|
// check digest
|
||||||
|
|
|
@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.matchers.JUnitMatchers.containsString;
|
import static org.junit.matchers.JUnitMatchers.containsString;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -334,17 +335,17 @@ public class ConstraintTest
|
||||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||||
byte[] ha1;
|
byte[] ha1;
|
||||||
// calc A1 digest
|
// calc A1 digest
|
||||||
md.update(username.getBytes(StringUtil.__ISO_8859_1));
|
md.update(username.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update("TestRealm".getBytes(StringUtil.__ISO_8859_1));
|
md.update("TestRealm".getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update(password.getBytes(StringUtil.__ISO_8859_1));
|
md.update(password.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
ha1 = md.digest();
|
ha1 = md.digest();
|
||||||
// calc A2 digest
|
// calc A2 digest
|
||||||
md.reset();
|
md.reset();
|
||||||
md.update("GET".getBytes(StringUtil.__ISO_8859_1));
|
md.update("GET".getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update(uri.getBytes(StringUtil.__ISO_8859_1));
|
md.update(uri.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
byte[] ha2 = md.digest();
|
byte[] ha2 = md.digest();
|
||||||
|
|
||||||
// calc digest
|
// calc digest
|
||||||
|
@ -354,17 +355,17 @@ public class ConstraintTest
|
||||||
// request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2)
|
// 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((byte) ':');
|
||||||
md.update(nonce.getBytes(StringUtil.__ISO_8859_1));
|
md.update(nonce.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update(nc.getBytes(StringUtil.__ISO_8859_1));
|
md.update(nc.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update(CNONCE.getBytes(StringUtil.__ISO_8859_1));
|
md.update(CNONCE.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
md.update((byte) ':');
|
||||||
md.update("auth".getBytes(StringUtil.__ISO_8859_1));
|
md.update("auth".getBytes(StandardCharsets.ISO_8859_1));
|
||||||
md.update((byte) ':');
|
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();
|
byte[] digest = md.digest();
|
||||||
|
|
||||||
// check digest
|
// check digest
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.ClosedChannelException;
|
import java.nio.channels.ClosedChannelException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
@ -373,9 +374,12 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
_request.setAttribute(RequestDispatcher.ERROR_EXCEPTION,x);
|
||||||
|
_request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE,x.getClass());
|
||||||
if (_state.isSuspended())
|
if (_state.isSuspended())
|
||||||
{
|
{
|
||||||
HttpFields fields = new HttpFields();
|
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());
|
ResponseInfo info = new ResponseInfo(_request.getHttpVersion(), fields, 0, HttpStatus.INTERNAL_SERVER_ERROR_500, null, _request.isHead());
|
||||||
boolean committed = sendResponse(info, null, true);
|
boolean committed = sendResponse(info, null, true);
|
||||||
if (!committed)
|
if (!committed)
|
||||||
|
@ -389,8 +393,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_request.setAttribute(RequestDispatcher.ERROR_EXCEPTION,x);
|
_response.setHeader(HttpHeader.CONNECTION.asString(),HttpHeaderValue.CLOSE.asString());
|
||||||
_request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE,x.getClass());
|
|
||||||
_response.sendError(500, x.getMessage());
|
_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.warn("Failed UTF-8 decode for request path, trying ISO-8859-1");
|
||||||
LOG.ignore(e);
|
LOG.ignore(e);
|
||||||
path = _uri.getDecodedPath(StringUtil.__ISO_8859_1);
|
path = _uri.getDecodedPath(StandardCharsets.ISO_8859_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String info = URIUtil.canonicalPath(path);
|
String info = URIUtil.canonicalPath(path);
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.channels.ByteChannel;
|
||||||
import java.nio.channels.ClosedChannelException;
|
import java.nio.channels.ClosedChannelException;
|
||||||
import java.util.concurrent.RejectedExecutionException;
|
import java.util.concurrent.RejectedExecutionException;
|
||||||
|
|
||||||
|
@ -91,13 +92,29 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
_config = config;
|
_config = config;
|
||||||
_connector = connector;
|
_connector = connector;
|
||||||
_bufferPool = _connector.getByteBufferPool();
|
_bufferPool = _connector.getByteBufferPool();
|
||||||
_generator = new HttpGenerator(_config.getSendServerVersion(),_config.getSendXPoweredBy());
|
_generator = newHttpGenerator();
|
||||||
_channel = new HttpChannelOverHttp(connector, config, endPoint, this, new Input());
|
HttpInput<ByteBuffer> input = newHttpInput();
|
||||||
|
_channel = newHttpChannel(input);
|
||||||
_parser = newHttpParser();
|
_parser = newHttpParser();
|
||||||
|
|
||||||
LOG.debug("New HTTP Connection {}", this);
|
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()
|
protected HttpParser newHttpParser()
|
||||||
{
|
{
|
||||||
return new HttpParser(newRequestHandler(), getHttpConfiguration().getRequestHeaderSize());
|
return new HttpParser(newRequestHandler(), getHttpConfiguration().getRequestHeaderSize());
|
||||||
|
@ -421,7 +438,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
return _requestBuffer;
|
return _requestBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Input extends ByteBufferHttpInput
|
protected class Input extends ByteBufferHttpInput
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected void blockForContent() throws IOException
|
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)
|
public HttpChannelOverHttp(Connector connector, HttpConfiguration config, EndPoint endPoint, HttpTransport transport, HttpInput<ByteBuffer> input)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.Executor;
|
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
|
public String getResponses(String requests,long idleFor,TimeUnit units) throws Exception
|
||||||
{
|
{
|
||||||
ByteBuffer result = getResponses(BufferUtil.toBuffer(requests,StringUtil.__UTF8_CHARSET),idleFor,units);
|
ByteBuffer result = getResponses(BufferUtil.toBuffer(requests,StandardCharsets.UTF_8),idleFor,units);
|
||||||
return result==null?null:BufferUtil.toString(result,StringUtil.__UTF8_CHARSET);
|
return result==null?null:BufferUtil.toString(result,StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sends requests and get's responses based on thread activity.
|
/** Sends requests and get's responses based on thread activity.
|
||||||
|
@ -150,7 +151,7 @@ public class LocalConnector extends AbstractConnector
|
||||||
*/
|
*/
|
||||||
public LocalEndPoint executeRequest(String rawRequest)
|
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)
|
private LocalEndPoint executeRequest(ByteBuffer rawRequest)
|
||||||
|
@ -191,7 +192,7 @@ public class LocalConnector extends AbstractConnector
|
||||||
// TODO this is a busy wait
|
// TODO this is a busy wait
|
||||||
while(getIn()==null || BufferUtil.hasContent(getIn()))
|
while(getIn()==null || BufferUtil.hasContent(getIn()))
|
||||||
Thread.yield();
|
Thread.yield();
|
||||||
setInput(BufferUtil.toBuffer(s, StringUtil.__UTF8_CHARSET));
|
setInput(BufferUtil.toBuffer(s, StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,12 +18,13 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.server;
|
package org.eclipse.jetty.server;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>A {@link Connector} for TCP/IP network connectors</p>
|
* <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
|
* <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>
|
* (for example, to stop accepting network connections).</p>
|
||||||
* Once a connector has been closed, it cannot be opened again without first
|
* 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()}
|
* 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
|
@Override
|
||||||
void close();
|
void close();
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.io.UnsupportedEncodingException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.charset.UnsupportedCharsetException;
|
import java.nio.charset.UnsupportedCharsetException;
|
||||||
import java.security.Principal;
|
import java.security.Principal;
|
||||||
import java.util.ArrayList;
|
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
|
* 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.
|
* 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_INPUT_STREAM, _multiPartInputStream);
|
||||||
setAttribute(__MULTIPART_CONTEXT, _context);
|
setAttribute(__MULTIPART_CONTEXT, _context);
|
||||||
Collection<Part> parts = _multiPartInputStream.getParts(); //causes parsing
|
Collection<Part> parts = _multiPartInputStream.getParts(); //causes parsing
|
||||||
|
ByteArrayOutputStream os = null;
|
||||||
for (Part p:parts)
|
for (Part p:parts)
|
||||||
{
|
{
|
||||||
MultiPartInputStreamParser.MultiPart mp = (MultiPartInputStreamParser.MultiPart)p;
|
MultiPartInputStreamParser.MultiPart mp = (MultiPartInputStreamParser.MultiPart)p;
|
||||||
|
@ -2090,21 +2092,17 @@ public class Request implements HttpServletRequest
|
||||||
if (mp.getContentType() != null)
|
if (mp.getContentType() != null)
|
||||||
charset = MimeTypes.getCharsetFromContentType(mp.getContentType());
|
charset = MimeTypes.getCharsetFromContentType(mp.getContentType());
|
||||||
|
|
||||||
ByteArrayOutputStream os = null;
|
//get the bytes regardless of being in memory or in temp file
|
||||||
InputStream is = mp.getInputStream(); //get the bytes regardless of being in memory or in temp file
|
try (InputStream is = mp.getInputStream())
|
||||||
try
|
|
||||||
{
|
{
|
||||||
|
if (os == null)
|
||||||
os = new ByteArrayOutputStream();
|
os = new ByteArrayOutputStream();
|
||||||
IO.copy(is, os);
|
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
|
getParameter(""); //cause params to be evaluated
|
||||||
getParameters().add(mp.getName(), content);
|
getParameters().add(mp.getName(), content);
|
||||||
}
|
}
|
||||||
finally
|
os.reset();
|
||||||
{
|
|
||||||
IO.close(os);
|
|
||||||
IO.close(is);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2149,7 +2147,7 @@ public class Request implements HttpServletRequest
|
||||||
{
|
{
|
||||||
// extract parameters from dispatch query
|
// extract parameters from dispatch query
|
||||||
MultiMap<String> parameters = new MultiMap<>();
|
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;
|
boolean merge_old_query = false;
|
||||||
|
|
||||||
|
@ -2174,7 +2172,7 @@ public class Request implements HttpServletRequest
|
||||||
|
|
||||||
|
|
||||||
MultiMap<String> overridden_new_query = new MultiMap<>();
|
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())
|
for(String name: overridden_old_query.keySet())
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.io.OutputStream;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.StringUtil;
|
import org.eclipse.jetty.util.StringUtil;
|
||||||
|
@ -112,7 +113,7 @@ public class ShutdownMonitor
|
||||||
|
|
||||||
// Reply to client
|
// Reply to client
|
||||||
debug("Informing client that we are stopped.");
|
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();
|
out.flush();
|
||||||
|
|
||||||
// Shutdown Monitor
|
// Shutdown Monitor
|
||||||
|
@ -131,7 +132,7 @@ public class ShutdownMonitor
|
||||||
else if ("status".equals(cmd))
|
else if ("status".equals(cmd))
|
||||||
{
|
{
|
||||||
// Reply to client
|
// Reply to client
|
||||||
out.write("OK\r\n".getBytes(StringUtil.__UTF8));
|
out.write("OK\r\n".getBytes(StandardCharsets.UTF_8));
|
||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.io.OutputStreamWriter;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -75,7 +76,7 @@ public abstract class AbstractHttpTest
|
||||||
{
|
{
|
||||||
Socket socket = new Socket("localhost", connector.getLocalPort());
|
Socket socket = new Socket("localhost", connector.getLocalPort());
|
||||||
socket.setSoTimeout((int)connector.getIdleTimeout());
|
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()));
|
PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
|
||||||
String request = "GET / " + httpVersion + "\r\n";
|
String request = "GET / " + httpVersion + "\r\n";
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.Exchanger;
|
import java.util.concurrent.Exchanger;
|
||||||
|
@ -96,7 +97,7 @@ public class AsyncRequestReadTest
|
||||||
"Content-Length: "+content.length+"\r\n"+
|
"Content-Length: "+content.length+"\r\n"+
|
||||||
"Content-Type: bytes\r\n"+
|
"Content-Type: bytes\r\n"+
|
||||||
"\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(h);
|
||||||
out.write(content);
|
out.write(content);
|
||||||
|
|
||||||
|
@ -108,7 +109,7 @@ public class AsyncRequestReadTest
|
||||||
"Content-Type: bytes\r\n"+
|
"Content-Type: bytes\r\n"+
|
||||||
"Connection: close\r\n"+
|
"Connection: close\r\n"+
|
||||||
"\r\n";
|
"\r\n";
|
||||||
h=header.getBytes(StringUtil.__ISO_8859_1);
|
h=header.getBytes(StandardCharsets.ISO_8859_1);
|
||||||
out.write(h);
|
out.write(h);
|
||||||
out.write(content);
|
out.write(content);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
@ -244,7 +245,7 @@ public class AsyncRequestReadTest
|
||||||
"Content-Length: "+content.length+"\r\n"+
|
"Content-Length: "+content.length+"\r\n"+
|
||||||
"Content-Type: bytes\r\n"+
|
"Content-Type: bytes\r\n"+
|
||||||
"\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(h);
|
||||||
out.write(content);
|
out.write(content);
|
||||||
|
|
||||||
|
@ -254,7 +255,7 @@ public class AsyncRequestReadTest
|
||||||
"Content-Type: bytes\r\n"+
|
"Content-Type: bytes\r\n"+
|
||||||
"Connection: close\r\n"+
|
"Connection: close\r\n"+
|
||||||
"\r\n";
|
"\r\n";
|
||||||
h=header.getBytes(StringUtil.__ISO_8859_1);
|
h=header.getBytes(StandardCharsets.ISO_8859_1);
|
||||||
out.write(h);
|
out.write(h);
|
||||||
out.write(content);
|
out.write(content);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
@ -294,7 +295,7 @@ public class AsyncRequestReadTest
|
||||||
"Content-Length: "+content.length+"\r\n"+
|
"Content-Length: "+content.length+"\r\n"+
|
||||||
"Content-Type: bytes\r\n"+
|
"Content-Type: bytes\r\n"+
|
||||||
"\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(h);
|
||||||
out.write(content,0,4096);
|
out.write(content,0,4096);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
@ -329,7 +330,7 @@ public class AsyncRequestReadTest
|
||||||
"Content-Length: "+content.length+"\r\n"+
|
"Content-Length: "+content.length+"\r\n"+
|
||||||
"Content-Type: bytes\r\n"+
|
"Content-Type: bytes\r\n"+
|
||||||
"\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(h);
|
||||||
out.write(content,0,4096);
|
out.write(content,0,4096);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
@ -140,7 +141,7 @@ public class AsyncStressTest
|
||||||
"result: "+__paths[p][1]+"\r\n"+
|
"result: "+__paths[p][1]+"\r\n"+
|
||||||
((l+1<loops)?"":"Connection: close\r\n")+
|
((l+1<loops)?"":"Connection: close\r\n")+
|
||||||
"\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();
|
socket[i].getOutputStream().flush();
|
||||||
}
|
}
|
||||||
if (l%80==0)
|
if (l%80==0)
|
||||||
|
@ -155,7 +156,7 @@ public class AsyncStressTest
|
||||||
String[] results=new String[connections];
|
String[] results=new String[connections];
|
||||||
for (int i=0;i<connections;i++)
|
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)
|
if (i%80==0)
|
||||||
System.err.println();
|
System.err.println();
|
||||||
System.err.print('-');
|
System.err.print('-');
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
@ -91,7 +92,7 @@ public class ConnectionOpenCloseTest extends AbstractHttpTest
|
||||||
"GET / HTTP/1.1\r\n" +
|
"GET / HTTP/1.1\r\n" +
|
||||||
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
|
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
|
||||||
"Connection: close\r\n" +
|
"Connection: close\r\n" +
|
||||||
"\r\n").getBytes("UTF-8"));
|
"\r\n").getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
@ -162,7 +163,7 @@ public class ConnectionOpenCloseTest extends AbstractHttpTest
|
||||||
"GET / HTTP/1.1\r\n" +
|
"GET / HTTP/1.1\r\n" +
|
||||||
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
|
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
|
||||||
"Connection: close\r\n" +
|
"Connection: close\r\n" +
|
||||||
"\r\n").getBytes("UTF-8"));
|
"\r\n").getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
@ -97,7 +98,7 @@ public class DumpHandler extends AbstractHandler
|
||||||
|
|
||||||
OutputStream out = response.getOutputStream();
|
OutputStream out = response.getOutputStream();
|
||||||
ByteArrayOutputStream buf = new ByteArrayOutputStream(2048);
|
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("<html><h1>"+label+"</h1>");
|
||||||
writer.write("<pre>\npathInfo="+request.getPathInfo()+"\n</pre>\n");
|
writer.write("<pre>\npathInfo="+request.getPathInfo()+"\n</pre>\n");
|
||||||
writer.write("<pre>\ncontentType="+request.getContentType()+"\n</pre>\n");
|
writer.write("<pre>\ncontentType="+request.getContentType()+"\n</pre>\n");
|
||||||
|
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
@ -76,7 +77,7 @@ public class GracefulStopTest
|
||||||
|
|
||||||
try(Socket socket = new Socket("localhost",server.getBean(NetworkConnector.class).getLocalPort());)
|
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());
|
String out = IO.toString(socket.getInputStream());
|
||||||
Assert.assertThat(out,Matchers.containsString("200 OK"));
|
Assert.assertThat(out,Matchers.containsString("200 OK"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
@ -71,10 +72,10 @@ public class HostHeaderCustomizerTest
|
||||||
String request = "" +
|
String request = "" +
|
||||||
"GET / HTTP/1.0\r\n" +
|
"GET / HTTP/1.0\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
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();
|
SimpleHttpParser parser = new SimpleHttpParser();
|
||||||
SimpleHttpResponse response = parser.readResponse(input);
|
SimpleHttpResponse response = parser.readResponse(input);
|
||||||
|
|
||||||
|
|
|
@ -448,7 +448,7 @@ public class HttpConnectionTest
|
||||||
|
|
||||||
offset=0;
|
offset=0;
|
||||||
requests=
|
requests=
|
||||||
"GET /R1?read=1&error=500 HTTP/1.1\n"+
|
"GET /R1?read=1&error=499 HTTP/1.1\n"+
|
||||||
"Host: localhost\n"+
|
"Host: localhost\n"+
|
||||||
"Transfer-Encoding: chunked\n"+
|
"Transfer-Encoding: chunked\n"+
|
||||||
"Content-Type: text/plain; charset=utf-8\n"+
|
"Content-Type: text/plain; charset=utf-8\n"+
|
||||||
|
@ -468,7 +468,7 @@ public class HttpConnectionTest
|
||||||
|
|
||||||
response=connector.getResponses(requests);
|
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,"HTTP/1.1 200");
|
||||||
offset = checkContains(response,offset,"/R2");
|
offset = checkContains(response,offset,"/R2");
|
||||||
offset = checkContains(response,offset,"encoding=UTF-8");
|
offset = checkContains(response,offset,"encoding=UTF-8");
|
||||||
|
|
|
@ -37,6 +37,7 @@ import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
@ -114,6 +115,26 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
|
||||||
"\n" +
|
"\n" +
|
||||||
RESPONSE2_CONTENT;
|
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
|
* 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("123456789"));
|
||||||
assertTrue(in.contains("abcdefghZ"));
|
assertTrue(in.contains("abcdefghZ"));
|
||||||
assertFalse(in.contains("Wibble"));
|
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);
|
assertEquals("Wibble\n", in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1416,11 +1437,11 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
|
||||||
{
|
{
|
||||||
for (int i = 0; i < REQS; i++)
|
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("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(StringUtil.__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(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();
|
out.flush();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.eclipse.jetty.http.HttpURI;
|
import org.eclipse.jetty.http.HttpURI;
|
||||||
import org.eclipse.jetty.util.MultiMap;
|
import org.eclipse.jetty.util.MultiMap;
|
||||||
|
@ -330,7 +331,7 @@ public class HttpURITest
|
||||||
|
|
||||||
huri=new HttpURI(uri);
|
huri=new HttpURI(uri);
|
||||||
params = new MultiMap<>();
|
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));
|
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"));
|
HttpURI uri = new HttpURI("/path?value="+URLEncoder.encode(value,"UTF-8"));
|
||||||
|
|
||||||
MultiMap<String> parameters = new MultiMap<>();
|
MultiMap<String> parameters = new MultiMap<>();
|
||||||
uri.decodeQueryTo(parameters,"UTF-8");
|
uri.decodeQueryTo(parameters,StandardCharsets.UTF_8);
|
||||||
assertEquals(value,parameters.getString("value"));
|
assertEquals(value,parameters.getString("value"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -366,7 +367,7 @@ public class HttpURITest
|
||||||
{
|
{
|
||||||
try
|
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);
|
uri.parseConnect(buf,2,buf.length-4);
|
||||||
assertEquals("path"+i,connect_tests[i][0].trim(),uri.getPath());
|
assertEquals("path"+i,connect_tests[i][0].trim(),uri.getPath());
|
||||||
|
@ -384,13 +385,13 @@ public class HttpURITest
|
||||||
public void testNonURIAscii() throws Exception
|
public void testNonURIAscii() throws Exception
|
||||||
{
|
{
|
||||||
String url = "http://www.foo.com/ma\u00F1ana";
|
String url = "http://www.foo.com/ma\u00F1ana";
|
||||||
byte[] asISO = url.getBytes("ISO-8859-1");
|
byte[] asISO = url.getBytes(StandardCharsets.ISO_8859_1);
|
||||||
new String(asISO, "ISO-8859-1");
|
new String(asISO, StandardCharsets.ISO_8859_1);
|
||||||
|
|
||||||
//use a non UTF-8 charset as the encoding and url-escape as per
|
//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
|
//http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars
|
||||||
String s = URLEncoder.encode(url, "ISO-8859-1");
|
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
|
//parse it, using the same encoding
|
||||||
uri.parse(s);
|
uri.parse(s);
|
||||||
|
|
|
@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.eclipse.jetty.io.ByteBufferPool;
|
import org.eclipse.jetty.io.ByteBufferPool;
|
||||||
import org.eclipse.jetty.io.MappedByteBufferPool;
|
import org.eclipse.jetty.io.MappedByteBufferPool;
|
||||||
|
@ -67,7 +68,7 @@ public class HttpWriterTest
|
||||||
{
|
{
|
||||||
HttpWriter _writer = new Utf8HttpWriter(_httpOut);
|
HttpWriter _writer = new Utf8HttpWriter(_httpOut);
|
||||||
_writer.write("Now is the time");
|
_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
|
@Test
|
||||||
|
@ -75,7 +76,7 @@ public class HttpWriterTest
|
||||||
{
|
{
|
||||||
HttpWriter _writer = new Utf8HttpWriter(_httpOut);
|
HttpWriter _writer = new Utf8HttpWriter(_httpOut);
|
||||||
_writer.write("How now \uFF22rown cow");
|
_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
|
@Test
|
||||||
|
@ -83,7 +84,7 @@ public class HttpWriterTest
|
||||||
{
|
{
|
||||||
HttpWriter _writer = new EncodingHttpWriter(_httpOut,StringUtil.__UTF16);
|
HttpWriter _writer = new EncodingHttpWriter(_httpOut,StringUtil.__UTF16);
|
||||||
_writer.write("How now \uFF22rown cow");
|
_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
|
@Test
|
||||||
|
@ -93,7 +94,7 @@ public class HttpWriterTest
|
||||||
String data="xxx\uD801\uDC00xxx";
|
String data="xxx\uD801\uDC00xxx";
|
||||||
_writer.write(data);
|
_writer.write(data);
|
||||||
assertEquals("787878F0909080787878",TypeUtil.toHexString(BufferUtil.toArray(_bytes)));
|
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());
|
assertEquals(3+4+3,_bytes.remaining());
|
||||||
|
|
||||||
Utf8StringBuilder buf = new Utf8StringBuilder();
|
Utf8StringBuilder buf = new Utf8StringBuilder();
|
||||||
|
@ -109,7 +110,7 @@ public class HttpWriterTest
|
||||||
final String multiByteDuplicateStr = "\uFF22";
|
final String multiByteDuplicateStr = "\uFF22";
|
||||||
int remainSize = 1;
|
int remainSize = 1;
|
||||||
|
|
||||||
int multiByteStrByteLength = multiByteDuplicateStr.getBytes("UTF-8").length;
|
int multiByteStrByteLength = multiByteDuplicateStr.getBytes(StandardCharsets.UTF_8).length;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < HttpWriter.MAX_OUTPUT_CHARS - multiByteStrByteLength; i++) {
|
for (int i = 0; i < HttpWriter.MAX_OUTPUT_CHARS - multiByteStrByteLength; i++) {
|
||||||
sb.append(singleByteStr);
|
sb.append(singleByteStr);
|
||||||
|
@ -125,7 +126,7 @@ public class HttpWriterTest
|
||||||
|
|
||||||
_writer.write(buf, 0, length);
|
_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
|
@Test
|
||||||
|
@ -133,7 +134,7 @@ public class HttpWriterTest
|
||||||
{
|
{
|
||||||
HttpWriter _writer = new Iso88591HttpWriter(_httpOut);
|
HttpWriter _writer = new Iso88591HttpWriter(_httpOut);
|
||||||
_writer.write("How now \uFF22rown cow");
|
_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
|
@Test
|
||||||
|
@ -143,11 +144,11 @@ public class HttpWriterTest
|
||||||
|
|
||||||
String source = "\uD842\uDF9F";
|
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);
|
_writer.write(source.toCharArray(),0,source.toCharArray().length);
|
||||||
|
|
||||||
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
|
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.write(source.toCharArray(),0,source.toCharArray().length);
|
||||||
osw.flush();
|
osw.flush();
|
||||||
|
|
||||||
|
@ -181,11 +182,11 @@ public class HttpWriterTest
|
||||||
}
|
}
|
||||||
String source = sb.toString();
|
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);
|
_writer.write(source.toCharArray(),0,source.toCharArray().length);
|
||||||
|
|
||||||
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
|
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.write(source.toCharArray(),0,source.toCharArray().length);
|
||||||
osw.flush();
|
osw.flush();
|
||||||
|
|
||||||
|
@ -219,11 +220,11 @@ public class HttpWriterTest
|
||||||
}
|
}
|
||||||
String source = sb.toString();
|
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);
|
_writer.write(source.toCharArray(),0,source.toCharArray().length);
|
||||||
|
|
||||||
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
|
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.write(source.toCharArray(),0,source.toCharArray().length);
|
||||||
osw.flush();
|
osw.flush();
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import static org.hamcrest.Matchers.not;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
|
@ -161,7 +162,7 @@ public class LowResourcesMonitorTest
|
||||||
for (int i=0;i<socket.length;i++)
|
for (int i=0;i<socket.length;i++)
|
||||||
Assert.assertEquals(-1,socket[i].getInputStream().read());
|
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());
|
Assert.assertEquals('H',newSocket.getInputStream().read());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -183,11 +184,11 @@ public class LowResourcesMonitorTest
|
||||||
Thread.sleep(1200);
|
Thread.sleep(1200);
|
||||||
Assert.assertTrue(_lowResourcesMonitor.isLowOnResources());
|
Assert.assertTrue(_lowResourcesMonitor.isLowOnResources());
|
||||||
Assert.assertEquals(-1,socket0.getInputStream().read());
|
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);
|
Thread.sleep(1200);
|
||||||
Assert.assertTrue(_lowResourcesMonitor.isLowOnResources());
|
Assert.assertTrue(_lowResourcesMonitor.isLowOnResources());
|
||||||
socket1.getOutputStream().write("E".getBytes(StringUtil.__UTF8_CHARSET));
|
socket1.getOutputStream().write("E".getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
Thread.sleep(1200);
|
Thread.sleep(1200);
|
||||||
Assert.assertTrue(_lowResourcesMonitor.isLowOnResources());
|
Assert.assertTrue(_lowResourcesMonitor.isLowOnResources());
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
@ -130,14 +131,14 @@ public class NetworkTrafficListenerTest
|
||||||
@Override
|
@Override
|
||||||
public void incoming(Socket socket, ByteBuffer bytes)
|
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();
|
incomingLatch.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void outgoing(Socket socket, ByteBuffer bytes)
|
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();
|
outgoingLatch.countDown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -155,7 +156,7 @@ public class NetworkTrafficListenerTest
|
||||||
|
|
||||||
Socket socket = new Socket("localhost", port);
|
Socket socket = new Socket("localhost", port);
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
|
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
|
||||||
|
@ -165,7 +166,7 @@ public class NetworkTrafficListenerTest
|
||||||
assertEquals(expectedResponse, outgoingData.get());
|
assertEquals(expectedResponse, outgoingData.get());
|
||||||
|
|
||||||
byte[] responseBytes = readResponse(socket);
|
byte[] responseBytes = readResponse(socket);
|
||||||
String response = new String(responseBytes, "UTF-8");
|
String response = new String(responseBytes, StandardCharsets.UTF_8);
|
||||||
assertEquals(expectedResponse, response);
|
assertEquals(expectedResponse, response);
|
||||||
|
|
||||||
socket.close();
|
socket.close();
|
||||||
|
@ -181,7 +182,7 @@ public class NetworkTrafficListenerTest
|
||||||
{
|
{
|
||||||
request.setHandled(true);
|
request.setHandled(true);
|
||||||
ServletOutputStream output = servletResponse.getOutputStream();
|
ServletOutputStream output = servletResponse.getOutputStream();
|
||||||
output.write(responseContent.getBytes("UTF-8"));
|
output.write(responseContent.getBytes(StandardCharsets.UTF_8));
|
||||||
output.write(END_OF_CONTENT);
|
output.write(END_OF_CONTENT);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -194,13 +195,13 @@ public class NetworkTrafficListenerTest
|
||||||
{
|
{
|
||||||
public void incoming(Socket socket, ByteBuffer bytes)
|
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();
|
incomingLatch.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void outgoing(Socket socket, ByteBuffer bytes)
|
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();
|
outgoingLatch.countDown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -218,7 +219,7 @@ public class NetworkTrafficListenerTest
|
||||||
|
|
||||||
Socket socket = new Socket("localhost", port);
|
Socket socket = new Socket("localhost", port);
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
|
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
|
||||||
|
@ -228,7 +229,7 @@ public class NetworkTrafficListenerTest
|
||||||
assertEquals(expectedResponse, outgoingData.get());
|
assertEquals(expectedResponse, outgoingData.get());
|
||||||
|
|
||||||
byte[] responseBytes = readResponse(socket);
|
byte[] responseBytes = readResponse(socket);
|
||||||
String response = new String(responseBytes, "UTF-8");
|
String response = new String(responseBytes, StandardCharsets.UTF_8);
|
||||||
assertEquals(expectedResponse, response);
|
assertEquals(expectedResponse, response);
|
||||||
|
|
||||||
socket.close();
|
socket.close();
|
||||||
|
@ -246,9 +247,9 @@ public class NetworkTrafficListenerTest
|
||||||
{
|
{
|
||||||
request.setHandled(true);
|
request.setHandled(true);
|
||||||
ServletOutputStream output = servletResponse.getOutputStream();
|
ServletOutputStream output = servletResponse.getOutputStream();
|
||||||
output.write(responseChunk1.getBytes("UTF-8"));
|
output.write(responseChunk1.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
output.write(responseChunk2.getBytes("UTF-8"));
|
output.write(responseChunk2.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -261,13 +262,13 @@ public class NetworkTrafficListenerTest
|
||||||
{
|
{
|
||||||
public void incoming(Socket socket, ByteBuffer bytes)
|
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();
|
incomingLatch.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void outgoing(Socket socket, ByteBuffer bytes)
|
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();
|
outgoingLatch.countDown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -290,7 +291,7 @@ public class NetworkTrafficListenerTest
|
||||||
|
|
||||||
Socket socket = new Socket("localhost", port);
|
Socket socket = new Socket("localhost", port);
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
|
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
|
||||||
|
@ -300,7 +301,7 @@ public class NetworkTrafficListenerTest
|
||||||
assertEquals(expectedResponse, outgoingData.get());
|
assertEquals(expectedResponse, outgoingData.get());
|
||||||
|
|
||||||
byte[] responseBytes = readResponse(socket);
|
byte[] responseBytes = readResponse(socket);
|
||||||
String response = new String(responseBytes, "UTF-8");
|
String response = new String(responseBytes, StandardCharsets.UTF_8);
|
||||||
assertEquals(expectedResponse, response);
|
assertEquals(expectedResponse, response);
|
||||||
|
|
||||||
socket.close();
|
socket.close();
|
||||||
|
@ -327,13 +328,13 @@ public class NetworkTrafficListenerTest
|
||||||
{
|
{
|
||||||
public void incoming(Socket socket, ByteBuffer bytes)
|
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();
|
incomingLatch.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void outgoing(Socket socket, ByteBuffer bytes)
|
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();
|
outgoingLatch.countDown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -355,7 +356,7 @@ public class NetworkTrafficListenerTest
|
||||||
|
|
||||||
Socket socket = new Socket("localhost", port);
|
Socket socket = new Socket("localhost", port);
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
|
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
|
||||||
|
@ -365,7 +366,7 @@ public class NetworkTrafficListenerTest
|
||||||
assertEquals(expectedResponse, outgoingData.get());
|
assertEquals(expectedResponse, outgoingData.get());
|
||||||
|
|
||||||
byte[] responseBytes = readResponse(socket);
|
byte[] responseBytes = readResponse(socket);
|
||||||
String response = new String(responseBytes, "UTF-8");
|
String response = new String(responseBytes, StandardCharsets.UTF_8);
|
||||||
assertEquals(expectedResponse, response);
|
assertEquals(expectedResponse, response);
|
||||||
|
|
||||||
socket.close();
|
socket.close();
|
||||||
|
@ -400,12 +401,12 @@ public class NetworkTrafficListenerTest
|
||||||
{
|
{
|
||||||
public void incoming(Socket socket, ByteBuffer bytes)
|
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)
|
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();
|
outgoingLatch.countDown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -429,14 +430,14 @@ public class NetworkTrafficListenerTest
|
||||||
|
|
||||||
Socket socket = new Socket("localhost", port);
|
Socket socket = new Socket("localhost", port);
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
assertTrue(outgoingLatch.await(1, TimeUnit.SECONDS));
|
assertTrue(outgoingLatch.await(1, TimeUnit.SECONDS));
|
||||||
assertEquals(expectedResponse, outgoingData.get());
|
assertEquals(expectedResponse, outgoingData.get());
|
||||||
|
|
||||||
byte[] responseBytes = readResponse(socket);
|
byte[] responseBytes = readResponse(socket);
|
||||||
String response = new String(responseBytes, "UTF-8");
|
String response = new String(responseBytes, StandardCharsets.UTF_8);
|
||||||
assertEquals(expectedResponse, response);
|
assertEquals(expectedResponse, response);
|
||||||
|
|
||||||
assertEquals(request, incomingData.get());
|
assertEquals(request, incomingData.get());
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -553,7 +554,7 @@ public class RequestTest
|
||||||
{
|
{
|
||||||
baseRequest.setHandled(true);
|
baseRequest.setHandled(true);
|
||||||
Reader reader=request.getReader();
|
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.setContentLength(b.length);
|
||||||
response.getOutputStream().write(b);
|
response.getOutputStream().write(b);
|
||||||
response.flushBuffer();
|
response.flushBuffer();
|
||||||
|
@ -602,7 +603,7 @@ public class RequestTest
|
||||||
String in = IO.toString(reader);
|
String in = IO.toString(reader);
|
||||||
String param = request.getParameter("param");
|
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.setContentLength(b.length);
|
||||||
response.getOutputStream().write(b);
|
response.getOutputStream().write(b);
|
||||||
response.flushBuffer();
|
response.flushBuffer();
|
||||||
|
@ -637,7 +638,7 @@ public class RequestTest
|
||||||
{
|
{
|
||||||
baseRequest.setHandled(true);
|
baseRequest.setHandled(true);
|
||||||
InputStream in=request.getInputStream();
|
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.setContentLength(b.length);
|
||||||
response.getOutputStream().write(b);
|
response.getOutputStream().write(b);
|
||||||
response.flushBuffer();
|
response.flushBuffer();
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.server;
|
package org.eclipse.jetty.server;
|
||||||
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.IO;
|
import org.eclipse.jetty.util.IO;
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ public class SelectChannelAsyncContextTest extends LocalAsyncContextTest
|
||||||
{
|
{
|
||||||
ServerConnector connector = (ServerConnector)_connector;
|
ServerConnector connector = (ServerConnector)_connector;
|
||||||
Socket socket = new Socket((String)null,connector.getLocalPort());
|
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());
|
return IO.toString(socket.getInputStream());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.session.SessionHandler;
|
import org.eclipse.jetty.server.session.SessionHandler;
|
||||||
|
@ -101,7 +102,7 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest
|
||||||
ServerConnector connector = (ServerConnector)_connector;
|
ServerConnector connector = (ServerConnector)_connector;
|
||||||
Socket socket = new Socket((String)null,connector.getLocalPort());
|
Socket socket = new Socket((String)null,connector.getLocalPort());
|
||||||
socket.setSoTimeout(10 * MAX_IDLE_TIME);
|
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();
|
InputStream inputStream = socket.getInputStream();
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
String response = IO.toString(inputStream);
|
String response = IO.toString(inputStream);
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
@ -118,7 +119,7 @@ public class SlowClientWithPipelinedRequestTest
|
||||||
"GET /content HTTP/1.1\r\n" +
|
"GET /content HTTP/1.1\r\n" +
|
||||||
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
|
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
"").getBytes("UTF-8"));
|
"").getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
InputStream input = client.getInputStream();
|
InputStream input = client.getInputStream();
|
||||||
|
@ -131,7 +132,7 @@ public class SlowClientWithPipelinedRequestTest
|
||||||
"GET /pipelined HTTP/1.1\r\n" +
|
"GET /pipelined HTTP/1.1\r\n" +
|
||||||
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
|
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
"").getBytes("UTF-8"));
|
"").getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Simulate a slow reader
|
// Simulate a slow reader
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
@ -124,7 +125,7 @@ public class IPAccessHandlerTest
|
||||||
OutputStream output = socket.getOutputStream();
|
OutputStream output = socket.getOutputStream();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
Response response = readResponse(input);
|
Response response = readResponse(input);
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.servlet.ServletException;
|
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+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++)
|
for (int i=0;i<2;i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,6 +49,8 @@ import javax.servlet.UnavailableException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
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.http.PathMap;
|
||||||
import org.eclipse.jetty.io.EofException;
|
import org.eclipse.jetty.io.EofException;
|
||||||
import org.eclipse.jetty.io.RuntimeIOException;
|
import org.eclipse.jetty.io.RuntimeIOException;
|
||||||
|
@ -492,7 +494,7 @@ public class ServletHandler extends ScopedHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug("chain={}",chain);
|
LOG.debug("chain={}",chain);
|
||||||
|
Throwable th=null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (servlet_holder==null)
|
if (servlet_holder==null)
|
||||||
|
@ -540,7 +542,7 @@ public class ServletHandler extends ScopedHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
// unwrap cause
|
// unwrap cause
|
||||||
Throwable th=e;
|
th=e;
|
||||||
if (th instanceof ServletException)
|
if (th instanceof ServletException)
|
||||||
{
|
{
|
||||||
if (th instanceof QuietServletException)
|
if (th instanceof QuietServletException)
|
||||||
|
@ -573,6 +575,7 @@ public class ServletHandler extends ScopedHandler
|
||||||
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION,th);
|
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION,th);
|
||||||
if (!response.isCommitted())
|
if (!response.isCommitted())
|
||||||
{
|
{
|
||||||
|
baseRequest.getResponse().getHttpFields().put(HttpHeader.CONNECTION,HttpHeaderValue.CLOSE);
|
||||||
if (th instanceof UnavailableException)
|
if (th instanceof UnavailableException)
|
||||||
{
|
{
|
||||||
UnavailableException ue = (UnavailableException)th;
|
UnavailableException ue = (UnavailableException)th;
|
||||||
|
@ -586,33 +589,34 @@ public class ServletHandler extends ScopedHandler
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LOG.debug("Response already committed for handling "+th);
|
LOG.debug("Response already committed for handling "+th);
|
||||||
|
|
||||||
// Complete async requests
|
|
||||||
if (request.isAsyncStarted())
|
|
||||||
request.getAsyncContext().complete();
|
|
||||||
}
|
}
|
||||||
catch(Error e)
|
catch(Error e)
|
||||||
{
|
{
|
||||||
if ("ContinuationThrowable".equals(e.getClass().getSimpleName()))
|
if ("ContinuationThrowable".equals(e.getClass().getSimpleName()))
|
||||||
throw e;
|
throw e;
|
||||||
|
th=e;
|
||||||
if (!(DispatcherType.REQUEST.equals(type) || DispatcherType.ASYNC.equals(type)))
|
if (!(DispatcherType.REQUEST.equals(type) || DispatcherType.ASYNC.equals(type)))
|
||||||
throw e;
|
throw e;
|
||||||
LOG.warn("Error for "+request.getRequestURI(),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_TYPE,e.getClass());
|
||||||
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION,e);
|
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION,e);
|
||||||
if (!response.isCommitted())
|
if (!response.isCommitted())
|
||||||
|
{
|
||||||
|
baseRequest.getResponse().getHttpFields().put(HttpHeader.CONNECTION,HttpHeaderValue.CLOSE);
|
||||||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
LOG.debug("Response already committed for handling ",e);
|
LOG.debug("Response already committed for handling ",e);
|
||||||
|
|
||||||
// Complete async requests
|
|
||||||
if (request.isAsyncStarted())
|
|
||||||
request.getAsyncContext().complete();
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
// Complete async errored requests
|
||||||
|
if (th!=null && request.isAsyncStarted())
|
||||||
|
request.getAsyncContext().complete();
|
||||||
|
|
||||||
if (servlet_holder!=null)
|
if (servlet_holder!=null)
|
||||||
baseRequest.setHandled(true);
|
baseRequest.setHandled(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import javax.servlet.AsyncContext;
|
import javax.servlet.AsyncContext;
|
||||||
import javax.servlet.AsyncEvent;
|
import javax.servlet.AsyncEvent;
|
||||||
|
@ -109,10 +110,10 @@ public class AsyncContextListenersTest
|
||||||
"GET " + path + " HTTP/1.1\r\n" +
|
"GET " + path + " HTTP/1.1\r\n" +
|
||||||
"Host: localhost\r\n" +
|
"Host: localhost\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
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();
|
SimpleHttpParser parser = new SimpleHttpParser();
|
||||||
SimpleHttpResponse response = parser.readResponse(reader);
|
SimpleHttpResponse response = parser.readResponse(reader);
|
||||||
Assert.assertEquals("200", response.getCode());
|
Assert.assertEquals("200", response.getCode());
|
||||||
|
@ -120,7 +121,7 @@ public class AsyncContextListenersTest
|
||||||
|
|
||||||
// Send a second request
|
// Send a second request
|
||||||
completes.set(0);
|
completes.set(0);
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = parser.readResponse(reader);
|
response = parser.readResponse(reader);
|
||||||
|
@ -180,10 +181,10 @@ public class AsyncContextListenersTest
|
||||||
"GET " + path + " HTTP/1.1\r\n" +
|
"GET " + path + " HTTP/1.1\r\n" +
|
||||||
"Host: localhost\r\n" +
|
"Host: localhost\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
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();
|
SimpleHttpParser parser = new SimpleHttpParser();
|
||||||
SimpleHttpResponse response = parser.readResponse(reader);
|
SimpleHttpResponse response = parser.readResponse(reader);
|
||||||
Assert.assertEquals("200", response.getCode());
|
Assert.assertEquals("200", response.getCode());
|
||||||
|
@ -191,7 +192,7 @@ public class AsyncContextListenersTest
|
||||||
|
|
||||||
// Send a second request
|
// Send a second request
|
||||||
completes.set(0);
|
completes.set(0);
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = parser.readResponse(reader);
|
response = parser.readResponse(reader);
|
||||||
|
@ -258,10 +259,10 @@ public class AsyncContextListenersTest
|
||||||
"GET " + path + "/one HTTP/1.1\r\n" +
|
"GET " + path + "/one HTTP/1.1\r\n" +
|
||||||
"Host: localhost\r\n" +
|
"Host: localhost\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
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();
|
SimpleHttpParser parser = new SimpleHttpParser();
|
||||||
SimpleHttpResponse response = parser.readResponse(reader);
|
SimpleHttpResponse response = parser.readResponse(reader);
|
||||||
Assert.assertEquals("200", response.getCode());
|
Assert.assertEquals("200", response.getCode());
|
||||||
|
@ -269,7 +270,7 @@ public class AsyncContextListenersTest
|
||||||
|
|
||||||
// Send a second request
|
// Send a second request
|
||||||
completes.set(0);
|
completes.set(0);
|
||||||
output.write(request.getBytes("UTF-8"));
|
output.write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
response = parser.readResponse(reader);
|
response = parser.readResponse(reader);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import javax.servlet.AsyncContext;
|
import javax.servlet.AsyncContext;
|
||||||
|
@ -122,7 +123,7 @@ public class AsyncServletLongPollTest
|
||||||
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
|
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
OutputStream output1 = socket1.getOutputStream();
|
OutputStream output1 = socket1.getOutputStream();
|
||||||
output1.write(request1.getBytes("UTF-8"));
|
output1.write(request1.getBytes(StandardCharsets.UTF_8));
|
||||||
output1.flush();
|
output1.flush();
|
||||||
|
|
||||||
Assert.assertTrue(asyncLatch.await(5, TimeUnit.SECONDS));
|
Assert.assertTrue(asyncLatch.await(5, TimeUnit.SECONDS));
|
||||||
|
@ -134,18 +135,18 @@ public class AsyncServletLongPollTest
|
||||||
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
|
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
OutputStream output2 = socket2.getOutputStream();
|
OutputStream output2 = socket2.getOutputStream();
|
||||||
output2.write(request2.getBytes("UTF-8"));
|
output2.write(request2.getBytes(StandardCharsets.UTF_8));
|
||||||
output2.flush();
|
output2.flush();
|
||||||
|
|
||||||
SimpleHttpParser parser2 = new SimpleHttpParser();
|
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);
|
SimpleHttpResponse response2 = parser2.readResponse(input2);
|
||||||
Assert.assertEquals("200", response2.getCode());
|
Assert.assertEquals("200", response2.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
socket1.setSoTimeout(2 * wait);
|
socket1.setSoTimeout(2 * wait);
|
||||||
SimpleHttpParser parser1 = new SimpleHttpParser();
|
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);
|
SimpleHttpResponse response1 = parser1.readResponse(input1);
|
||||||
Assert.assertEquals(error, response1.getCode());
|
Assert.assertEquals(error, response1.getCode());
|
||||||
|
|
||||||
|
@ -154,7 +155,7 @@ public class AsyncServletLongPollTest
|
||||||
String request3 = "GET " + uri + " HTTP/1.1\r\n" +
|
String request3 = "GET " + uri + " HTTP/1.1\r\n" +
|
||||||
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
|
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
|
||||||
"\r\n";
|
"\r\n";
|
||||||
output1.write(request3.getBytes("UTF-8"));
|
output1.write(request3.getBytes(StandardCharsets.UTF_8));
|
||||||
output1.flush();
|
output1.flush();
|
||||||
|
|
||||||
SimpleHttpResponse response3 = parser1.readResponse(input1);
|
SimpleHttpResponse response3 = parser1.readResponse(input1);
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.servlet;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
|
@ -416,7 +417,7 @@ public class AsyncServletTest
|
||||||
try (Socket socket = new Socket("localhost",port))
|
try (Socket socket = new Socket("localhost",port))
|
||||||
{
|
{
|
||||||
socket.setSoTimeout(1000000);
|
socket.setSoTimeout(1000000);
|
||||||
socket.getOutputStream().write(request.getBytes("UTF-8"));
|
socket.getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
|
||||||
return IO.toString(socket.getInputStream());
|
return IO.toString(socket.getInputStream());
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
|
|
|
@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.HttpConfiguration;
|
import org.eclipse.jetty.server.HttpConfiguration;
|
||||||
import org.eclipse.jetty.server.LocalConnector;
|
import org.eclipse.jetty.server.LocalConnector;
|
||||||
|
@ -220,7 +221,7 @@ public class DefaultServletRangesTest
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
out = new FileOutputStream(file);
|
out = new FileOutputStream(file);
|
||||||
out.write(str.getBytes(StringUtil.__UTF8));
|
out.write(str.getBytes(StandardCharsets.UTF_8));
|
||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|
|
@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -882,7 +883,7 @@ public class DefaultServletTest
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
out = new FileOutputStream(file);
|
out = new FileOutputStream(file);
|
||||||
out.write(str.getBytes(StringUtil.__UTF8));
|
out.write(str.getBytes(StandardCharsets.UTF_8));
|
||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.io.InputStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
|
@ -109,7 +110,7 @@ public class RequestHeadersTest
|
||||||
|
|
||||||
try (InputStream in = http.getInputStream())
|
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"));
|
Assert.assertThat("Response", resp, is("X-Camel-Type = bactrian"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,7 @@ package org.eclipse.jetty.servlets;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
@ -54,24 +53,10 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
*/
|
*/
|
||||||
public abstract class EventSourceServlet extends HttpServlet
|
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[] CRLF = new byte[]{'\r', '\n'};
|
||||||
private static final byte[] EVENT_FIELD;
|
private static final byte[] EVENT_FIELD = "event: ".getBytes(StandardCharsets.UTF_8);
|
||||||
private static final byte[] DATA_FIELD;
|
private static final byte[] DATA_FIELD = "data: ".getBytes(StandardCharsets.UTF_8);
|
||||||
private static final byte[] COMMENT_FIELD;
|
private static final byte[] COMMENT_FIELD = ": ".getBytes(StandardCharsets.UTF_8);
|
||||||
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 ScheduledExecutorService scheduler;
|
private ScheduledExecutorService scheduler;
|
||||||
private int heartBeatPeriod = 10;
|
private int heartBeatPeriod = 10;
|
||||||
|
@ -129,7 +114,7 @@ public abstract class EventSourceServlet extends HttpServlet
|
||||||
protected void respond(HttpServletRequest request, HttpServletResponse response) throws IOException
|
protected void respond(HttpServletRequest request, HttpServletResponse response) throws IOException
|
||||||
{
|
{
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
response.setCharacterEncoding(UTF_8.name());
|
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||||
response.setContentType("text/event-stream");
|
response.setContentType("text/event-stream");
|
||||||
// By adding this header, and not closing the connection,
|
// By adding this header, and not closing the connection,
|
||||||
// we disable HTTP chunking, and we can use write()+flush()
|
// we disable HTTP chunking, and we can use write()+flush()
|
||||||
|
@ -164,7 +149,7 @@ public abstract class EventSourceServlet extends HttpServlet
|
||||||
synchronized (this)
|
synchronized (this)
|
||||||
{
|
{
|
||||||
output.write(EVENT_FIELD);
|
output.write(EVENT_FIELD);
|
||||||
output.write(name.getBytes(UTF_8.name()));
|
output.write(name.getBytes(StandardCharsets.UTF_8));
|
||||||
output.write(CRLF);
|
output.write(CRLF);
|
||||||
data(data);
|
data(data);
|
||||||
}
|
}
|
||||||
|
@ -180,7 +165,7 @@ public abstract class EventSourceServlet extends HttpServlet
|
||||||
while ((line = reader.readLine()) != null)
|
while ((line = reader.readLine()) != null)
|
||||||
{
|
{
|
||||||
output.write(DATA_FIELD);
|
output.write(DATA_FIELD);
|
||||||
output.write(line.getBytes(UTF_8.name()));
|
output.write(line.getBytes(StandardCharsets.UTF_8));
|
||||||
output.write(CRLF);
|
output.write(CRLF);
|
||||||
}
|
}
|
||||||
output.write(CRLF);
|
output.write(CRLF);
|
||||||
|
@ -194,7 +179,7 @@ public abstract class EventSourceServlet extends HttpServlet
|
||||||
synchronized (this)
|
synchronized (this)
|
||||||
{
|
{
|
||||||
output.write(COMMENT_FIELD);
|
output.write(COMMENT_FIELD);
|
||||||
output.write(comment.getBytes(UTF_8.name()));
|
output.write(comment.getBytes(StandardCharsets.UTF_8));
|
||||||
output.write(CRLF);
|
output.write(CRLF);
|
||||||
output.write(CRLF);
|
output.write(CRLF);
|
||||||
flush();
|
flush();
|
||||||
|
|
|
@ -24,6 +24,9 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
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.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
@ -223,7 +226,7 @@ public class MultiPartFilter implements Filter
|
||||||
/* ------------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------------- */
|
||||||
private static class Wrapper extends HttpServletRequestWrapper
|
private static class Wrapper extends HttpServletRequestWrapper
|
||||||
{
|
{
|
||||||
String _encoding=StringUtil.__UTF8;
|
Charset _encoding=StandardCharsets.UTF_8;
|
||||||
MultiMap<Object> _params;
|
MultiMap<Object> _params;
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------------- */
|
||||||
|
@ -339,7 +342,14 @@ public class MultiPartFilter implements Filter
|
||||||
public void setCharacterEncoding(String enc)
|
public void setCharacterEncoding(String enc)
|
||||||
throws UnsupportedEncodingException
|
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
|
//check if there is a specific encoding for the parameter
|
||||||
Object ct = _params.getValue(name+CONTENT_TYPE_SUFFIX,0);
|
Object ct = _params.getValue(name+CONTENT_TYPE_SUFFIX,0);
|
||||||
//use default if not
|
//use default if not
|
||||||
String contentType = _encoding;
|
Charset contentType = _encoding;
|
||||||
if (ct != null)
|
if (ct != null)
|
||||||
{
|
{
|
||||||
String tmp = MimeTypes.getCharsetFromContentType((String)ct);
|
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);
|
return new String(bytes,contentType);
|
||||||
|
|
|
@ -41,13 +41,15 @@ public class GzipOutputStream extends DeflaterOutputStream
|
||||||
out.write(GZIP_HEADER);
|
out.write(GZIP_HEADER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public synchronized void write(byte[] buf, int off, int len) throws IOException
|
public synchronized void write(byte[] buf, int off, int len) throws IOException
|
||||||
{
|
{
|
||||||
super.write(buf,off,len);
|
super.write(buf,off,len);
|
||||||
_crc.update(buf,off,len);
|
_crc.update(buf,off,len);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finish() throws IOException
|
@Override
|
||||||
|
public synchronized void finish() throws IOException
|
||||||
{
|
{
|
||||||
if (!def.finished())
|
if (!def.finished())
|
||||||
{
|
{
|
||||||
|
@ -59,6 +61,14 @@ public class GzipOutputStream extends DeflaterOutputStream
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void close() throws IOException
|
||||||
|
{
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void writeInt(int i, byte[] buf, int offset)
|
private void writeInt(int i, byte[] buf, int offset)
|
||||||
{
|
{
|
||||||
int o = offset;
|
int o = offset;
|
||||||
|
|
|
@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
import javax.servlet.DispatcherType;
|
import javax.servlet.DispatcherType;
|
||||||
|
@ -117,14 +118,14 @@ public abstract class AbstractDoSFilterTest
|
||||||
|
|
||||||
for (int i=loops;i-->0;)
|
for (int i=loops;i-->0;)
|
||||||
{
|
{
|
||||||
socket.getOutputStream().write(loopRequests.getBytes("UTF-8"));
|
socket.getOutputStream().write(loopRequests.getBytes(StandardCharsets.UTF_8));
|
||||||
socket.getOutputStream().flush();
|
socket.getOutputStream().flush();
|
||||||
if (i>0 && pauseBetweenLoops>0)
|
if (i>0 && pauseBetweenLoops>0)
|
||||||
Thread.sleep(pauseBetweenLoops);
|
Thread.sleep(pauseBetweenLoops);
|
||||||
}
|
}
|
||||||
if (pauseBeforeLast>0)
|
if (pauseBeforeLast>0)
|
||||||
Thread.sleep(pauseBeforeLast);
|
Thread.sleep(pauseBeforeLast);
|
||||||
socket.getOutputStream().write(lastRequest.getBytes("UTF-8"));
|
socket.getOutputStream().write(lastRequest.getBytes(StandardCharsets.UTF_8));
|
||||||
socket.getOutputStream().flush();
|
socket.getOutputStream().flush();
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,11 +134,11 @@ public abstract class AbstractDoSFilterTest
|
||||||
{
|
{
|
||||||
// don't read in anything, forcing the request to time out
|
// don't read in anything, forcing the request to time out
|
||||||
Thread.sleep(_requestMaxTime * 2);
|
Thread.sleep(_requestMaxTime * 2);
|
||||||
response = IO.toString(socket.getInputStream(),"UTF-8");
|
response = IO.toString(socket.getInputStream(),StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
response = IO.toString(socket.getInputStream(),"UTF-8");
|
response = IO.toString(socket.getInputStream(),StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
socket.close();
|
socket.close();
|
||||||
return response;
|
return response;
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
@ -326,7 +327,7 @@ public class EventSourceServletTest
|
||||||
handshake += "Host: localhost:" + serverPort + "\r\n";
|
handshake += "Host: localhost:" + serverPort + "\r\n";
|
||||||
handshake += "Accept: text/event-stream\r\n";
|
handshake += "Accept: text/event-stream\r\n";
|
||||||
handshake += "\r\n";
|
handshake += "\r\n";
|
||||||
output.write(handshake.getBytes("UTF-8"));
|
output.write(handshake.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,7 +335,7 @@ public class EventSourceServletTest
|
||||||
{
|
{
|
||||||
// Read and discard the HTTP response
|
// Read and discard the HTTP response
|
||||||
InputStream input = socket.getInputStream();
|
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();
|
String line = reader.readLine();
|
||||||
while (line != null)
|
while (line != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,6 +31,7 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -867,7 +868,7 @@ public class MultipartFilterTest
|
||||||
baos.write(("--" + boundary + "\r\n"+
|
baos.write(("--" + boundary + "\r\n"+
|
||||||
"Content-Disposition: form-data; name=\"ttt\"\r\n"+
|
"Content-Disposition: form-data; name=\"ttt\"\r\n"+
|
||||||
"Content-Type: application/octet-stream; charset=UTF-8\r\n\r\n").getBytes());
|
"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());
|
baos.write(("\r\n--" + boundary + "--\r\n\r\n").getBytes());
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -208,9 +208,20 @@ public abstract class DataInfo extends Info
|
||||||
* @return a String with the content of this {@link DataInfo}
|
* @return a String with the content of this {@link DataInfo}
|
||||||
*/
|
*/
|
||||||
public String asString(String charset, boolean consume)
|
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);
|
ByteBuffer buffer = asByteBuffer(consume);
|
||||||
return Charset.forName(charset).decode(buffer).toString();
|
return charset.decode(buffer).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.spdy.api;
|
package org.eclipse.jetty.spdy.api;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,11 +28,11 @@ public class StringDataInfo extends BytesDataInfo
|
||||||
{
|
{
|
||||||
public StringDataInfo(String string, boolean close)
|
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)
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ package org.eclipse.jetty.spdy.generator;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.eclipse.jetty.spdy.CompressionDictionary;
|
import org.eclipse.jetty.spdy.CompressionDictionary;
|
||||||
|
@ -41,25 +41,24 @@ public class HeadersBlockGenerator
|
||||||
public ByteBuffer generate(short version, Fields headers)
|
public ByteBuffer generate(short version, Fields headers)
|
||||||
{
|
{
|
||||||
// TODO: ByteArrayOutputStream is quite inefficient, but grows on demand; optimize using ByteBuffer ?
|
// 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);
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream(headers.size() * 64);
|
||||||
writeCount(version, buffer, headers.size());
|
writeCount(version, buffer, headers.size());
|
||||||
for (Fields.Field header : headers)
|
for (Fields.Field header : headers)
|
||||||
{
|
{
|
||||||
String name = header.name().toLowerCase(Locale.ENGLISH);
|
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);
|
writeNameLength(version, buffer, nameBytes.length);
|
||||||
buffer.write(nameBytes, 0, nameBytes.length);
|
buffer.write(nameBytes, 0, nameBytes.length);
|
||||||
|
|
||||||
// Most common path first
|
// Most common path first
|
||||||
String value = header.value();
|
String value = header.value();
|
||||||
byte[] valueBytes = value.getBytes(iso1);
|
byte[] valueBytes = value.getBytes(StandardCharsets.ISO_8859_1);
|
||||||
if (header.hasMultipleValues())
|
if (header.hasMultipleValues())
|
||||||
{
|
{
|
||||||
String[] values = header.values();
|
String[] values = header.values();
|
||||||
for (int i = 1; i < values.length; ++i)
|
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];
|
byte[] newValueBytes = new byte[valueBytes.length + 1 + moreValueBytes.length];
|
||||||
System.arraycopy(valueBytes, 0, newValueBytes, 0, valueBytes.length);
|
System.arraycopy(valueBytes, 0, newValueBytes, 0, valueBytes.length);
|
||||||
newValueBytes[valueBytes.length] = 0;
|
newValueBytes[valueBytes.length] = 0;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
package org.eclipse.jetty.spdy.parser;
|
package org.eclipse.jetty.spdy.parser;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.zip.ZipException;
|
import java.util.zip.ZipException;
|
||||||
|
|
||||||
import org.eclipse.jetty.spdy.CompressionDictionary;
|
import org.eclipse.jetty.spdy.CompressionDictionary;
|
||||||
|
@ -57,8 +57,6 @@ public abstract class HeadersBlockParser
|
||||||
data = null;
|
data = null;
|
||||||
ByteBuffer decompressedHeaders = decompress(version, compressedHeaders);
|
ByteBuffer decompressedHeaders = decompress(version, compressedHeaders);
|
||||||
|
|
||||||
Charset iso1 = Charset.forName("ISO-8859-1");
|
|
||||||
|
|
||||||
// We know the decoded bytes contain the full headers,
|
// We know the decoded bytes contain the full headers,
|
||||||
// so optimize instead of looping byte by byte
|
// so optimize instead of looping byte by byte
|
||||||
int count = readCount(version, decompressedHeaders);
|
int count = readCount(version, decompressedHeaders);
|
||||||
|
@ -69,14 +67,14 @@ public abstract class HeadersBlockParser
|
||||||
throw new StreamException(streamId, StreamStatus.PROTOCOL_ERROR, "Invalid header name length");
|
throw new StreamException(streamId, StreamStatus.PROTOCOL_ERROR, "Invalid header name length");
|
||||||
byte[] nameBytes = new byte[nameLength];
|
byte[] nameBytes = new byte[nameLength];
|
||||||
decompressedHeaders.get(nameBytes);
|
decompressedHeaders.get(nameBytes);
|
||||||
String name = new String(nameBytes, iso1);
|
String name = new String(nameBytes, StandardCharsets.ISO_8859_1);
|
||||||
|
|
||||||
int valueLength = readValueLength(version, decompressedHeaders);
|
int valueLength = readValueLength(version, decompressedHeaders);
|
||||||
if (valueLength == 0)
|
if (valueLength == 0)
|
||||||
throw new StreamException(streamId, StreamStatus.PROTOCOL_ERROR, "Invalid header value length");
|
throw new StreamException(streamId, StreamStatus.PROTOCOL_ERROR, "Invalid header value length");
|
||||||
byte[] valueBytes = new byte[valueLength];
|
byte[] valueBytes = new byte[valueLength];
|
||||||
decompressedHeaders.get(valueBytes);
|
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
|
// Multi valued headers are separate by NUL
|
||||||
String[] values = value.split("\u0000");
|
String[] values = value.split("\u0000");
|
||||||
// Check if there are multiple NULs (section 2.6.9)
|
// Check if there are multiple NULs (section 2.6.9)
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.spdy.api;
|
package org.eclipse.jetty.spdy.api;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
@ -242,7 +243,7 @@ public class ClientUsageTest
|
||||||
public void onData(Stream stream, DataInfo dataInfo)
|
public void onData(Stream stream, DataInfo dataInfo)
|
||||||
{
|
{
|
||||||
StringBuilder builder = (StringBuilder)stream.getAttribute("builder");
|
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>()
|
}, new Promise.Adapter<Stream>()
|
||||||
|
@ -250,9 +251,9 @@ public class ClientUsageTest
|
||||||
@Override
|
@Override
|
||||||
public void succeeded(Stream stream)
|
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 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.spdy.parser;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -43,8 +44,7 @@ public class ParseVersusCacheBenchmarkTest
|
||||||
|
|
||||||
String name = "Content-Type";
|
String name = "Content-Type";
|
||||||
String value = "application/octect-stream";
|
String value = "application/octect-stream";
|
||||||
Charset charset = Charset.forName("ISO-8859-1");
|
ByteBuffer buffer = ByteBuffer.wrap((name + value).getBytes(StandardCharsets.ISO_8859_1));
|
||||||
ByteBuffer buffer = ByteBuffer.wrap((name + value).getBytes(charset));
|
|
||||||
int iterations = 100_000_000;
|
int iterations = 100_000_000;
|
||||||
|
|
||||||
long begin = System.nanoTime();
|
long begin = System.nanoTime();
|
||||||
|
@ -52,12 +52,12 @@ public class ParseVersusCacheBenchmarkTest
|
||||||
{
|
{
|
||||||
byte[] nameBytes = new byte[name.length()];
|
byte[] nameBytes = new byte[name.length()];
|
||||||
buffer.get(nameBytes);
|
buffer.get(nameBytes);
|
||||||
String name2 = new String(nameBytes, charset);
|
String name2 = new String(nameBytes, StandardCharsets.ISO_8859_1);
|
||||||
Assert.assertEquals(name2, name);
|
Assert.assertEquals(name2, name);
|
||||||
|
|
||||||
byte[] valueBytes = new byte[value.length()];
|
byte[] valueBytes = new byte[value.length()];
|
||||||
buffer.get(valueBytes);
|
buffer.get(valueBytes);
|
||||||
String value2 = new String(valueBytes, charset);
|
String value2 = new String(valueBytes, StandardCharsets.ISO_8859_1);
|
||||||
Assert.assertEquals(value2, value);
|
Assert.assertEquals(value2, value);
|
||||||
|
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
|
@ -66,8 +66,8 @@ public class ParseVersusCacheBenchmarkTest
|
||||||
System.err.printf("parse time: %d%n", TimeUnit.NANOSECONDS.toMillis(end - begin));
|
System.err.printf("parse time: %d%n", TimeUnit.NANOSECONDS.toMillis(end - begin));
|
||||||
|
|
||||||
Map<ByteBuffer, String> map = new HashMap<>();
|
Map<ByteBuffer, String> map = new HashMap<>();
|
||||||
map.put(ByteBuffer.wrap(name.getBytes(charset)), name);
|
map.put(ByteBuffer.wrap(name.getBytes(StandardCharsets.ISO_8859_1)), name);
|
||||||
map.put(ByteBuffer.wrap(value.getBytes(charset)), value);
|
map.put(ByteBuffer.wrap(value.getBytes(StandardCharsets.ISO_8859_1)), value);
|
||||||
final Map<ByteBuffer, String> cache = Collections.unmodifiableMap(map);
|
final Map<ByteBuffer, String> cache = Collections.unmodifiableMap(map);
|
||||||
|
|
||||||
begin = System.nanoTime();
|
begin = System.nanoTime();
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
|
@ -129,11 +130,11 @@ public class ProtocolNegotiationTest
|
||||||
"GET / HTTP/1.1\r\n" +
|
"GET / HTTP/1.1\r\n" +
|
||||||
"Host: localhost:" + address.getPort() + "\r\n" +
|
"Host: localhost:" + address.getPort() + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
"").getBytes("UTF-8"));
|
"").getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
InputStream input = client.getInputStream();
|
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();
|
String line = reader.readLine();
|
||||||
Assert.assertTrue(line.contains(" 404 "));
|
Assert.assertTrue(line.contains(" 404 "));
|
||||||
|
|
||||||
|
@ -188,11 +189,11 @@ public class ProtocolNegotiationTest
|
||||||
"GET / HTTP/1.1\r\n" +
|
"GET / HTTP/1.1\r\n" +
|
||||||
"Host: localhost:" + address.getPort() + "\r\n" +
|
"Host: localhost:" + address.getPort() + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
"").getBytes("UTF-8"));
|
"").getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
InputStream input = client.getInputStream();
|
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();
|
String line = reader.readLine();
|
||||||
Assert.assertTrue(line.contains(" 404 "));
|
Assert.assertTrue(line.contains(" 404 "));
|
||||||
|
|
||||||
|
@ -241,11 +242,11 @@ public class ProtocolNegotiationTest
|
||||||
"GET / HTTP/1.1\r\n" +
|
"GET / HTTP/1.1\r\n" +
|
||||||
"Host: localhost:" + address.getPort() + "\r\n" +
|
"Host: localhost:" + address.getPort() + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
"").getBytes("UTF-8"));
|
"").getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
InputStream input = client.getInputStream();
|
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();
|
String line = reader.readLine();
|
||||||
Assert.assertTrue(line.contains(" 404 "));
|
Assert.assertTrue(line.contains(" 404 "));
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -432,7 +433,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
|
||||||
request.setHandled(true);
|
request.setHandled(true);
|
||||||
httpResponse.setStatus(HttpServletResponse.SC_OK);
|
httpResponse.setStatus(HttpServletResponse.SC_OK);
|
||||||
ServletOutputStream output = httpResponse.getOutputStream();
|
ServletOutputStream output = httpResponse.getOutputStream();
|
||||||
output.write(data.getBytes("UTF-8"));
|
output.write(data.getBytes(StandardCharsets.UTF_8));
|
||||||
handlerLatch.countDown();
|
handlerLatch.countDown();
|
||||||
}
|
}
|
||||||
}), null);
|
}), null);
|
||||||
|
@ -455,7 +456,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
|
||||||
public void onData(Stream stream, DataInfo dataInfo)
|
public void onData(Stream stream, DataInfo dataInfo)
|
||||||
{
|
{
|
||||||
assertTrue(dataInfo.isClose());
|
assertTrue(dataInfo.isClose());
|
||||||
assertEquals(data, dataInfo.asString("UTF-8", true));
|
assertEquals(data, dataInfo.asString(StandardCharsets.UTF_8, true));
|
||||||
dataLatch.countDown();
|
dataLatch.countDown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -527,9 +528,9 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
|
||||||
request.setHandled(true);
|
request.setHandled(true);
|
||||||
httpResponse.setStatus(HttpServletResponse.SC_OK);
|
httpResponse.setStatus(HttpServletResponse.SC_OK);
|
||||||
ServletOutputStream output = httpResponse.getOutputStream();
|
ServletOutputStream output = httpResponse.getOutputStream();
|
||||||
output.write(data1.getBytes("UTF-8"));
|
output.write(data1.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
output.write(data2.getBytes("UTF-8"));
|
output.write(data2.getBytes(StandardCharsets.UTF_8));
|
||||||
handlerLatch.countDown();
|
handlerLatch.countDown();
|
||||||
}
|
}
|
||||||
}), null);
|
}), null);
|
||||||
|
@ -558,9 +559,9 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
|
||||||
int data = dataFrames.incrementAndGet();
|
int data = dataFrames.incrementAndGet();
|
||||||
assertTrue(data >= 1 && data <= 2);
|
assertTrue(data >= 1 && data <= 2);
|
||||||
if (data == 1)
|
if (data == 1)
|
||||||
assertEquals(data1, dataInfo.asString("UTF8", true));
|
assertEquals(data1, dataInfo.asString(StandardCharsets.UTF_8, true));
|
||||||
else
|
else
|
||||||
assertEquals(data2, dataInfo.asString("UTF8", true));
|
assertEquals(data2, dataInfo.asString(StandardCharsets.UTF_8, true));
|
||||||
dataLatch.countDown();
|
dataLatch.countDown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -744,7 +745,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
|
||||||
request.setHandled(true);
|
request.setHandled(true);
|
||||||
httpResponse.setStatus(HttpServletResponse.SC_OK);
|
httpResponse.setStatus(HttpServletResponse.SC_OK);
|
||||||
ServletOutputStream output = httpResponse.getOutputStream();
|
ServletOutputStream output = httpResponse.getOutputStream();
|
||||||
output.write(data.getBytes("UTF-8"));
|
output.write(data.getBytes(StandardCharsets.UTF_8));
|
||||||
output.flush();
|
output.flush();
|
||||||
output.close();
|
output.close();
|
||||||
handlerLatch.countDown();
|
handlerLatch.countDown();
|
||||||
|
@ -775,7 +776,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
|
||||||
buffer.write(byteBuffer.get());
|
buffer.write(byteBuffer.get());
|
||||||
if (dataInfo.isClose())
|
if (dataInfo.isClose())
|
||||||
{
|
{
|
||||||
assertEquals(data, new String(buffer.toByteArray(), Charset.forName("UTF-8")));
|
assertEquals(data, new String(buffer.toByteArray(), StandardCharsets.UTF_8));
|
||||||
dataLatch.countDown();
|
dataLatch.countDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -801,10 +802,10 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
|
||||||
httpResponse.setStatus(HttpServletResponse.SC_OK);
|
httpResponse.setStatus(HttpServletResponse.SC_OK);
|
||||||
ServletOutputStream output = httpResponse.getOutputStream();
|
ServletOutputStream output = httpResponse.getOutputStream();
|
||||||
// Write some
|
// Write some
|
||||||
output.write(data1.getBytes("UTF-8"));
|
output.write(data1.getBytes(StandardCharsets.UTF_8));
|
||||||
// But then change your mind and reset the buffer
|
// But then change your mind and reset the buffer
|
||||||
httpResponse.resetBuffer();
|
httpResponse.resetBuffer();
|
||||||
output.write(data2.getBytes("UTF-8"));
|
output.write(data2.getBytes(StandardCharsets.UTF_8));
|
||||||
handlerLatch.countDown();
|
handlerLatch.countDown();
|
||||||
}
|
}
|
||||||
}), null);
|
}), null);
|
||||||
|
@ -833,7 +834,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
|
||||||
buffer.write(byteBuffer.get());
|
buffer.write(byteBuffer.get());
|
||||||
if (dataInfo.isClose())
|
if (dataInfo.isClose())
|
||||||
{
|
{
|
||||||
assertEquals(data2, new String(buffer.toByteArray(), Charset.forName("UTF-8")));
|
assertEquals(data2, new String(buffer.toByteArray(), StandardCharsets.UTF_8));
|
||||||
dataLatch.countDown();
|
dataLatch.countDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -990,10 +991,10 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
|
||||||
request.setHandled(true);
|
request.setHandled(true);
|
||||||
httpResponse.setHeader("Transfer-Encoding", "chunked");
|
httpResponse.setHeader("Transfer-Encoding", "chunked");
|
||||||
ServletOutputStream output = httpResponse.getOutputStream();
|
ServletOutputStream output = httpResponse.getOutputStream();
|
||||||
output.write(pangram1.getBytes("UTF-8"));
|
output.write(pangram1.getBytes(StandardCharsets.UTF_8));
|
||||||
httpResponse.setHeader("EXTRA", "X");
|
httpResponse.setHeader("EXTRA", "X");
|
||||||
output.flush();
|
output.flush();
|
||||||
output.write(pangram2.getBytes("UTF-8"));
|
output.write(pangram2.getBytes(StandardCharsets.UTF_8));
|
||||||
handlerLatch.countDown();
|
handlerLatch.countDown();
|
||||||
}
|
}
|
||||||
}), null);
|
}), null);
|
||||||
|
@ -1024,12 +1025,12 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
|
||||||
if (count == 1)
|
if (count == 1)
|
||||||
{
|
{
|
||||||
Assert.assertFalse(dataInfo.isClose());
|
Assert.assertFalse(dataInfo.isClose());
|
||||||
assertEquals(pangram1, dataInfo.asString("UTF-8", true));
|
assertEquals(pangram1, dataInfo.asString(StandardCharsets.UTF_8, true));
|
||||||
}
|
}
|
||||||
else if (count == 2)
|
else if (count == 2)
|
||||||
{
|
{
|
||||||
assertTrue(dataInfo.isClose());
|
assertTrue(dataInfo.isClose());
|
||||||
assertEquals(pangram2, dataInfo.asString("UTF-8", true));
|
assertEquals(pangram2, dataInfo.asString(StandardCharsets.UTF_8, true));
|
||||||
}
|
}
|
||||||
dataLatch.countDown();
|
dataLatch.countDown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.spdy.server.proxy;
|
package org.eclipse.jetty.spdy.server.proxy;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
@ -251,7 +252,7 @@ public class ProxyHTTPToSPDYTest
|
||||||
@Test
|
@Test
|
||||||
public void testGETThenSmallResponseContent() throws Exception
|
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()
|
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -328,7 +329,7 @@ public class ProxyHTTPToSPDYTest
|
||||||
public void testPOSTWithSmallRequestContentThenSmallResponseContent() throws Exception
|
public void testPOSTWithSmallRequestContentThenSmallResponseContent() throws Exception
|
||||||
{
|
{
|
||||||
String dataString = "0123456789ABCDEF";
|
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()
|
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -370,7 +371,7 @@ public class ProxyHTTPToSPDYTest
|
||||||
@Test
|
@Test
|
||||||
public void testGETThenSPDYPushIsIgnored() throws Exception
|
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()
|
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.io.BufferedReader;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
@ -197,7 +198,7 @@ public class ProxySPDYToHTTPTest
|
||||||
@Test
|
@Test
|
||||||
public void testSYNThenREPLYAndDATA() throws Exception
|
public void testSYNThenREPLYAndDATA() throws Exception
|
||||||
{
|
{
|
||||||
final byte[] data = "0123456789ABCDEF".getBytes("UTF-8");
|
final byte[] data = "0123456789ABCDEF".getBytes(StandardCharsets.UTF_8);
|
||||||
final String header = "foo";
|
final String header = "foo";
|
||||||
|
|
||||||
InetSocketAddress proxyAddress = startProxy(startServer(new TestServerHandler(header, data)), 30000, 30000);
|
InetSocketAddress proxyAddress = startProxy(startServer(new TestServerHandler(header, data)), 30000, 30000);
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.spdy.server.proxy;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
@ -227,7 +228,7 @@ public class ProxySPDYToSPDYTest
|
||||||
@Test
|
@Test
|
||||||
public void testSYNThenREPLYAndDATA() throws Exception
|
public void testSYNThenREPLYAndDATA() throws Exception
|
||||||
{
|
{
|
||||||
final byte[] data = "0123456789ABCDEF".getBytes("UTF-8");
|
final byte[] data = "0123456789ABCDEF".getBytes(StandardCharsets.UTF_8);
|
||||||
final String header = "foo";
|
final String header = "foo";
|
||||||
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
|
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
|
||||||
{
|
{
|
||||||
|
@ -287,7 +288,7 @@ public class ProxySPDYToSPDYTest
|
||||||
@Test
|
@Test
|
||||||
public void testSYNThenSPDYPushIsReceived() throws Exception
|
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()
|
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -368,7 +369,7 @@ public class ProxySPDYToSPDYTest
|
||||||
@Test
|
@Test
|
||||||
public void testSYNThenSPDYNestedPushIsReceived() throws Exception
|
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()
|
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.spdy.server;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -118,7 +119,7 @@ public class SynReplyTest extends AbstractTest
|
||||||
@Test
|
@Test
|
||||||
public void testSynDataReply() throws Exception
|
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 synLatch = new CountDownLatch(1);
|
||||||
final CountDownLatch dataLatch = new CountDownLatch(1);
|
final CountDownLatch dataLatch = new CountDownLatch(1);
|
||||||
|
@ -235,13 +236,13 @@ public class SynReplyTest extends AbstractTest
|
||||||
int dataCount = this.dataCount.incrementAndGet();
|
int dataCount = this.dataCount.incrementAndGet();
|
||||||
if (dataCount == 1)
|
if (dataCount == 1)
|
||||||
{
|
{
|
||||||
String chunk1 = dataInfo.asString("UTF-8", true);
|
String chunk1 = dataInfo.asString(StandardCharsets.UTF_8, true);
|
||||||
Assert.assertEquals(data1, chunk1);
|
Assert.assertEquals(data1, chunk1);
|
||||||
dataLatch1.countDown();
|
dataLatch1.countDown();
|
||||||
}
|
}
|
||||||
else if (dataCount == 2)
|
else if (dataCount == 2)
|
||||||
{
|
{
|
||||||
String chunk2 = dataInfo.asString("UTF-8", true);
|
String chunk2 = dataInfo.asString(StandardCharsets.UTF_8, true);
|
||||||
Assert.assertEquals(data2, chunk2);
|
Assert.assertEquals(data2, chunk2);
|
||||||
dataLatch2.countDown();
|
dataLatch2.countDown();
|
||||||
}
|
}
|
||||||
|
@ -277,7 +278,7 @@ public class SynReplyTest extends AbstractTest
|
||||||
@Override
|
@Override
|
||||||
public void onData(Stream stream, DataInfo dataInfo)
|
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);
|
Assert.assertEquals(clientData, data);
|
||||||
clientDataLatch.countDown();
|
clientDataLatch.countDown();
|
||||||
}
|
}
|
||||||
|
@ -311,7 +312,7 @@ public class SynReplyTest extends AbstractTest
|
||||||
public void onData(Stream stream, DataInfo dataInfo)
|
public void onData(Stream stream, DataInfo dataInfo)
|
||||||
{
|
{
|
||||||
ByteBuffer buffer = dataInfo.asByteBuffer(false);
|
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);
|
Assert.assertEquals(serverData, data);
|
||||||
serverDataLatch.countDown();
|
serverDataLatch.countDown();
|
||||||
}
|
}
|
||||||
|
@ -361,7 +362,7 @@ public class SynReplyTest extends AbstractTest
|
||||||
@Override
|
@Override
|
||||||
public void onData(Stream stream, DataInfo dataInfo)
|
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);
|
Assert.assertEquals(data, chunk);
|
||||||
dataLatch.countDown();
|
dataLatch.countDown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.eclipse.jetty.spring;
|
package org.eclipse.jetty.spring;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
|
@ -80,7 +81,7 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor
|
||||||
: new ByteArrayResource(("" +
|
: new ByteArrayResource(("" +
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||||
"<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">" +
|
"<!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()
|
_beanFactory = new DefaultListableBeanFactory()
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.util;
|
package org.eclipse.jetty.util;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
@ -72,7 +73,7 @@ public abstract class AbstractTrie<V> implements Trie<V>
|
||||||
@Override
|
@Override
|
||||||
public V getBest(byte[] b, int offset, int len)
|
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
|
@Override
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.util;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.charset.UnsupportedCharsetException;
|
import java.nio.charset.UnsupportedCharsetException;
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,7 +66,7 @@ public class B64Code
|
||||||
*/
|
*/
|
||||||
public static String encode(String s)
|
public static String encode(String s)
|
||||||
{
|
{
|
||||||
return encode(s,null);
|
return encode(s, (Charset)null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,12 +81,25 @@ public class B64Code
|
||||||
{
|
{
|
||||||
byte[] bytes;
|
byte[] bytes;
|
||||||
if (charEncoding==null)
|
if (charEncoding==null)
|
||||||
bytes=s.getBytes(Charset.forName(StringUtil.__ISO_8859_1));
|
bytes=s.getBytes(StandardCharsets.ISO_8859_1);
|
||||||
else
|
else
|
||||||
bytes=s.getBytes(Charset.forName(charEncoding));
|
bytes=s.getBytes(Charset.forName(charEncoding));
|
||||||
return new String(encode(bytes));
|
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.
|
* Fast Base 64 encode as described in RFC 1421.
|
||||||
* <p>Does not insert whitespace as described in RFC 1521.
|
* <p>Does not insert whitespace as described in RFC 1521.
|
||||||
|
@ -236,6 +250,24 @@ public class B64Code
|
||||||
return new String(decoded,Charset.forName(charEncoding));
|
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.
|
* Fast Base 64 decode as described in RFC 1421.
|
||||||
*
|
*
|
||||||
|
|
|
@ -29,6 +29,7 @@ import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.channels.FileChannel.MapMode;
|
import java.nio.channels.FileChannel.MapMode;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------------- */
|
||||||
|
@ -454,7 +455,7 @@ public class BufferUtil
|
||||||
*/
|
*/
|
||||||
public static String toString(ByteBuffer buffer)
|
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)
|
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)
|
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)
|
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);
|
ByteBuffer buf = ByteBuffer.allocateDirect(bytes.length);
|
||||||
buf.put(bytes);
|
buf.put(bytes);
|
||||||
buf.flip();
|
buf.flip();
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
@ -211,7 +212,7 @@ public class ByteArrayISO8859Writer extends Writer
|
||||||
if (_bout==null)
|
if (_bout==null)
|
||||||
{
|
{
|
||||||
_bout = new ByteArrayOutputStream2(2*length);
|
_bout = new ByteArrayOutputStream2(2*length);
|
||||||
_writer = new OutputStreamWriter(_bout,StringUtil.__ISO_8859_1);
|
_writer = new OutputStreamWriter(_bout,StandardCharsets.ISO_8859_1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_bout.reset();
|
_bout.reset();
|
||||||
|
|
|
@ -29,6 +29,7 @@ import java.io.PrintWriter;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
@ -311,7 +312,7 @@ public class IO
|
||||||
public static String toString(InputStream in)
|
public static String toString(InputStream in)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
return toString(in,null);
|
return toString(in,(Charset)null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
@ -319,6 +320,14 @@ public class IO
|
||||||
*/
|
*/
|
||||||
public static String toString(InputStream in,String encoding)
|
public static String toString(InputStream in,String encoding)
|
||||||
throws IOException
|
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();
|
StringWriter writer=new StringWriter();
|
||||||
InputStreamReader reader = encoding==null?new InputStreamReader(in):new InputStreamReader(in,encoding);
|
InputStreamReader reader = encoding==null?new InputStreamReader(in):new InputStreamReader(in,encoding);
|
||||||
|
|
|
@ -29,6 +29,7 @@ import java.io.FilterInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -475,7 +476,7 @@ public class MultiPartInputStreamParser
|
||||||
}
|
}
|
||||||
|
|
||||||
String boundary="--"+contentTypeBoundary;
|
String boundary="--"+contentTypeBoundary;
|
||||||
byte[] byteBoundary=(boundary+"--").getBytes(StringUtil.__ISO_8859_1);
|
byte[] byteBoundary=(boundary+"--").getBytes(StandardCharsets.ISO_8859_1);
|
||||||
|
|
||||||
// Get first boundary
|
// Get first boundary
|
||||||
String line = null;
|
String line = null;
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.util;
|
||||||
import java.io.FilterOutputStream;
|
import java.io.FilterOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
|
||||||
/* ================================================================ */
|
/* ================================================================ */
|
||||||
|
@ -53,7 +54,7 @@ public class MultiPartOutputStream extends FilterOutputStream
|
||||||
|
|
||||||
boundary = "jetty"+System.identityHashCode(this)+
|
boundary = "jetty"+System.identityHashCode(this)+
|
||||||
Long.toString(System.currentTimeMillis(),36);
|
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)
|
public MultiPartOutputStream(OutputStream out, String boundary)
|
||||||
|
@ -62,7 +63,7 @@ public class MultiPartOutputStream extends FilterOutputStream
|
||||||
super(out);
|
super(out);
|
||||||
|
|
||||||
this.boundary = boundary;
|
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(boundaryBytes);
|
||||||
out.write(__CRLF);
|
out.write(__CRLF);
|
||||||
if (contentType != null)
|
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);
|
||||||
out.write(__CRLF);
|
out.write(__CRLF);
|
||||||
}
|
}
|
||||||
|
@ -128,11 +129,11 @@ public class MultiPartOutputStream extends FilterOutputStream
|
||||||
out.write(boundaryBytes);
|
out.write(boundaryBytes);
|
||||||
out.write(__CRLF);
|
out.write(__CRLF);
|
||||||
if (contentType != null)
|
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);
|
||||||
for (int i=0;headers!=null && i<headers.length;i++)
|
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);
|
||||||
}
|
}
|
||||||
out.write(__CRLF);
|
out.write(__CRLF);
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.util;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ReadLineInputStream
|
* ReadLineInputStream
|
||||||
|
@ -58,7 +59,7 @@ public class ReadLineInputStream extends BufferedInputStream
|
||||||
int m=markpos;
|
int m=markpos;
|
||||||
markpos=-1;
|
markpos=-1;
|
||||||
if (pos>m)
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +78,7 @@ public class ReadLineInputStream extends BufferedInputStream
|
||||||
_skipLF=true;
|
_skipLF=true;
|
||||||
int m=markpos;
|
int m=markpos;
|
||||||
markpos=-1;
|
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')
|
if (b=='\n')
|
||||||
|
@ -91,7 +92,7 @@ public class ReadLineInputStream extends BufferedInputStream
|
||||||
}
|
}
|
||||||
int m=markpos;
|
int m=markpos;
|
||||||
markpos=-1;
|
markpos=-1;
|
||||||
return new String(buf,m,pos-m-1,StringUtil.__UTF8_CHARSET);
|
return new String(buf,m,pos-m-1,StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,14 @@ package org.eclipse.jetty.util;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
|
||||||
/** Fast String Utilities.
|
/** 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
|
* performance improvements over most standard library versions. The
|
||||||
* main aim of the optimizations is to avoid object creation unless
|
* main aim of the optimizations is to avoid object creation unless
|
||||||
* absolutely required.
|
* absolutely required.
|
||||||
|
@ -50,18 +51,29 @@ public class StringUtil
|
||||||
public final static String __UTF8="UTF-8";
|
public final static String __UTF8="UTF-8";
|
||||||
public final static String __UTF16="UTF-16";
|
public final static String __UTF16="UTF-16";
|
||||||
|
|
||||||
public final static Charset __UTF8_CHARSET;
|
/**
|
||||||
public final static Charset __ISO_8859_1_CHARSET;
|
* @deprecated Use {@link StandardCharsets#UTF_8}
|
||||||
public final static Charset __UTF16_CHARSET;
|
*/
|
||||||
public final static Charset __US_ASCII_CHARSET;
|
@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
|
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("UTF-8",__UTF8);
|
||||||
CHARSETS.put("UTF8",__UTF8);
|
CHARSETS.put("UTF8",__UTF8);
|
||||||
CHARSETS.put("UTF-16",__UTF16);
|
CHARSETS.put("UTF-16",__UTF16);
|
||||||
|
@ -343,7 +355,7 @@ public class StringUtil
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
public static String toUTF8String(byte[] b,int offset,int length)
|
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)
|
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)
|
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)
|
public static byte[] getBytes(String s,String charset)
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -215,7 +216,7 @@ public class TreeTrie<V> extends AbstractTrie<V>
|
||||||
public V getBest(String s, int offset, int len)
|
public V getBest(String s, int offset, int len)
|
||||||
{
|
{
|
||||||
// TODO inefficient
|
// 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);
|
return getBest(b,0,b.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.util;
|
package org.eclipse.jetty.util;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,7 +44,13 @@ public class URIUtil
|
||||||
public static final String HTTPS_COLON="https:";
|
public static final String HTTPS_COLON="https:";
|
||||||
|
|
||||||
// Use UTF-8 as per http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars
|
// 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()
|
private URIUtil()
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -59,15 +60,16 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
|
||||||
public static final Charset ENCODING;
|
public static final Charset ENCODING;
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
Charset encoding=null;
|
Charset encoding;
|
||||||
try
|
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)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
LOG.warn(e);
|
LOG.warn(e);
|
||||||
encoding=StringUtil.__UTF8_CHARSET;
|
encoding=StandardCharsets.UTF_8;
|
||||||
}
|
}
|
||||||
ENCODING=encoding;
|
ENCODING=encoding;
|
||||||
}
|
}
|
||||||
|
@ -269,7 +271,6 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
|
||||||
* @param offset the offset within raw to decode from
|
* @param offset the offset within raw to decode from
|
||||||
* @param length the length of the section to decode
|
* @param length the length of the section to decode
|
||||||
* @param map the {@link MultiMap} to populate
|
* @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)
|
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
|
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);
|
StringWriter buf = new StringWriter(8192);
|
||||||
IO.copy(input,buf,maxLength);
|
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 (charset==null)
|
||||||
{
|
{
|
||||||
if (ENCODING==StringUtil.__UTF8_CHARSET)
|
if (ENCODING.equals(StandardCharsets.UTF_8))
|
||||||
decodeUtf8To(in,map,maxLength,maxKeys);
|
decodeUtf8To(in,map,maxLength,maxKeys);
|
||||||
else
|
else
|
||||||
decodeTo(in,map,ENCODING,maxLength,maxKeys);
|
decodeTo(in,map,ENCODING,maxLength,maxKeys);
|
||||||
|
@ -636,19 +637,19 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
|
||||||
if (charset==null)
|
if (charset==null)
|
||||||
charset=ENCODING;
|
charset=ENCODING;
|
||||||
|
|
||||||
if (StringUtil.__UTF8_CHARSET.equals(charset))
|
if (StandardCharsets.UTF_8.equals(charset))
|
||||||
{
|
{
|
||||||
decodeUtf8To(in,map,maxLength,maxKeys);
|
decodeUtf8To(in,map,maxLength,maxKeys);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtil.__ISO_8859_1_CHARSET.equals(charset))
|
if (StandardCharsets.ISO_8859_1.equals(charset))
|
||||||
{
|
{
|
||||||
decode88591To(in,map,maxLength,maxKeys);
|
decode88591To(in,map,maxLength,maxKeys);
|
||||||
return;
|
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);
|
decodeUtf16To(in,map,maxLength,maxKeys);
|
||||||
return;
|
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)
|
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;
|
Utf8StringBuffer buffer=null;
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.eclipse.jetty.util.security;
|
package org.eclipse.jetty.util.security;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.StringUtil;
|
import org.eclipse.jetty.util.StringUtil;
|
||||||
|
@ -156,7 +157,7 @@ public abstract class Credential implements Serializable
|
||||||
{
|
{
|
||||||
if (__md == null) __md = MessageDigest.getInstance("MD5");
|
if (__md == null) __md = MessageDigest.getInstance("MD5");
|
||||||
__md.reset();
|
__md.reset();
|
||||||
__md.update(credentials.toString().getBytes(StringUtil.__ISO_8859_1));
|
__md.update(credentials.toString().getBytes(StandardCharsets.ISO_8859_1));
|
||||||
digest = __md.digest();
|
digest = __md.digest();
|
||||||
}
|
}
|
||||||
if (digest == null || digest.length != _digest.length) return false;
|
if (digest == null || digest.length != _digest.length) return false;
|
||||||
|
@ -213,7 +214,7 @@ public abstract class Credential implements Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
__md.reset();
|
__md.reset();
|
||||||
__md.update(password.getBytes(StringUtil.__ISO_8859_1));
|
__md.update(password.getBytes(StandardCharsets.ISO_8859_1));
|
||||||
digest = __md.digest();
|
digest = __md.digest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue