X-Git-Url: https://git.hedgecode.org/?p=chesshog-scanner.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fhedgecode%2Fchess%2Fscanner%2Fproxy%2Fclient%2FHttpRequestClient.java;fp=src%2Fmain%2Fjava%2Forg%2Fhedgecode%2Fchess%2Fscanner%2Fproxy%2Fclient%2FHttpRequestClient.java;h=f3b8517fa7cdda8c61a60c903dc8382aac565ea0;hp=0000000000000000000000000000000000000000;hb=70d45ca74e19c98d0bef2a081f77fc1e3543691e;hpb=6e3a8590a26312b6cea579777db885107cae88df diff --git a/src/main/java/org/hedgecode/chess/scanner/proxy/client/HttpRequestClient.java b/src/main/java/org/hedgecode/chess/scanner/proxy/client/HttpRequestClient.java new file mode 100644 index 0000000..f3b8517 --- /dev/null +++ b/src/main/java/org/hedgecode/chess/scanner/proxy/client/HttpRequestClient.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2019-2020. Developed by Hedgecode. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.hedgecode.chess.scanner.proxy.client; + +import org.apache.http.HttpHost; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.CloseableHttpClient; + +import org.apache.http.impl.client.HttpClientBuilder; +import org.hedgecode.chess.scanner.proxy.ProxyParams; +import org.hedgecode.chess.scanner.request.RequestClient; + +/** + * HttpRequestClient + * + * @author Dmitry Samoshin aka gotty + */ +public class HttpRequestClient implements RequestClient { + + private final HttpClientBuilder clientBuilder; + + public HttpRequestClient(ProxyParams params) { + HttpHost proxy = new HttpHost( + params.getHost(), params.getPort() + ); + clientBuilder = HttpClientBuilder.create().setProxy(proxy); + if (params.getUser() != null) { + CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + credentialsProvider.setCredentials( + new AuthScope( + params.getHost(), params.getPort() + ), + new UsernamePasswordCredentials( + params.getUser(), params.getPassword() + ) + ); + clientBuilder.setDefaultCredentialsProvider( + credentialsProvider + ); + } + } + + @Override + public CloseableHttpClient getClient() { + return clientBuilder.build(); + } + + @Override + public HttpClientContext getContext() { + return null; + } + +/* + private void ntlm() { + NTCredentials ntCreds = new NTCredentials(ntUsername, ntPassword,localMachineName, domainName ); + + CredentialsProvider credsProvider = new BasicCredentialsProvider(); + credsProvider.setCredentials( new AuthScope(proxyHost,proxyPort), ntCreds ); + HttpClientBuilder clientBuilder = HttpClientBuilder.create(); + + clientBuilder.useSystemProperties(); + clientBuilder.setProxy(new HttpHost(pxInfo.getProxyURL(), pxInfo.getProxyPort())); + clientBuilder.setDefaultCredentialsProvider(credsProvider); + clientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); + + CloseableHttpClient client = clientBuilder.build(); + } +*/ + +}