Check if Glassfish DAS is running programmatically

后端 未结 3 888
南笙
南笙 2021-01-16 06:52

How to check if Glassfish DAS is running programmatically even if it is deployed on local machine or remote machine?

Using Java6

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-16 07:13

    I have found a way to check if DAS is up other than Linux script. With this way it does not matter if both my application and DAS are at same machine or each installed different machine.

    public static boolean isUrlReachable(String host) {
      String URLName="http://"+host+":4848";
      boolean isUp = false;
      try {
         HttpURLConnection.setFollowRedirects(false);
         HttpURLConnection con = (HttpURLConnection) new URL(URLName).openConnection();
         con.setRequestMethod("GET");
         isUp = (con.getResponseCode() == HttpURLConnection.HTTP_OK);
         con.disconnect();
      }
      catch (Exception e) {
         return isUp;
      }
    
      return isUp;
    

    }

提交回复
热议问题