4 |
|
//---IMPORTS--- |
5 |
|
import uk.ac.ukc.iscream.filter.PluginServiceCheck; |
6 |
|
import java.net.URL; |
7 |
< |
import java.net.URLConnection; |
7 |
> |
import java.net.HttpURLConnection; |
8 |
|
|
9 |
|
/** |
10 |
|
* A first REAL service check! ;-) |
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(); |
40 |
> |
String status = ""; |
41 |
> |
String message = ""; |
42 |
> |
try { |
43 |
> |
HttpURLConnection connection = (HttpURLConnection) ((new URL("HTTP://" + hostname)).openConnection()); |
44 |
> |
// only get the head as we don't want any real content |
45 |
> |
connection.setRequestMethod("HEAD"); |
46 |
> |
// let the server know who we are, just to be nice, and get our name about ;p |
47 |
> |
connection.setRequestProperty("User-Agent", "i-scream HTTP Service Checker v" + REVISION.substring(11, REVISION.length() - 2)); |
48 |
> |
// connect and do the request |
49 |
> |
connection.connect(); |
50 |
> |
status += connection.getResponseCode(); |
51 |
> |
message = connection.getResponseMessage(); |
52 |
> |
connection.disconnect(); |
53 |
> |
} catch (Exception e) { |
54 |
> |
status = "0"; |
55 |
> |
message = "Service check failed to establish connection to host:" + e.getMessage(); |
56 |
> |
} |
57 |
|
// send the results back |
58 |
< |
return "<HTTP status=\"" + connection.getResponseCode() + "\" message=\"" + connection.getResponseMessage() + "\"></HTTP>"; |
58 |
> |
return "<HTTP status=\"" + status + "\" message=\"" + message + "\"></HTTP>"; |
59 |
|
} |
60 |
|
|
61 |
|
/** |