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
11
12
13
14
15
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 }