Skip to content

Commit e7cf182

Browse files
committed
8364263: HttpClient: Improve encapsulation of ProxyServer
Backport-of: 190e113031bc6ece781fdf0d9f3c853ce324f170
1 parent a05de7d commit e7cf182

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

test/jdk/java/net/httpclient/ProxyServer.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -42,7 +42,7 @@
4242
* Two threads are created per client connection. So, it's not
4343
* intended for large numbers of parallel connections.
4444
*/
45-
public class ProxyServer extends Thread implements Closeable {
45+
public final class ProxyServer implements Closeable {
4646

4747
// could use the test library here - Platform.isWindows(),
4848
// but it would force all tests that use ProxyServer to
@@ -99,9 +99,7 @@ public ProxyServer(Integer port,
9999
this(port, debug, null);
100100
}
101101

102-
public ProxyServer(Integer port,
103-
Boolean debug,
104-
Credentials credentials)
102+
private ProxyServer(Integer port, Boolean debug, Credentials credentials)
105103
throws IOException
106104
{
107105
this.debug = debug;
@@ -110,15 +108,8 @@ public ProxyServer(Integer port,
110108
listener.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), port));
111109
this.port = ((InetSocketAddress)listener.getLocalAddress()).getPort();
112110
this.credentials = credentials;
113-
setName("ProxyListener");
114-
setDaemon(true);
115-
connections = new CopyOnWriteArrayList<Connection>();
116-
start();
117-
}
118-
119-
public ProxyServer(String s) {
120-
credentials = null;
121111
connections = new CopyOnWriteArrayList<Connection>();
112+
Thread.ofPlatform().name("ProxyListener").daemon().start(this::run);
122113
}
123114

124115
/**
@@ -150,7 +141,7 @@ public void close() throws IOException {
150141

151142
volatile boolean done;
152143

153-
public void run() {
144+
private void run() {
154145
if (System.getSecurityManager() == null) {
155146
execute();
156147
} else {
@@ -672,10 +663,11 @@ public static void main(String[] args) throws Exception {
672663
int port = Integer.parseInt(args[0]);
673664
boolean debug = args.length > 1 && args[1].equals("-debug");
674665
System.out.println("Debugging : " + debug);
675-
ProxyServer ps = new ProxyServer(port, debug);
676-
System.out.println("Proxy server listening on port " + ps.getPort());
677-
while (true) {
678-
Thread.sleep(5000);
666+
try (ProxyServer ps = new ProxyServer(port, debug)) {
667+
System.out.println("Proxy server listening on port " + ps.getPort());
668+
while (true) {
669+
Thread.sleep(5000);
670+
}
679671
}
680672
}
681673
}

0 commit comments

Comments
 (0)