diff --git a/aliyun-java-sdk-core/src/main/java/com/aliyuncs/http/clients/ApacheHttpClient.java b/aliyun-java-sdk-core/src/main/java/com/aliyuncs/http/clients/ApacheHttpClient.java index 9c59f1d95d..917f4f176e 100644 --- a/aliyun-java-sdk-core/src/main/java/com/aliyuncs/http/clients/ApacheHttpClient.java +++ b/aliyun-java-sdk-core/src/main/java/com/aliyuncs/http/clients/ApacheHttpClient.java @@ -2,7 +2,7 @@ import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.http.*; -import com.aliyuncs.utils.EnvironmentUtils; +import com.aliyuncs.utils.EnvHelper; import com.aliyuncs.utils.IOUtils; import com.aliyuncs.utils.StringUtils; import org.apache.http.Header; @@ -271,16 +271,16 @@ private HttpUriRequest parseToHttpRequest(HttpRequest apiReq) throws IOException } private HttpHost calcProxy(HttpRequest apiReq) throws MalformedURLException, ClientException { - boolean needProxy = HttpUtil.needProxy(new URL(apiReq.getSysUrl()).getHost(), clientConfig.getNoProxy(), EnvironmentUtils.getNoProxy()); + boolean needProxy = HttpUtil.needProxy(new URL(apiReq.getSysUrl()).getHost(), clientConfig.getNoProxy(), EnvHelper.getenv("NO_PROXY")); if (!needProxy) { return null; } URL url = new URL(apiReq.getSysUrl()); HttpHost proxy = null; if ("https".equalsIgnoreCase(url.getProtocol())) { - proxy = HttpUtil.getApacheProxy(clientConfig.getHttpsProxy(), EnvironmentUtils.getHttpsProxy(), apiReq); + proxy = HttpUtil.getApacheProxy(clientConfig.getHttpsProxy(), EnvHelper.getenv("HTTPS_PROXY"), apiReq); } else { - proxy = HttpUtil.getApacheProxy(clientConfig.getHttpProxy(), EnvironmentUtils.getHttpProxy(), apiReq); + proxy = HttpUtil.getApacheProxy(clientConfig.getHttpProxy(), EnvHelper.getenv("HTTP_PROXY"), apiReq); } return proxy; } diff --git a/aliyun-java-sdk-core/src/main/java/com/aliyuncs/http/clients/CompatibleUrlConnClient.java b/aliyun-java-sdk-core/src/main/java/com/aliyuncs/http/clients/CompatibleUrlConnClient.java index d51356156b..f9095eb969 100644 --- a/aliyun-java-sdk-core/src/main/java/com/aliyuncs/http/clients/CompatibleUrlConnClient.java +++ b/aliyun-java-sdk-core/src/main/java/com/aliyuncs/http/clients/CompatibleUrlConnClient.java @@ -2,7 +2,7 @@ import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.http.*; -import com.aliyuncs.utils.EnvironmentUtils; +import com.aliyuncs.utils.EnvHelper; import org.apache.http.conn.ssl.DefaultHostnameVerifier; import org.apache.http.conn.ssl.NoopHostnameVerifier; @@ -169,16 +169,16 @@ private void checkHttpRequest(HttpRequest request) { private Proxy calcProxy(URL url, HttpRequest request) throws ClientException { String targetHost = url.getHost(); - boolean needProxy = HttpUtil.needProxy(targetHost, clientConfig.getNoProxy(), EnvironmentUtils.getNoProxy()); + boolean needProxy = HttpUtil.needProxy(targetHost, clientConfig.getNoProxy(), EnvHelper.getenv("NO_PROXY")); if (!needProxy) { return Proxy.NO_PROXY; } Proxy proxy; if ("https".equalsIgnoreCase(url.getProtocol())) { - String httpsProxy = EnvironmentUtils.getHttpsProxy(); + String httpsProxy = EnvHelper.getenv("HTTPS_PROXY"); proxy = HttpUtil.getJDKProxy(clientConfig.getHttpsProxy(), httpsProxy, request); } else { - String httpProxy = EnvironmentUtils.getHttpProxy(); + String httpProxy = EnvHelper.getenv("HTTP_PROXY"); proxy = HttpUtil.getJDKProxy(clientConfig.getHttpProxy(), httpProxy, request); } return proxy; diff --git a/aliyun-java-sdk-core/src/main/java/com/aliyuncs/utils/EnvironmentUtils.java b/aliyun-java-sdk-core/src/main/java/com/aliyuncs/utils/EnvironmentUtils.java deleted file mode 100644 index c31d02be66..0000000000 --- a/aliyun-java-sdk-core/src/main/java/com/aliyuncs/utils/EnvironmentUtils.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.aliyuncs.utils; - -public class EnvironmentUtils { - - private static volatile String httpProxy; - private static volatile String httpsProxy; - private static volatile String noProxy; - - public static String getHttpProxy() { - if (null == httpProxy) { - String proxy0 = System.getenv("HTTP_PROXY"); - String proxy1 = System.getenv("http_proxy"); - return (!StringUtils.isEmpty(proxy0) ? proxy0 : proxy1); - } else { - return httpProxy; - } - } - - public static void setHttpProxy(String httpProxy) { - EnvironmentUtils.httpProxy = httpProxy; - } - - public static String getHttpsProxy() { - if (null == httpsProxy) { - return System.getenv("HTTPS_PROXY"); - } else { - return httpsProxy; - } - } - - public static void setHttpsProxy(String httpsProxy) { - EnvironmentUtils.httpsProxy = httpsProxy; - } - - - public static String getNoProxy() { - if (null == noProxy) { - return System.getenv("NO_PROXY"); - } else { - return noProxy; - } - } - - public static void setNoProxy(String noProxy) { - EnvironmentUtils.noProxy = noProxy; - } - -} diff --git a/aliyun-java-sdk-core/src/test/java/com/aliyuncs/auth/EnvironmentVariableCredentialsProviderTest.java b/aliyun-java-sdk-core/src/test/java/com/aliyuncs/auth/EnvironmentVariableCredentialsProviderTest.java index 2e4962be96..c87536155b 100644 --- a/aliyun-java-sdk-core/src/test/java/com/aliyuncs/auth/EnvironmentVariableCredentialsProviderTest.java +++ b/aliyun-java-sdk-core/src/test/java/com/aliyuncs/auth/EnvironmentVariableCredentialsProviderTest.java @@ -3,7 +3,6 @@ import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.utils.AuthUtils; import com.aliyuncs.utils.EnvHelper; -import com.aliyuncs.utils.EnvironmentUtils; import org.junit.Assert; import org.junit.Test; diff --git a/aliyun-java-sdk-core/src/test/java/com/aliyuncs/utils/EnvironmentUtilsTest.java b/aliyun-java-sdk-core/src/test/java/com/aliyuncs/utils/EnvironmentUtilsTest.java deleted file mode 100644 index 45efa41988..0000000000 --- a/aliyun-java-sdk-core/src/test/java/com/aliyuncs/utils/EnvironmentUtilsTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.aliyuncs.utils; - -import org.junit.Assert; -import org.junit.Test; - -public class EnvironmentUtilsTest { - - @Test - public void testConstructor() { - Assert.assertNotNull(new EnvironmentUtils()); - } - - @Test - public void testGetSetHttpProxy() { - Assert.assertNull(EnvironmentUtils.getHttpProxy()); - EnvironmentUtils.setHttpProxy("http://www.aliyun.com"); - Assert.assertEquals("http://www.aliyun.com", EnvironmentUtils.getHttpProxy()); - } - - @Test - public void testGetSetHttpsProxy() { - Assert.assertNull(EnvironmentUtils.getHttpsProxy()); - EnvironmentUtils.setHttpsProxy("https://www.aliyun.com"); - Assert.assertEquals("https://www.aliyun.com", EnvironmentUtils.getHttpsProxy()); - } - - @Test - public void testGetSetNoProxy() { - Assert.assertNull(EnvironmentUtils.getNoProxy()); - EnvironmentUtils.setNoProxy("https://www.aliyun.com"); - Assert.assertEquals("https://www.aliyun.com", EnvironmentUtils.getNoProxy()); - } -}