Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions test/jdk/java/net/httpclient/ProxyServer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, 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
Expand Down Expand Up @@ -42,7 +42,7 @@
* Two threads are created per client connection. So, it's not
* intended for large numbers of parallel connections.
*/
public class ProxyServer extends Thread implements Closeable {
public final class ProxyServer implements Closeable {

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

public ProxyServer(Integer port,
Boolean debug,
Credentials credentials)
private ProxyServer(Integer port, Boolean debug, Credentials credentials)
throws IOException
{
this.debug = debug;
Expand All @@ -110,15 +108,11 @@ public ProxyServer(Integer port,
listener.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), port));
this.port = ((InetSocketAddress)listener.getLocalAddress()).getPort();
this.credentials = credentials;
setName("ProxyListener");
setDaemon(true);
connections = new CopyOnWriteArrayList<Connection>();
start();
}

public ProxyServer(String s) {
credentials = null;
connections = new CopyOnWriteArrayList<Connection>();
Thread d = new Thread(() -> run());
d.setName("ProxyListener");
d.setDaemon(true);
d.start();
}

/**
Expand Down Expand Up @@ -150,7 +144,7 @@ public void close() throws IOException {

volatile boolean done;

public void run() {
private void run() {
if (System.getSecurityManager() == null) {
execute();
} else {
Expand Down Expand Up @@ -672,10 +666,11 @@ public static void main(String[] args) throws Exception {
int port = Integer.parseInt(args[0]);
boolean debug = args.length > 1 && args[1].equals("-debug");
System.out.println("Debugging : " + debug);
ProxyServer ps = new ProxyServer(port, debug);
System.out.println("Proxy server listening on port " + ps.getPort());
while (true) {
Thread.sleep(5000);
try (ProxyServer ps = new ProxyServer(port, debug)) {
System.out.println("Proxy server listening on port " + ps.getPort());
while (true) {
Thread.sleep(5000);
}
}
}
}