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.system;
19 import java.util.HashMap;
22 import org.hedgecode.chess.scanner.proxy.ProxyParams;
23 import org.hedgecode.chess.scanner.proxy.ProxyType;
26 * Setter for system proxy settings.
28 * @author Dmitry Samoshin aka gotty
30 public final class SystemProxy {
32 private static final Map<ProxyType, ProxySetter> setters = new HashMap<ProxyType, ProxySetter>() {
34 put( ProxyType.HTTP, new HttpSetter() );
35 put( ProxyType.SOCKS, new SocksSetter() );
39 public static void setProxy(ProxyParams proxyParams) {
41 proxyParams.getType(),
42 proxyParams.getHost(),
43 proxyParams.getPort(),
44 proxyParams.getUser(),
45 proxyParams.getPassword()
49 public static void setProxy(ProxyType type, String host, int port) {
50 setProxy(type, host, port, null, null);
53 public static void setProxy(ProxyType type, String host, int port, String user, String password) {
54 ProxySetter proxySetter = setters.get(type);
55 if (proxySetter != null) {
56 proxySetter.setProxyHost(host);
57 proxySetter.setProxyPort(port);
59 proxySetter.setProxyAuth(user, password);