11package com .unidev .httpclient .apache ;
22
3- import com .unidev .platform .Randoms ;
4- import com .unidev .platform .Strings ;
53import com .unidev .httpclient .socks .PlainSocksSocketFactory ;
64import com .unidev .httpclient .socks .SSLSocksSocketFactory ;
7- import java .io .IOException ;
8- import java .util .List ;
9- import java .util .concurrent .TimeUnit ;
5+ import com .unidev .platform .Randoms ;
6+ import com .unidev .platform .Strings ;
107import org .apache .commons .collections4 .CollectionUtils ;
11- import org .apache .http .Header ;
12- import org .apache .http .HttpEntity ;
13- import org .apache .http .HttpHost ;
14- import org .apache .http .HttpResponse ;
15- import org .apache .http .StatusLine ;
8+ import org .apache .http .*;
169import org .apache .http .client .ClientProtocolException ;
1710import org .apache .http .client .HttpClient ;
1811import org .apache .http .client .config .RequestConfig ;
19- import org .apache .http .client .methods .HttpDelete ;
20- import org .apache .http .client .methods .HttpGet ;
21- import org .apache .http .client .methods .HttpHead ;
22- import org .apache .http .client .methods .HttpPatch ;
23- import org .apache .http .client .methods .HttpPost ;
24- import org .apache .http .client .methods .HttpPut ;
25- import org .apache .http .client .methods .HttpUriRequest ;
12+ import org .apache .http .client .methods .*;
2613import org .apache .http .config .RegistryBuilder ;
2714import org .apache .http .conn .socket .ConnectionSocketFactory ;
2815import org .apache .http .cookie .Cookie ;
3623import org .apache .http .protocol .HttpContext ;
3724import org .apache .http .util .EntityUtils ;
3825
26+ import java .io .IOException ;
27+ import java .util .List ;
28+ import java .util .concurrent .TimeUnit ;
29+
3930/**
4031 * Basic HTTP client, used to get stuff from web pages
4132 */
@@ -111,9 +102,9 @@ public void init(String socksIP, int socksPort) {
111102 */
112103 protected RequestConfig .Builder buildRequestConfig () {
113104 return RequestConfig .custom ().setCircularRedirectsAllowed (true )
114- .setConnectTimeout (connectionTimeout )
115- .setConnectionRequestTimeout (connectionTimeout )
116- .setSocketTimeout (connectionTimeout );
105+ .setConnectTimeout (connectionTimeout )
106+ .setConnectionRequestTimeout (connectionTimeout )
107+ .setSocketTimeout (connectionTimeout );
117108 }
118109
119110 /**
@@ -142,11 +133,11 @@ public String get(String url, Header... headers) throws IOException {
142133 rsp = httpClient .execute (httpget , context );
143134
144135 HttpUriRequest currentReq = (HttpUriRequest ) context .getAttribute (
145- ExecutionContext .HTTP_REQUEST );
136+ ExecutionContext .HTTP_REQUEST );
146137 HttpHost currentHost = (HttpHost ) context .getAttribute (
147- ExecutionContext .HTTP_TARGET_HOST );
138+ ExecutionContext .HTTP_TARGET_HOST );
148139 currentUrl = (currentReq .getURI ().isAbsolute ()) ? currentReq .getURI ().toString ()
149- : (currentHost .toURI () + currentReq .getURI ());
140+ : (currentHost .toURI () + currentReq .getURI ());
150141
151142 HttpEntity entity = rsp .getEntity ();
152143 lastResponseHeaders = rsp .getAllHeaders ();
@@ -159,7 +150,7 @@ public String get(String url, Header... headers) throws IOException {
159150 }
160151
161152 public HttpEntity getAsEntity (String url , Header ... headers )
162- throws ClientProtocolException , IOException {
153+ throws ClientProtocolException , IOException {
163154 HttpGet httpget = new HttpGet (url );
164155 copyHeaders (httpget , headers );
165156 rsp = httpClient .execute (httpget , context );
@@ -199,11 +190,11 @@ public String post(String url, HttpEntity data, Header... headers) throws IOExce
199190 rsp = httpClient .execute (httpPost , context );
200191
201192 HttpUriRequest currentReq = (HttpUriRequest ) context .getAttribute (
202- ExecutionContext .HTTP_REQUEST );
193+ ExecutionContext .HTTP_REQUEST );
203194 HttpHost currentHost = (HttpHost ) context .getAttribute (
204- ExecutionContext .HTTP_TARGET_HOST );
195+ ExecutionContext .HTTP_TARGET_HOST );
205196 currentUrl = (currentReq .getURI ().isAbsolute ()) ? currentReq .getURI ().toString ()
206- : (currentHost .toURI () + currentReq .getURI ());
197+ : (currentHost .toURI () + currentReq .getURI ());
207198
208199 HttpEntity entity = rsp .getEntity ();
209200
@@ -217,7 +208,7 @@ public String post(String url, HttpEntity data, Header... headers) throws IOExce
217208 }
218209
219210 public HttpEntity postAsEntity (String url , Header ... headers )
220- throws ClientProtocolException , IOException {
211+ throws ClientProtocolException , IOException {
221212 HttpPost httpPost = new HttpPost (url );
222213 copyHeaders (httpPost , headers );
223214
@@ -311,10 +302,10 @@ public Cookie getCookie(String name) {
311302
312303 private void createProxyConnectionManager (String socksIP , int socksPort ) {
313304 connectionManager = new PoolingHttpClientConnectionManager (
314- RegistryBuilder .<ConnectionSocketFactory >create ()
315- .register ("http" , new PlainSocksSocketFactory (socksIP , socksPort ))
316- .register ("https" , new SSLSocksSocketFactory (socksIP , socksPort ))
317- .build ()
305+ RegistryBuilder .<ConnectionSocketFactory >create ()
306+ .register ("http" , new PlainSocksSocketFactory (socksIP , socksPort ))
307+ .register ("https" , new SSLSocksSocketFactory (socksIP , socksPort ))
308+ .build ()
318309 );
319310 }
320311
@@ -403,7 +394,7 @@ public PoolingHttpClientConnectionManager getConnectionManager() {
403394 }
404395
405396 public void setConnectionManager (
406- PoolingHttpClientConnectionManager connectionManager ) {
397+ PoolingHttpClientConnectionManager connectionManager ) {
407398 this .connectionManager = connectionManager ;
408399 }
409400}
0 commit comments