Skip to content

Commit

Permalink
8240666: Websocket client’s OpeningHandshake discards the HTTP respon…
Browse files Browse the repository at this point in the history
…se body

The fix updates jdk.internal.net.http.websocket. OpeningHandshake.send() method to process the response body from server

Reviewed-by: chegar, dfuchs, prappo
  • Loading branch information
Rahul Yadav authored and Julia Boes committed May 6, 2020
1 parent 9f86d94 commit ed24927
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Expand Up @@ -188,7 +188,7 @@ static URI createRequestURI(URI uri) {


public CompletableFuture<Result> send() { public CompletableFuture<Result> send() {
PrivilegedAction<CompletableFuture<Result>> pa = () -> PrivilegedAction<CompletableFuture<Result>> pa = () ->
client.sendAsync(this.request, BodyHandlers.discarding()) client.sendAsync(this.request, BodyHandlers.ofString())
.thenCompose(this::resultFrom); .thenCompose(this::resultFrom);
return AccessController.doPrivileged(pa); return AccessController.doPrivileged(pa);
} }
Expand Down
@@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,6 +23,7 @@


/* /*
* @test * @test
* @bug 8240666
* @summary Basic test for WebSocketHandshakeException * @summary Basic test for WebSocketHandshakeException
* @library /test/lib * @library /test/lib
* @build jdk.test.lib.net.SimpleSSLContext * @build jdk.test.lib.net.SimpleSSLContext
Expand Down Expand Up @@ -55,7 +56,9 @@
import static java.net.http.HttpClient.Builder.NO_PROXY; import static java.net.http.HttpClient.Builder.NO_PROXY;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
import static java.lang.System.out;


public class WSHandshakeExceptionTest { public class WSHandshakeExceptionTest {


Expand Down Expand Up @@ -107,6 +110,9 @@ public void test(String uri, boolean sameClient) {
} }
WebSocketHandshakeException wse = (WebSocketHandshakeException) t; WebSocketHandshakeException wse = (WebSocketHandshakeException) t;
assertNotNull(wse.getResponse()); 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); assertEquals(wse.getResponse().statusCode(), 404);
} }
} }
Expand Down

0 comments on commit ed24927

Please sign in to comment.