diff --git a/src/IntWrapper.java b/src/IntWrapper.java new file mode 100644 index 0000000..f70e16a --- /dev/null +++ b/src/IntWrapper.java @@ -0,0 +1,9 @@ +/** + * Created to be able to pass ints by refs + */ +public class IntWrapper { + private int value; + public IntWrapper(int value) {this.value = value;} + public int getValue() {return value;} + public void setValue(int value) {this.value = value;} +} diff --git a/src/WebVerif.java b/src/WebVerif.java new file mode 100644 index 0000000..3c26a86 --- /dev/null +++ b/src/WebVerif.java @@ -0,0 +1,28 @@ +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; + +public class WebVerif implements Runnable { + private final String url; + private final IntWrapper status; + + public WebVerif(String url, IntWrapper status) { + this.status = status; + this.url = url; + } + + @Override + public void run() { + try { + HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + connection.connect(); + status.setValue(connection.getResponseCode()); + } catch (MalformedURLException e) { + status.setValue(HttpURLConnection.HTTP_BAD_REQUEST); + e.printStackTrace(); + } catch (IOException ex) { + status.setValue(500); + } + } +}