changeset 47278:b841be61b9d9

8181176: java/net/httpclient/websocket/ConnectionHandover.java times out Reviewed-by: coffeys
author chegar
date Tue, 26 Sep 2017 10:20:35 +0100
parents fae0bf9e361f
children b3a91921bafc
files test/jdk/java/net/httpclient/websocket/DummyWebSocketServer.java test/jdk/java/net/httpclient/websocket/LoggingHelper.java
diffstat 2 files changed, 17 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/java/net/httpclient/websocket/DummyWebSocketServer.java	Tue Sep 26 01:26:00 2017 -0400
+++ b/test/jdk/java/net/httpclient/websocket/DummyWebSocketServer.java	Tue Sep 26 10:20:35 2017 +0100
@@ -105,7 +105,7 @@
                         channel.configureBlocking(true);
                         StringBuilder request = new StringBuilder();
                         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> response = mapping.apply(strings);
@@ -156,6 +156,7 @@
     public void close() {
         log.log(INFO, "Stopping: " + getURI());
         thread.interrupt();
+        close(ssc);
     }
 
     URI getURI() {
@@ -169,19 +170,21 @@
             throws IOException
     {
         ByteBuffer buffer = ByteBuffer.allocate(512);
-        int num = channel.read(buffer);
-        if (num == -1) {
-            return false;
+        while (channel.read(buffer) != -1) {
+            // read the complete HTTP request headers, there should be no body
+            CharBuffer decoded;
+            buffer.flip();
+            try {
+                decoded = ISO_8859_1.newDecoder().decode(buffer);
+            } catch (CharacterCodingException e) {
+                throw new UncheckedIOException(e);
+            }
+            request.append(decoded);
+            if (Pattern.compile("\r\n\r\n").matcher(request).find())
+                return true;
+            buffer.clear();
         }
-        CharBuffer decoded;
-        buffer.flip();
-        try {
-            decoded = ISO_8859_1.newDecoder().decode(buffer);
-        } catch (CharacterCodingException e) {
-            throw new UncheckedIOException(e);
-        }
-        request.append(decoded);
-        return Pattern.compile("\r\n\r\n").matcher(request).find();
+        return false;
     }
 
     private void writeResponse(SocketChannel channel, List<String> response)
--- a/test/jdk/java/net/httpclient/websocket/LoggingHelper.java	Tue Sep 26 01:26:00 2017 -0400
+++ b/test/jdk/java/net/httpclient/websocket/LoggingHelper.java	Tue Sep 26 10:20:35 2017 +0100
@@ -32,7 +32,7 @@
      *     @run main/othervm/jul=logging.properties ClassUnderTest
      */
     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);
     }
 }