8181176: java/net/httpclient/websocket/ConnectionHandover.java times out

Reviewed-by: coffeys
This commit is contained in:
Chris Hegarty 2017-09-26 10:20:35 +01:00
parent da352d7930
commit b98d0bda76
2 changed files with 17 additions and 14 deletions

View file

@ -105,7 +105,7 @@ public final class DummyWebSocketServer implements Closeable {
channel.configureBlocking(true); channel.configureBlocking(true);
StringBuilder request = new StringBuilder(); StringBuilder request = new StringBuilder();
if (!readRequest(channel, request)) { if (!readRequest(channel, request)) {
throw new IOException("Bad request"); throw new IOException("Bad request:" + request);
} }
List<String> strings = asList(request.toString().split("\r\n")); List<String> strings = asList(request.toString().split("\r\n"));
List<String> response = mapping.apply(strings); List<String> response = mapping.apply(strings);
@ -156,6 +156,7 @@ public final class DummyWebSocketServer implements Closeable {
public void close() { public void close() {
log.log(INFO, "Stopping: " + getURI()); log.log(INFO, "Stopping: " + getURI());
thread.interrupt(); thread.interrupt();
close(ssc);
} }
URI getURI() { URI getURI() {
@ -169,10 +170,8 @@ public final class DummyWebSocketServer implements Closeable {
throws IOException throws IOException
{ {
ByteBuffer buffer = ByteBuffer.allocate(512); ByteBuffer buffer = ByteBuffer.allocate(512);
int num = channel.read(buffer); while (channel.read(buffer) != -1) {
if (num == -1) { // read the complete HTTP request headers, there should be no body
return false;
}
CharBuffer decoded; CharBuffer decoded;
buffer.flip(); buffer.flip();
try { try {
@ -181,7 +180,11 @@ public final class DummyWebSocketServer implements Closeable {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
request.append(decoded); request.append(decoded);
return Pattern.compile("\r\n\r\n").matcher(request).find(); if (Pattern.compile("\r\n\r\n").matcher(request).find())
return true;
buffer.clear();
}
return false;
} }
private void writeResponse(SocketChannel channel, List<String> response) private void writeResponse(SocketChannel channel, List<String> response)

View file

@ -32,7 +32,7 @@ public final class LoggingHelper {
* @run main/othervm/jul=logging.properties ClassUnderTest * @run main/othervm/jul=logging.properties ClassUnderTest
*/ */
public static void setupLogging() { public static void setupLogging() {
String path = System.getProperty("test.src") + File.separator + "logging.properties"; String path = System.getProperty("test.src", ".") + File.separator + "logging.properties";
System.setProperty("java.util.logging.config.file", path); System.setProperty("java.util.logging.config.file", path);
} }
} }