WWW monitoring
Hi there,
I need to create a piece of code to monitor www sites. I have found some code belowe, but have a question about it. What is the best way to examine whether site is up or not? By reading content of the site or http headers?
Code belowe sets default authenticator. But what if I have 100 sites to maintain and each has its own password?
Regards,
Kordian
import java.net.*;
import java.io.*;
public class httpISmonitoring {
public static void main(String[] args) throws Exception {
// TODO, add your application code
Authenticator.setDefault(new MyAuthenticator());
URL aURL = new URL("http://126.177.38.245:5555/");
BufferedReader in = new BufferedReader(
new InputStreamReader(
aURL.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
System.out.println("protocol = " + aURL.getProtocol());
System.out.println("authority = " + aURL.getAuthority());
System.out.println("host = " + aURL.getHost());
System.out.println("port = " + aURL.getPort());
System.out.println("path = " + aURL.getPath());
System.out.println("query = " + aURL.getQuery());
System.out.println("filename = " + aURL.getFile());
System.out.println("ref = " + aURL.getRef());
in.close();
}
}
class TestAuthenticator extends Authenticator {
private static String username = "xxxx";
private static String password = "yyyy";
public TestAuthenticator() {}
public PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(username,(password.toCharArray()));
}
}

