From c3b2b58fa309501c7f074f7e1a9eb679ba7b200b Mon Sep 17 00:00:00 2001 From: Osiris Team Date: Thu, 7 Sep 2023 22:36:00 +0200 Subject: [PATCH] 7.3.6 - Fixed google ping (again) --- pom.xml | 2 +- .../osiris/autoplug/client/SystemChecker.java | 12 +++++-- .../autoplug/client/SystemCheckerTest.java | 31 +++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 src/test/java/com/osiris/autoplug/client/SystemCheckerTest.java diff --git a/pom.xml b/pom.xml index 2a8e9d37..88418e72 100644 --- a/pom.xml +++ b/pom.xml @@ -229,7 +229,7 @@ org.junit.jupiter junit-jupiter - RELEASE + 5.9.2 test diff --git a/src/main/java/com/osiris/autoplug/client/SystemChecker.java b/src/main/java/com/osiris/autoplug/client/SystemChecker.java index 0a2d2dac..05333678 100644 --- a/src/main/java/com/osiris/autoplug/client/SystemChecker.java +++ b/src/main/java/com/osiris/autoplug/client/SystemChecker.java @@ -11,7 +11,9 @@ import com.osiris.jlib.logger.AL; import java.io.*; +import java.net.HttpURLConnection; import java.net.InetAddress; +import java.net.URL; public class SystemChecker { @@ -45,8 +47,14 @@ public void checkInternetAccess() throws Exception { boolean reachable = InetAddress.getByName("www.google.com").isReachable(10000); if (!reachable) throw new Exception("Failed to reach www.google.com!"); } catch (Exception e) { - System.err.println("Make sure that you have an internet connection!"); - throw e; + try { + HttpURLConnection connection = (HttpURLConnection) new URL("https://www.google.com").openConnection(); + connection.connect(); + connection.disconnect(); + } catch (Exception ex) { + System.err.println("Make sure that you have an internet connection!"); + throw ex; + } } } diff --git a/src/test/java/com/osiris/autoplug/client/SystemCheckerTest.java b/src/test/java/com/osiris/autoplug/client/SystemCheckerTest.java new file mode 100644 index 00000000..a13f61c0 --- /dev/null +++ b/src/test/java/com/osiris/autoplug/client/SystemCheckerTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Osiris-Team. + * All rights reserved. + * + * This software is copyrighted work, licensed under the terms + * of the MIT-License. Consult the "LICENSE" file for details. + */ + +package com.osiris.autoplug.client; + +import org.junit.jupiter.api.Test; + +import java.net.HttpURLConnection; +import java.net.InetAddress; +import java.net.URL; + +class SystemCheckerTest { + + @Test + void checkInternetAccessMethod1() throws Exception { + boolean reachable = InetAddress.getByName("www.google.com").isReachable(10000); + if (!reachable) throw new Exception("Failed to reach www.google.com!"); + } + + @Test + void checkInternetAccessMethod2() throws Exception { + HttpURLConnection connection = (HttpURLConnection) new URL("https://www.google.com").openConnection(); + connection.connect(); + connection.disconnect(); + } +} \ No newline at end of file