简体   繁体   中英

How to check if Java is using configured proxy server?

I have the -Dhttps.proxyHost= set in the run command, is there some kind of logging I can enable to see when it is proxying a call? I need to verify that this is working.

I have also whitelisted a number of hosts via -Dhttp.nonProxyHosts= so I want to make sure it is not proxying these.

1. Using java.util.logging

Create logging.properties file with the following contents:

handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = ALL
sun.net.www.protocol.http.HttpURLConnection.level = FINEST

Then add -Djava.util.logging.config.file=/path/to/logging.properties JVM option.

Now you'll see log messages whenever HTTPS connection is established through a proxy:

May 30, 2020 2:12:56 AM sun.net.www.protocol.http.HttpURLConnection plainConnect0
FINEST: ProxySelector Request for https://example.com/
May 30, 2020 2:12:56 AM sun.net.www.protocol.https.HttpsClient New
FINEST: Looking for HttpClient for URL https://example.com and proxy value of HTTP @ 127.0.0.1:443
May 30, 2020 2:12:56 AM sun.net.www.protocol.https.HttpsClient <init>
FINEST: Creating new HttpsClient with url:https://example.com and proxy:HTTP @ 127.0.0.1:443 with connect timeout:-1
May 30, 2020 2:12:56 AM sun.net.www.protocol.http.HttpURLConnection plainConnect0
FINEST: Proxy used: HTTP @ 127.0.0.1:443

2. Another option, assuming you are on Linux, is to trace all connect system calls:

$ sudo strace -f -p <PID> -e connect

After attaching to a Java process <PID> with strace , you'll see all addresses where the process connects to. If a proxy is used, there will be an address of the proxy.

[pid 12345] connect(263, {sa_family=AF_INET, sin_port=htons(443), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM