2 * Copyright (c) 2019-2020. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.chess.scanner.proxy.client;
19 import org.apache.http.HttpHost;
20 import org.apache.http.auth.AuthScope;
21 import org.apache.http.auth.UsernamePasswordCredentials;
22 import org.apache.http.client.CredentialsProvider;
23 import org.apache.http.client.protocol.HttpClientContext;
24 import org.apache.http.impl.client.BasicCredentialsProvider;
25 import org.apache.http.impl.client.CloseableHttpClient;
27 import org.apache.http.impl.client.HttpClientBuilder;
28 import org.hedgecode.chess.scanner.proxy.ProxyParams;
29 import org.hedgecode.chess.scanner.request.RequestClient;
34 * @author Dmitry Samoshin aka gotty
36 public class HttpRequestClient implements RequestClient {
38 private final HttpClientBuilder clientBuilder;
40 public HttpRequestClient(ProxyParams params) {
41 HttpHost proxy = new HttpHost(
42 params.getHost(), params.getPort()
44 clientBuilder = HttpClientBuilder.create().setProxy(proxy);
45 if (params.getUser() != null) {
46 CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
47 credentialsProvider.setCredentials(
49 params.getHost(), params.getPort()
51 new UsernamePasswordCredentials(
52 params.getUser(), params.getPassword()
55 clientBuilder.setDefaultCredentialsProvider(
62 public CloseableHttpClient getClient() {
63 return clientBuilder.build();
67 public HttpClientContext getContext() {
73 NTCredentials ntCreds = new NTCredentials(ntUsername, ntPassword,localMachineName, domainName );
75 CredentialsProvider credsProvider = new BasicCredentialsProvider();
76 credsProvider.setCredentials( new AuthScope(proxyHost,proxyPort), ntCreds );
77 HttpClientBuilder clientBuilder = HttpClientBuilder.create();
79 clientBuilder.useSystemProperties();
80 clientBuilder.setProxy(new HttpHost(pxInfo.getProxyURL(), pxInfo.getProxyPort()));
81 clientBuilder.setDefaultCredentialsProvider(credsProvider);
82 clientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
84 CloseableHttpClient client = clientBuilder.build();