|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2018-2022 Maxprograms. |
| 3 | + * |
| 4 | + * This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Public License 1.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * https://www.eclipse.org/org/documents/epl-v10.html |
| 8 | + * |
| 9 | + * Contributors: |
| 10 | + * Maxprograms - initial API and implementation |
| 11 | + *******************************************************************************/ |
| 12 | + |
| 13 | +package com.maxprograms.tmxserver; |
| 14 | + |
| 15 | +import java.io.IOException; |
| 16 | +import java.lang.System.Logger; |
| 17 | +import java.lang.System.Logger.Level; |
| 18 | +import java.net.HttpURLConnection; |
| 19 | +import java.net.URL; |
| 20 | + |
| 21 | +public class CheckURL { |
| 22 | + |
| 23 | + protected static final Logger LOGGER = System.getLogger(CheckURL.class.getName()); |
| 24 | + |
| 25 | + public static void main(String[] args) { |
| 26 | + if (args.length < 1) { |
| 27 | + return; |
| 28 | + } |
| 29 | + checkURL(args[0]); |
| 30 | + } |
| 31 | + |
| 32 | + protected static void checkURL(String string) { |
| 33 | + boolean waiting = true; |
| 34 | + int count = 0; |
| 35 | + while (waiting && count < 40) { |
| 36 | + try { |
| 37 | + connect(string); |
| 38 | + waiting = false; |
| 39 | + } catch (IOException e) { |
| 40 | + try { |
| 41 | + Thread.sleep(500); |
| 42 | + count++; |
| 43 | + } catch (InterruptedException e1) { |
| 44 | + LOGGER.log(Level.ERROR, e1.getMessage(), e1); |
| 45 | + Thread.currentThread().interrupt(); |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + if (count < 40) { |
| 50 | + LOGGER.log(Level.INFO, "ready"); |
| 51 | + } else { |
| 52 | + System.exit(1); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + private static void connect(String string) throws IOException { |
| 57 | + URL url = new URL(string); |
| 58 | + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
| 59 | + connection.setConnectTimeout(1000); |
| 60 | + connection.connect(); |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments