View Javadoc
1   package com.foxinmy.weixin4j.http.support.apache4;
2   
3   import java.io.IOException;
4   
5   import org.apache.http.client.methods.HttpRequestBase;
6   
7   import com.foxinmy.weixin4j.http.HttpClientException;
8   import com.foxinmy.weixin4j.http.HttpRequest;
9   import com.foxinmy.weixin4j.http.HttpResponse;
10  
11  /**
12   * Requires Apache HttpComponents 4.2 or lower
13   * 
14   * @className HttpComponent4_1
15   * @author jinyu(foxinmy@gmail.com)
16   * @date 2015年8月18日
17   * @since JDK 1.6
18   * @see
19   */
20  public class HttpComponent4_1 extends HttpComponent4 {
21  
22  	private final org.apache.http.client.HttpClient httpClient;
23  
24  	public HttpComponent4_1(org.apache.http.client.HttpClient httpClient) {
25  		this.httpClient = httpClient;
26  	}
27  
28  	@Override
29  	public HttpResponse execute(HttpRequest request) throws HttpClientException {
30  		HttpResponse response = null;
31  		try {
32  			HttpRequestBase uriRequest = createRequest(request);
33  			org.apache.http.HttpResponse httpResponse = httpClient
34  					.execute(uriRequest);
35  			response = new HttpComponent4_1Response(httpResponse,
36  					getContent(httpResponse));
37  			handleResponse(response);
38  		} catch (IOException e) {
39  			throw new HttpClientException("I/O error on "
40  					+ request.getMethod().name() + " request for \""
41  					+ request.getURI().toString(), e);
42  		} finally {
43  			if (response != null) {
44  				response.close();
45  			}
46  		}
47  		return response;
48  	}
49  }