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
Revision: 1.6
Committed: Mon Mar 5 15:57:28 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.5: +3 -3 lines
Log Message:
eek, bug

File Contents

# User Rev Content
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 ajm 1.2 import java.net.HttpURLConnection;
8 ajm 1.1
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 ajm 1.5 * @author $Author: ajm4 $
15 ajm 1.6 * @version $Id: HTTP__ServiceCheck.java,v 1.5 2001/03/05 15:46:12 ajm4 Exp $
16 ajm 1.1 */
17     public class HTTP__ServiceCheck implements PluginServiceCheck {
18    
19     //---FINAL ATTRIBUTES---
20    
21     /**
22     * The current CVS revision of this class
23     */
24 ajm 1.6 public final String REVISION = "$Revision: 1.5 $";
25 ajm 1.1
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 tdb 1.3 * @return XML data representing the result of the test
39 ajm 1.1 */
40     public String runServiceCheck(String hostname){
41 ajm 1.2 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 ajm 1.6 if (connection.getResponseCode() == 200 ) {
52 ajm 1.5 status = "0";
53 ajm 1.4 } else {
54 ajm 1.5 status = "1";
55 ajm 1.4 }
56 ajm 1.2 message = connection.getResponseMessage();
57     connection.disconnect();
58     } catch (Exception e) {
59 ajm 1.5 status = "1";
60 ajm 1.2 message = "Service check failed to establish connection to host:" + e.getMessage();
61     }
62 ajm 1.1 // send the results back
63 ajm 1.2 return "<HTTP status=\"" + status + "\" message=\"" + message + "\"></HTTP>";
64 ajm 1.1 }
65    
66     /**
67     * return the String representation of what the filter does
68     */
69     public String getDescription(){
70     return DESC;
71     }
72    
73     //---PRIVATE METHODS---
74    
75     //---ACCESSOR/MUTATOR METHODS---
76    
77     //---ATTRIBUTES---
78    
79     //---STATIC ATTRIBUTES---
80    
81     }