Skip to content

Commit

Permalink
8304962: sun/net/www/http/KeepAliveCache/B5045306.java: java.lang.Run…
Browse files Browse the repository at this point in the history
…timeException: Failed: Initial Keep Alive Connection is not being reused

Backport-of: cddaf686e16424e9543be50a48b1c02337e79cf1
  • Loading branch information
Amos Shi committed Aug 8, 2024
1 parent f07c266 commit cf21d29
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions test/jdk/sun/net/www/http/KeepAliveCache/B5045306.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
Expand All @@ -40,7 +40,6 @@
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -176,9 +175,9 @@ public void handle(HttpExchange trans) {
byte[] responseBody = new byte[RESPONSE_DATA_LENGTH];
for (int i=0; i<responseBody.length; i++)
responseBody[i] = 0x41;
trans.sendResponseHeaders(200, 0);
try(PrintWriter pw = new PrintWriter(trans.getResponseBody(), false, Charset.forName("UTF-8"))) {
pw.print(responseBody);
trans.sendResponseHeaders(200, responseBody.length);
try (OutputStream os = trans.getResponseBody()) {
os.write(responseBody);
}
} else if (path.equals("/secondCall")) {
int port2 = trans.getRemoteAddress().getPort();
Expand All @@ -201,10 +200,10 @@ public void handle(HttpExchange trans) {
responseBody[i] = 0x41;
// override the Content-length header to be greater than the actual response body
trans.sendResponseHeaders(200, responseBody.length+1);
try(PrintWriter pw = new PrintWriter(trans.getResponseBody(), false, Charset.forName("UTF-8"))) {
pw.print(responseBody);
}
OutputStream os = trans.getResponseBody();
os.write(responseBody);
// now close the socket
// closing the stream here would throw; close the exchange instead
trans.close();
}
} catch (Exception e) {
Expand Down

1 comment on commit cf21d29

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.