Add code for enabling SSL Debug logs

This commit is contained in:
anujgaud 2024-01-18 22:13:33 +05:30 committed by GitHub
parent 9801f1eb7d
commit 4b5a9dfbad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,32 @@
package com.baeldung.enablessldebug;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SSLDebugLogger {
private static final Logger logger = LoggerFactory.getLogger(SSLDebugLogger.class);
public static void enableSSLDebugUsingSystemProperties() {
System.setProperty("javax.net.debug", "ssl");
}
public static void makeHttpsRequest() throws Exception {
String url = "https://github.com/eugenp/tutorials";
URL httpsUrl = new URL(url);
HttpsURLConnection connection = (HttpsURLConnection) httpsUrl.openConnection();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String line;
logger.info("Response from " + url + ":");
while ((line = reader.readLine()) != null) {
logger.info(line);
}
}
}
}