View Javadoc
1   package com.foxinmy.weixin4j.http.support.apache4;
2   
3   import org.apache.http.util.VersionInfo;
4   
5   import com.foxinmy.weixin4j.http.HttpClient;
6   import com.foxinmy.weixin4j.http.HttpParams;
7   import com.foxinmy.weixin4j.http.factory.HttpClientFactory;
8   
9   /**
10   * 使用Apache的HttpClient4.x
11   * 
12   * @className HttpComponent4Factory
13   * @author jinyu(foxinmy@gmail.com)
14   * @date 2015年8月12日
15   * @since JDK 1.6
16   */
17  public class HttpComponent4Factory extends HttpClientFactory {
18  
19  	private static HttpClientFactory httpComponentFactory;
20  	static {
21  		VersionInfo version = VersionInfo.loadVersionInfo(
22  				"org.apache.http.client", HttpClient.class.getClassLoader());
23  		String release = (version != null) ? version.getRelease()
24  				: VersionInfo.UNAVAILABLE;
25  		if (release.startsWith("4.")) {
26  			if (release.startsWith("4.0") || release.startsWith("4.1")
27  					|| release.startsWith("4.2")) {
28  				httpComponentFactory = new HttpComponent4_1Factory();
29  			} else {
30  				httpComponentFactory = new HttpComponent4_2Factory();
31  			}
32  		} else {
33  			throw new RuntimeException("unknown the HttpComponent version:"
34  					+ release);
35  		}
36  	}
37  
38  	@Override
39  	public HttpClient newInstance(HttpParams params) {
40  		return httpComponentFactory.newInstance(params);
41  	}
42  }