????/**
????* ??HttpURLConnection?????????????????????????????
????*
????* @param connection
????* @throws Exception
????*/
????private static void checkConnectionContent(HttpURLConnection connection) throws Exception {
????try (InputStream inputStream = connection.getInputStream()) {
????byte[] b = new byte[1024];
????boolean success = false;
????StringBuffer sb = new StringBuffer();
????for (int i = inputStream.read(b); i > 0; i = inputStream.read(b)) {
????String tempStr = new String(b?? 0?? i);
????sb.append(tempStr);
????if (tempStr.indexOf("3??file not found") >= 0) {// service????????????????????service???????????????
????success = true;
????break;
????}
????}
????if (!success) {
????String str = sb.toString();
????if (str.length() > 3) {
????char char0 = str.charAt(0);
????char char1 = str.charAt(1);
????if (Utils.isNumber(char0 + "") && char1 == '??') {
????success = true;
????}
????}
????}
????if (!success) {
????throw new RuntimeException("result content does not meet expectations.");
????}
????} catch (Exception ex) {
????throw ex;
????}
????}
????/**
????* ?????????????9067???
????*
????* @param networkBean
????* @throws Exception
????*/
????public static void testURLConnection() throws Exception {
????HttpURLConnection connection = (HttpURLConnection) new URL(GeneralWebServiceAddress.FILE_DOWN_URL_ADD + "path=").openConnection();
????checkConnectionContent(connection);
????}
????/**
????* ????????????????
????*/
????private void testProxyConnection() {
????NetworkBean readNetworkBean = NetworkProxyTool.readNetworkBean();// ????????????NetworkBean
????try {
????NetworkBean networkBean = createNetworkBean();// ?????????д???????????NetworkBean????
????showTestResultDialog(NetworkProxyTool.testNetworkProxyBySystem(networkBean));
????} catch (Exception ex) {
????showTestResultDialog(false);
????}
????NetworkProxyTool.setNetworkProxyBySystem(readNetworkBean);// ?????????????????NetworkBean
????}
????5.???java???????????????????????????????????????ò??????л????????????????????????????????????ò????????棬?????????????ò????????檔
????/**
????* ???ó?????????????????????
????*
????* @param keepAlive
????*/
????public static void setKeepAliveAndAuthCache(boolean keepAlive) {
????System.setProperty("http.keepAlive"?? keepAlive + "");// ???????????????????false??????????????棨???????????棬????????????????????????棩
????if (keepAlive) {
????AuthCacheValue.setAuthCache(new AuthCacheImpl());
????} else {
????// ?????????????AuthCache????????????????????????
????AuthCacheValue.setAuthCache(new AuthCache() {
????public void remove(String pkey?? AuthCacheValue entry) {
????}
????public void put(String pkey?? AuthCacheValue value) {
????}
????public AuthCacheValue get(String pkey?? String skey) {
????return null;
????}
????});
????}
????}
????????????
????NetworkProxyTool.setKeepAliveAndAuthCache(false);
????new.Login();
????????????
????NetworkProxyTool.setKeepAliveAndAuthCache(true);
????6.?????????????????
?????????????л???????????????????汾?????????????????????????????????????
?????????????????л??????????????????????????????????????Map??????????л?map??
????/**
????* ?????????????????????????
????*
????* @return
????*/
????public static NetworkBean readNetworkBean() {
????NetworkBean networkBean = getCurrNetworkBean(readNetworkBeanMap());
????if (networkBean == null) {
????networkBean = new NetworkBean();
????networkBean.setType(Proxy.Type.DIRECT);
????}
????return networkBean;
????}
????/**
????* ???????????????????????
????*
????* @param map
????* @return
????*/
????public static NetworkBean getCurrNetworkBean(Map map) {
????putBrowserProxy(map);
????return (NetworkBean) map.get(getTypeMapKey(map));
????}
????/**
????* ?????????????????????????????map
????*
????* @param map
????*/
????private static void putBrowserProxy(Map map) {
????if (browserProxyBean == null) {
????browserProxyBean = getBrowserProxy();
????}
????NetworkBean networkBeanBrowser = (NetworkBean) map.get(key_browser);
????if (networkBeanBrowser == null) {
????networkBeanBrowser = browserProxyBean;
????}
????if ((Utils.toString(browserProxyBean.getAddress()).isEmpty() || !browserProxyBean.getAddress().equals(networkBeanBrowser.getAddress()))
????|| (Utils.toString(browserProxyBean.getPort()).isEmpty() || !browserProxyBean.getPort().equals(networkBeanBrowser.getPort()))) {
????networkBeanBrowser.setUsername(null);
????networkBeanBrowser.setPassword(null);
????networkBeanBrowser.setDomain(null);
????}
????networkBeanBrowser.setType(browserProxyBean.getType());
????networkBeanBrowser.setTypeText(browserProxyBean.getTypeText());
????networkBeanBrowser.setAddress(browserProxyBean.getAddress());
????networkBeanBrowser.setPort(browserProxyBean.getPort());
????map.put(key_browser?? networkBeanBrowser);
????}
????????????
????NetworkBean networkBean = NetworkProxyTool.readNetworkBean();
????NetworkProxyTool.setNetworkProxyBySystem(networkBean);
????NetworkProxyTool.setKeepAliveAndAuthCache(false);
????new.Login();
??????????????????????????
????/**
????* ??????
????*/
????private void confirm() {
????if ((isHttp() || isSocks()) && !checkIpAndPortNotNull()) {
????return;
????}
????NetworkBean networkBean = createNetworkBean();
????if (isHttp()) {// HTTP????
????if (networkBean.getDomain() != null) {
????networkBean.setDomain(networkBean.getDomain().trim());
????}
????proxySettingMap.put(key_http?? networkBean);
????proxySettingMap.put(key_proxy_type?? key_http);
????} else if (isSocks()) {// SOCKS????
????proxySettingMap.put(key_socks?? networkBean);
????proxySettingMap.put(key_proxy_type?? key_socks);
????} else if (isBrowser()) {
????proxySettingMap.put(key_browser?? networkBean);
????proxySettingMap.put(key_proxy_type?? key_browser);
????} else {
????proxySettingMap.put(key_direct?? networkBean);
????proxySettingMap.put(key_proxy_type?? key_direct);
????}
????userCurrShowNetworkBean = networkBean;
????isConfirm = true;
????setVisible(false);
????NetworkProxyTool.saveNetworkProxyConfig(proxySettingMap);
????}