MCPcopy Create free account
hub / github.com/Arronlong/httpclientutil / HCB

Class HCB

src/main/java/com/arronlong/httpclientutil/builder/HCB.java:37–241  ·  view source on GitHub ↗

httpclient创建者 @author arron @version 1.0

Source from the content-addressed store, hash-verified

35 * @version 1.0
36 */
37public class HCB extends HttpClientBuilder{
38
39 public boolean isSetPool=false;//记录是否设置了连接池
40 private SSLProtocolVersion sslpv=SSLProtocolVersion.SSLv3;//ssl 协议版本
41
42 //用于配置ssl
43 private SSLs ssls = SSLs.getInstance();
44
45 private HCB(){}
46 public static HCB custom(){
47 return new HCB();
48 }
49
50 /**
51 * 设置超时时间
52 *
53 * @param timeout 超市时间,单位-毫秒
54 * @return 返回当前对象
55 */
56 public HCB timeout(int timeout){
57 return timeout(timeout, true);
58 }
59
60 /**
61 * 设置超时时间以及是否允许网页重定向(自动跳转 302)
62 *
63 * @param timeout 超时时间,单位-毫秒
64 * @param redirectEnable 自动跳转
65 * @return 返回当前对象
66 */
67 public HCB timeout(int timeout, boolean redirectEnable){
68 // 配置请求的超时设置
69 RequestConfig config = RequestConfig.custom()
70 .setConnectionRequestTimeout(timeout)
71 .setConnectTimeout(timeout)
72 .setSocketTimeout(timeout)
73 .setRedirectsEnabled(redirectEnable)
74 .build();
75 return (HCB) this.setDefaultRequestConfig(config);
76 }
77
78 /**
79 * 设置ssl安全链接
80 *
81 * @return 返回当前对象
82 * @throws HttpProcessException http处理异常
83 */
84 public HCB ssl() throws HttpProcessException {
85// if(isSetPool){//如果已经设置过线程池,那肯定也就是https链接了
86// if(isNewSSL){
87// throw new HttpProcessException("请先设置ssl,后设置pool");
88// }
89// return this;
90// }
91// Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
92// .<ConnectionSocketFactory> create()
93// .register("http", PlainConnectionSocketFactory.INSTANCE)
94// .register("https", ssls.getSSLCONNSF()).build();

Callers

nothing calls this directly

Calls 1

getInstanceMethod · 0.95

Tested by

no test coverage detected