问题
I am working with Alfresco and sometimes the server is down for low space or other problem , the thing is with my serverURL i want to check if he is available (Alfresco Server) i thought to make a ping but the adresse is to complexe for a simple ping ex : http://127.0.0.1:8084/alfresco/api/-default-/public/cmis/versions/1.0/atom
I am working in a J2EE Project
回答1:
Hi i want to say that the part of the answer where given by @Gagravarr
public void pingADR() throws UnknownHostException, IOException {
String url = "http://127.0.0.1:8084/alfresco/service/api/server";
String status = getStatus(url);
System.out.println(url + "\t\tStatus:" + status);
}
and to see if it's available
public static String getStatus(String url) throws IOException {
String result = "";
try {
URL siteURL = new URL(url);
HttpURLConnection connection = (HttpURLConnection) siteURL
.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int code = connection.getResponseCode();
if (code == 200) {
result = "Green";
}
} catch (Exception e) {
result = "->Red<-";
}
return result;
}
I found this answer in a very helpful web site, Hope that will help other people
来源:https://stackoverflow.com/questions/38504722/see-if-alfresco-server-is-available