@@ -26,45 +26,39 @@ public class NativeHttpClient implements IHttpClient {
2626 private static final String KEYWORDS_READ_TIMED_OUT = "Read timed out" ;
2727
2828 private int _maxRetryTimes = 0 ;
29+ private String _authCode ;
30+ private HttpProxy _proxy ;
2931
30- public NativeHttpClient () {
31- this (DEFAULT_MAX_RETRY_TIMES );
32+ public NativeHttpClient (String authCode ) {
33+ this (authCode , DEFAULT_MAX_RETRY_TIMES , null );
3234 }
3335
34- public NativeHttpClient (int maxRetryTimes ) {
36+ public NativeHttpClient (String authCode , int maxRetryTimes , HttpProxy proxy ) {
3537 this ._maxRetryTimes = maxRetryTimes ;
3638 LOG .info ("Created instance with _maxRetryTimes = " + _maxRetryTimes );
3739
40+ this ._authCode = authCode ;
41+ this ._proxy = proxy ;
42+
3843 initSSL ();
3944 }
4045
41- public ResponseWrapper sendGet (String url , String params ,
42- String authCode ) throws APIConnectionException , APIRequestException {
43- return sendRequest (url , params , RequestMethod .GET , authCode , null );
46+ public ResponseWrapper sendGet (String url , String params )
47+ throws APIConnectionException , APIRequestException {
48+ return sendRequest (url , params , RequestMethod .GET );
4449 }
4550
46- public ResponseWrapper sendPost (String url , String content ,
47- String authCode ) throws APIConnectionException , APIRequestException {
48- return sendRequest (url , content , RequestMethod .POST , authCode , null );
51+ public ResponseWrapper sendPost (String url , String content )
52+ throws APIConnectionException , APIRequestException {
53+ return sendRequest (url , content , RequestMethod .POST );
4954 }
50-
51- public ResponseWrapper sendGet (String url , String params ,
52- String authCode , HttpProxy proxy ) throws APIConnectionException , APIRequestException {
53- return sendRequest (url , params , RequestMethod .GET , authCode , proxy );
54- }
55-
56- public ResponseWrapper sendPost (String url , String content ,
57- String authCode , HttpProxy proxy ) throws APIConnectionException , APIRequestException {
58- return sendRequest (url , content , RequestMethod .POST , authCode , proxy );
59- }
60-
61-
55+
6256 public ResponseWrapper sendRequest (String url , String content ,
63- RequestMethod method , String authCode , HttpProxy proxy ) throws APIConnectionException , APIRequestException {
57+ RequestMethod method ) throws APIConnectionException , APIRequestException {
6458 ResponseWrapper response = null ;
6559 for (int retryTimes = 0 ; ; retryTimes ++) {
6660 try {
67- response = _sendRequest (url , content , method , authCode , proxy );
61+ response = _sendRequest (url , content , method );
6862 break ;
6963 } catch (SocketTimeoutException e ) {
7064 if (KEYWORDS_READ_TIMED_OUT .equals (e .getMessage ())) {
@@ -83,7 +77,7 @@ public ResponseWrapper sendRequest(String url, String content,
8377 }
8478
8579 private ResponseWrapper _sendRequest (String url , String content ,
86- RequestMethod method , String authCode , HttpProxy proxy ) throws APIConnectionException , APIRequestException ,
80+ RequestMethod method ) throws APIConnectionException , APIRequestException ,
8781 SocketTimeoutException {
8882 LOG .debug ("Send request to - " + url );
8983 if (null != content ) {
@@ -98,10 +92,10 @@ private ResponseWrapper _sendRequest(String url, String content,
9892 try {
9993 URL aUrl = new URL (url );
10094
101- if (null != proxy ) {
102- conn = (HttpURLConnection ) aUrl .openConnection (proxy . getProxy ());
103- if (proxy .isAuthenticationNeeded ()) {
104- conn .addRequestProperty ("Proxy-Authorization" , proxy .getProxyAuthorization ());
95+ if (null != _proxy ) {
96+ conn = (HttpURLConnection ) aUrl .openConnection (_proxy . getNetProxy ());
97+ if (_proxy .isAuthenticationNeeded ()) {
98+ conn .setRequestProperty ("Proxy-Authorization" , _proxy .getProxyAuthorization ());
10599 }
106100 } else {
107101 conn = (HttpURLConnection ) aUrl .openConnection ();
@@ -115,7 +109,7 @@ private ResponseWrapper _sendRequest(String url, String content,
115109 conn .setRequestProperty ("Connection" , "Keep-Alive" );
116110 conn .setRequestProperty ("Accept-Charset" , CHARSET );
117111 conn .setRequestProperty ("Charset" , CHARSET );
118- conn .setRequestProperty ("Authorization" , authCode );
112+ conn .setRequestProperty ("Authorization" , _authCode );
119113
120114 if (RequestMethod .POST == method ) {
121115 conn .setDoOutput (true ); //POST Request
0 commit comments