ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/filter/plugins/HTTP__ServiceCheck.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/filter/plugins/HTTP__ServiceCheck.java (file contents):
Revision 1.1 by ajm, Sun Feb 11 22:36:07 2001 UTC vs.
Revision 1.7 by tdb, Wed Mar 14 23:25:29 2001 UTC

# Line 1 | Line 1
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! ;-)
# Line 35 | Line 35 | public class HTTP__ServiceCheck implements PluginServi
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      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines