--- a/test/jdk/java/net/httpclient/websocket/DummyWebSocketServer.java Tue Jan 30 13:52:40 2018 +0000
+++ b/test/jdk/java/net/httpclient/websocket/DummyWebSocketServer.java Tue Jan 30 17:28:12 2018 +0000
@@ -80,7 +80,7 @@
* Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
* Sec-WebSocket-Protocol: chat
*/
-public final class DummyWebSocketServer implements Closeable {
+public class DummyWebSocketServer implements Closeable {
private final AtomicBoolean started = new AtomicBoolean();
private final Thread thread;
@@ -108,12 +108,7 @@
List<String> strings = asList(request.toString().split("\r\n"));
List<String> response = mapping.apply(strings);
writeResponse(channel, response);
- // Read until the thread is interrupted or an error occurred
- // or the input is shutdown
- ByteBuffer b = ByteBuffer.allocate(1024);
- while (channel.read(b) != -1) {
- b.clear();
- }
+ serve(channel);
} catch (IOException e) {
err.println("Error in connection: " + channel + ", " + e);
} finally {
@@ -133,6 +128,15 @@
thread.setDaemon(false);
}
+ protected void serve(SocketChannel channel) throws IOException {
+ // Read until the thread is interrupted or an error occurred
+ // or the input is shutdown
+ ByteBuffer b = ByteBuffer.allocate(1024);
+ while (channel.read(b) != -1) {
+ b.clear();
+ }
+ }
+
public void open() throws IOException {
err.println("Starting");
if (!started.compareAndSet(false, true)) {