@@ 351-370 (lines=20) @@ | ||
348 | return n3; |
|
349 | } |
|
350 | ||
351 | private CloseableHttpClient createConnection() { |
|
352 | CloseableHttpClient httpClient = HttpClientBuilder.create().build(); |
|
353 | ||
354 | if (this.password != null) { |
|
355 | HttpHost targetHost = new HttpHost(this.host, this.port, this.protocol); |
|
356 | CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); |
|
357 | credentialsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), |
|
358 | new UsernamePasswordCredentials(this.user, this.password)); |
|
359 | ||
360 | httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build(); |
|
361 | ||
362 | AuthCache authCache = new BasicAuthCache(); |
|
363 | BasicScheme basicAuth = new BasicScheme(); |
|
364 | authCache.put(targetHost, basicAuth); |
|
365 | HttpClientContext context = HttpClientContext.create(); |
|
366 | context.setCredentialsProvider(credentialsProvider); |
|
367 | context.setAuthCache(authCache); |
|
368 | } |
|
369 | ||
370 | return httpClient; |
|
371 | } |
|
372 | ||
373 | private static void printLog(String classe, String method) { |
@@ 86-105 (lines=20) @@ | ||
83 | } |
|
84 | } |
|
85 | ||
86 | private CloseableHttpClient createConnection() { |
|
87 | CloseableHttpClient httpClient = HttpClientBuilder.create().build(); |
|
88 | ||
89 | if (this.password != null) { |
|
90 | HttpHost targetHost = new HttpHost(this.host, this.port, this.protocol); |
|
91 | CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); |
|
92 | credentialsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), |
|
93 | new UsernamePasswordCredentials(this.user, this.password)); |
|
94 | ||
95 | httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build(); |
|
96 | ||
97 | AuthCache authCache = new BasicAuthCache(); |
|
98 | BasicScheme basicAuth = new BasicScheme(); |
|
99 | authCache.put(targetHost, basicAuth); |
|
100 | HttpClientContext context = HttpClientContext.create(); |
|
101 | context.setCredentialsProvider(credentialsProvider); |
|
102 | context.setAuthCache(authCache); |
|
103 | } |
|
104 | ||
105 | return httpClient; |
|
106 | } |
|
107 | ||
108 | } |