1 |
ajm |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
|
|
package uk.ac.ukc.iscream.filter.plugins; |
3 |
|
|
|
4 |
|
|
//---IMPORTS--- |
5 |
|
|
import uk.ac.ukc.iscream.filter.PluginServiceCheck; |
6 |
|
|
import java.net.URL; |
7 |
|
|
import java.net.URLConnection; |
8 |
|
|
|
9 |
|
|
/** |
10 |
|
|
* A first REAL service check! ;-) |
11 |
|
|
* Connects on port 80 and performs a simple HTTP HEAD request. |
12 |
|
|
* Currently it sends back 200 for OK, anything else indicates a failure. |
13 |
|
|
* |
14 |
|
|
* @author $Author: ajm4 $ |
15 |
|
|
* @version $Id: Test__ServiceCheck.java,v 1.4 2001/02/11 18:17:38 ajm4 Exp $ |
16 |
|
|
*/ |
17 |
|
|
public class HTTP__ServiceCheck implements PluginServiceCheck { |
18 |
|
|
|
19 |
|
|
//---FINAL ATTRIBUTES--- |
20 |
|
|
|
21 |
|
|
/** |
22 |
|
|
* The current CVS revision of this class |
23 |
|
|
*/ |
24 |
|
|
public final String REVISION = "$Revision: 1.4 $"; |
25 |
|
|
|
26 |
|
|
public final String DESC = "Checks that a webserver is responding to requests."; |
27 |
|
|
|
28 |
|
|
//---STATIC METHODS--- |
29 |
|
|
|
30 |
|
|
//---CONSTRUCTORS--- |
31 |
|
|
|
32 |
|
|
//---PUBLIC METHODS--- |
33 |
|
|
|
34 |
|
|
/** |
35 |
|
|
* Performs the service check on a given host. |
36 |
|
|
* |
37 |
|
|
* @param hostname the host to check |
38 |
|
|
*/ |
39 |
|
|
public String runServiceCheck(String hostname){ |
40 |
|
|
HttpURLConnection connection = (HttpURLConnection) ((new URL("HTTP://" + hostname)).openConnection()); |
41 |
|
|
// only get the head as we don't want any real content |
42 |
|
|
connection.setRequestMethod("HEAD"); |
43 |
|
|
// let the server know who we are, just to be nice, and get our name about ;p |
44 |
|
|
connection.setRequestProperty("User-Agent", "i-scream HTTP Service Checker v" + revision.substring(11, revision.length() - 2)); |
45 |
|
|
// connect and do the request |
46 |
|
|
connection.connect(); |
47 |
|
|
// send the results back |
48 |
|
|
return "<HTTP status=\"" + connection.getResponseCode() + "\" message=\"" + connection.getResponseMessage() + "\"></HTTP>"; |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
/** |
52 |
|
|
* return the String representation of what the filter does |
53 |
|
|
*/ |
54 |
|
|
public String getDescription(){ |
55 |
|
|
return DESC; |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
//---PRIVATE METHODS--- |
59 |
|
|
|
60 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
61 |
|
|
|
62 |
|
|
//---ATTRIBUTES--- |
63 |
|
|
|
64 |
|
|
//---STATIC ATTRIBUTES--- |
65 |
|
|
|
66 |
|
|
} |