@@ -157,20 +157,25 @@ static HttpRequest newRequest(final HttpRequestFactory requestFactory, final Met
157157
158158 public void setProxy (final String proxyHost , final int proxyPort , final String proxyUsername , final String proxyPassword ) {
159159
160- if (proxyHost == null || proxyUsername == null || proxyPassword == null ) {
160+ if (proxyHost == null || proxyPort == 0 ) {
161161 return ;
162162 }
163163
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-
170164 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 );
174179 this .requestFactory = newRequestFactory ();
175180 }
176181
0 commit comments