View Javadoc
1   /*
2    * Copyright 2010 Capgemini
3    * Licensed under the Apache License, Version 2.0 (the "License"); 
4    * you may not use this file except in compliance with the License. 
5    * You may obtain a copy of the License at 
6    * 
7    * http://www.apache.org/licenses/LICENSE-2.0 
8    * 
9    * Unless required by applicable law or agreed to in writing, software 
10   * distributed under the License is distributed on an "AS IS" BASIS, 
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
12   * See the License for the specific language governing permissions and 
13   * limitations under the License. 
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   * @author Nicolas Richeton
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  }