From ed24927500ed3bb95da6e1c4140331d5f5ccac3e Mon Sep 17 00:00:00 2001 From: Rahul Yadav Date: Wed, 6 May 2020 17:33:32 +0100 Subject: [PATCH] =?UTF-8?q?8240666:=20Websocket=20client=E2=80=99s=20Openi?= =?UTF-8?q?ngHandshake=20discards=20the=20HTTP=20response=20body?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fix updates jdk.internal.net.http.websocket. OpeningHandshake.send() method to process the response body from server Reviewed-by: chegar, dfuchs, prappo --- .../jdk/internal/net/http/websocket/OpeningHandshake.java | 2 +- .../httpclient/websocket/WSHandshakeExceptionTest.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/websocket/OpeningHandshake.java b/src/java.net.http/share/classes/jdk/internal/net/http/websocket/OpeningHandshake.java index 63270bf5a5c..79397ad99d9 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/websocket/OpeningHandshake.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/websocket/OpeningHandshake.java @@ -188,7 +188,7 @@ public class OpeningHandshake { public CompletableFuture send() { PrivilegedAction> pa = () -> - client.sendAsync(this.request, BodyHandlers.discarding()) + client.sendAsync(this.request, BodyHandlers.ofString()) .thenCompose(this::resultFrom); return AccessController.doPrivileged(pa); } diff --git a/test/jdk/java/net/httpclient/websocket/WSHandshakeExceptionTest.java b/test/jdk/java/net/httpclient/websocket/WSHandshakeExceptionTest.java index 8702a49549f..d25d6c8e5ea 100644 --- a/test/jdk/java/net/httpclient/websocket/WSHandshakeExceptionTest.java +++ b/test/jdk/java/net/httpclient/websocket/WSHandshakeExceptionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,6 +23,7 @@ /* * @test + * @bug 8240666 * @summary Basic test for WebSocketHandshakeException * @library /test/lib * @build jdk.test.lib.net.SimpleSSLContext @@ -55,7 +56,9 @@ import java.util.concurrent.Executors; import static java.net.http.HttpClient.Builder.NO_PROXY; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; +import static java.lang.System.out; public class WSHandshakeExceptionTest { @@ -107,6 +110,9 @@ public class WSHandshakeExceptionTest { } WebSocketHandshakeException wse = (WebSocketHandshakeException) t; assertNotNull(wse.getResponse()); + out.println("Status code is " + wse.getResponse().statusCode()); + out.println("Response is " + wse.getResponse().body()); + assertTrue(((String)wse.getResponse().body()).contains("404")); assertEquals(wse.getResponse().statusCode(), 404); } }