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.2 by ajm, Sun Feb 11 22:56:02 2001 UTC

# Line 4 | Line 4 | package uk.ac.ukc.iscream.filter.plugins;
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! ;-)
# Line 37 | Line 37 | public class HTTP__ServiceCheck implements PluginServi
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      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines