@@ -157,20 +157,25 @@ static HttpRequest newRequest(final HttpRequestFactory requestFactory, final Met
157
157
158
158
public void setProxy (final String proxyHost , final int proxyPort , final String proxyUsername , final String proxyPassword ) {
159
159
160
- if (proxyHost == null || proxyUsername == null || proxyPassword == null ) {
160
+ if (proxyHost == null || proxyPort == 0 ) {
161
161
return ;
162
162
}
163
163
164
- final BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider ();
165
- final AuthScope proxyAuthScope = new AuthScope (proxyHost , proxyPort );
166
- UsernamePasswordCredentials proxyAuthentication =
167
- new UsernamePasswordCredentials (proxyUsername , proxyPassword );
168
- basicCredentialsProvider .setCredentials (proxyAuthScope , proxyAuthentication );
169
-
170
164
final HttpHost proxy = new HttpHost (proxyHost , proxyPort );
171
- final HttpClient client = HttpClientBuilder .create ().setProxy (proxy ).setDefaultCredentialsProvider (basicCredentialsProvider ).build ();
172
- final ApacheHttpTransport transport = new ApacheHttpTransport (client );
173
- this .HTTP_TRANSPORT = transport ;
165
+ HttpClientBuilder clientBuilder = HttpClientBuilder .create ().setProxy (proxy );
166
+
167
+ if (proxyUsername != null && proxyUsername .length () != 0 && proxyPassword != null && proxyPassword .length () != 0 ) {
168
+ final BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider ();
169
+ final AuthScope proxyAuthScope = new AuthScope (proxyHost , proxyPort );
170
+ UsernamePasswordCredentials proxyAuthentication =
171
+ new UsernamePasswordCredentials (proxyUsername , proxyPassword );
172
+ basicCredentialsProvider .setCredentials (proxyAuthScope , proxyAuthentication );
173
+
174
+ clientBuilder .setDefaultCredentialsProvider (basicCredentialsProvider );
175
+ }
176
+
177
+ final HttpClient client = clientBuilder .build ();
178
+ HTTP_TRANSPORT = new ApacheHttpTransport (client );
174
179
this .requestFactory = newRequestFactory ();
175
180
}
176
181
0 commit comments