1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.appstatus.demo.check;
17
18 import java.io.IOException;
19
20 import net.sf.appstatus.core.check.AbstractCheck;
21
22 import org.apache.http.client.ClientProtocolException;
23 import org.apache.http.client.HttpClient;
24 import org.apache.http.client.ResponseHandler;
25 import org.apache.http.client.methods.HttpGet;
26 import org.apache.http.impl.client.BasicResponseHandler;
27 import org.apache.http.impl.client.DefaultHttpClient;
28
29
30
31
32
33 public abstract class AbstractHttpCheck extends AbstractCheck {
34
35 protected String doHttpGet(String url) throws ClientProtocolException,
36 IOException {
37
38 HttpClient httpclient = new DefaultHttpClient();
39 HttpGet httpget = new HttpGet(url);
40 ResponseHandler<String> responseHandler = new BasicResponseHandler();
41
42 try {
43 String responseBody = httpclient.execute(httpget, responseHandler);
44 return responseBody;
45 } finally {
46 httpclient.getConnectionManager().shutdown();
47 }
48
49 }
50 }