1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.filter.plugins; |
2 |
> |
package uk.org.iscream.filter.plugins; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.filter.PluginServiceCheck; |
5 |
> |
import uk.org.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! ;-) |
35 |
|
* Performs the service check on a given host. |
36 |
|
* |
37 |
|
* @param hostname the host to check |
38 |
+ |
* @return XML data representing the result of the test |
39 |
|
*/ |
40 |
|
public String runServiceCheck(String hostname){ |
41 |
< |
HttpURLConnection connection = (HttpURLConnection) ((new URL("HTTP://" + hostname)).openConnection()); |
42 |
< |
// only get the head as we don't want any real content |
43 |
< |
connection.setRequestMethod("HEAD"); |
44 |
< |
// let the server know who we are, just to be nice, and get our name about ;p |
45 |
< |
connection.setRequestProperty("User-Agent", "i-scream HTTP Service Checker v" + revision.substring(11, revision.length() - 2)); |
46 |
< |
// connect and do the request |
47 |
< |
connection.connect(); |
41 |
> |
String status = ""; |
42 |
> |
String message = ""; |
43 |
> |
try { |
44 |
> |
HttpURLConnection connection = (HttpURLConnection) ((new URL("HTTP://" + hostname)).openConnection()); |
45 |
> |
// only get the head as we don't want any real content |
46 |
> |
connection.setRequestMethod("HEAD"); |
47 |
> |
// let the server know who we are, just to be nice, and get our name about ;p |
48 |
> |
connection.setRequestProperty("User-Agent", "i-scream HTTP Service Checker v" + REVISION.substring(11, REVISION.length() - 2)); |
49 |
> |
// connect and do the request |
50 |
> |
connection.connect(); |
51 |
> |
if (connection.getResponseCode() == 200 ) { |
52 |
> |
status = "0"; |
53 |
> |
} else { |
54 |
> |
status = "1"; |
55 |
> |
} |
56 |
> |
message = connection.getResponseMessage(); |
57 |
> |
connection.disconnect(); |
58 |
> |
} catch (Exception e) { |
59 |
> |
status = "1"; |
60 |
> |
message = "Service check failed to establish connection to host:" + e.getMessage(); |
61 |
> |
} |
62 |
|
// send the results back |
63 |
< |
return "<HTTP status=\"" + connection.getResponseCode() + "\" message=\"" + connection.getResponseMessage() + "\"></HTTP>"; |
63 |
> |
return "<HTTP status=\"" + status + "\" message=\"" + message + "\"></HTTP>"; |
64 |
|
} |
65 |
|
|
66 |
|
/** |