X-Git-Url: https://git.hedgecode.org/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fhedgecode%2Fchess%2Fscanner%2Fproxy%2FProxy.java;h=f190008a20b4b95d79236c588dff5283fa62650f;hb=refs%2Fheads%2Fpgn;hp=7d75a72c180e604091e5ac533f0a56fdb42fe13b;hpb=573d7b45d42661d2798193bc58b588a99ab94451;p=chesshog-scanner.git diff --git a/src/main/java/org/hedgecode/chess/scanner/proxy/Proxy.java b/src/main/java/org/hedgecode/chess/scanner/proxy/Proxy.java index 7d75a72..f190008 100644 --- a/src/main/java/org/hedgecode/chess/scanner/proxy/Proxy.java +++ b/src/main/java/org/hedgecode/chess/scanner/proxy/Proxy.java @@ -16,62 +16,62 @@ package org.hedgecode.chess.scanner.proxy; -import org.hedgecode.chess.scanner.ChessHogScannerConstants; -import org.hedgecode.chess.scanner.proxy.type.HTTPSetter; -import org.hedgecode.chess.scanner.proxy.type.SOCKSSetter; +import org.hedgecode.chess.scanner.proxy.client.HttpRequestClient; +import org.hedgecode.chess.scanner.proxy.client.SocksRequestClient; +import org.hedgecode.chess.scanner.proxy.system.SystemProxy; +import org.hedgecode.chess.scanner.request.PlainRequestClient; +import org.hedgecode.chess.scanner.request.RequestClient; /** - * Setter for proxy settings. + * Proxy settings main class. * * @author Dmitry Samoshin aka gotty */ -public enum Proxy { +public final class Proxy { - UNDEFINED ( ChessHogScannerConstants.PROXY_UNDEFINED, null ), - HTTP ( ChessHogScannerConstants.PROXY_HTTP, new HTTPSetter() ), - SOCKS ( ChessHogScannerConstants.PROXY_SOCKS, new SOCKSSetter() ); + private static Proxy proxy; - private String name; - private ProxySetter setter; + private RequestClient requestClient; - Proxy(String name, ProxySetter setter) { - this.name = name; - this.setter = setter; + private Proxy() { + requestClient = new PlainRequestClient(); } - private ProxySetter getSetter() { - return setter; + public static void setProxy(ProxyParams proxyParams) { + getProxy().set(proxyParams); } - public static Proxy byName(String name) { - for (Proxy proxy : Proxy.values()) { - if (proxy.name.equals(name)) - return proxy; - } - return UNDEFINED; + public static RequestClient getRequestClient() { + return getProxy().client(); } - public static void setProxy(ProxyParams proxyParams) { - setProxy( - proxyParams.getType(), - proxyParams.getHost(), proxyParams.getPort(), - proxyParams.getUser(), proxyParams.getPassword() - ); + private void set(ProxyParams proxyParams) { + if (proxyParams.isSystem()) { + SystemProxy.setProxy(proxyParams); + requestClient = new PlainRequestClient(); + } else { + switch (proxyParams.getType()) { + case HTTP: + requestClient = new HttpRequestClient(proxyParams); + break; + case SOCKS: + requestClient = new SocksRequestClient(proxyParams); + break; + default: + requestClient = new PlainRequestClient(); + } + } } - public static void setProxy(Proxy type, String host, String port) { - setProxy(type, host, port, null, null); + private RequestClient client() { + return requestClient; } - public static void setProxy(Proxy type, String host, String port, String user, String password) { - ProxySetter proxySetter = type.getSetter(); - if (proxySetter != null) { - proxySetter.setProxyHost(host); - proxySetter.setProxyPort(port); - if (user != null) { - proxySetter.setProxyAuth(user, password); - } + private static Proxy getProxy() { + if (proxy == null) { + proxy = new Proxy(); } + return proxy; } }