From 2e34ecd6d2481f86d88ab7cd872915b4111b23e2 Mon Sep 17 00:00:00 2001 From: yuwe Date: Thu, 2 Feb 2023 10:04:18 +0800 Subject: [PATCH] #2209 reset ProxySelector when exit plugin --- .../java/com/microsoft/azure/maven/AbstractAzureMojo.java | 1 + .../azure/toolkit/lib/common/proxy/ProxyManager.java | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/azure-maven-plugin-lib/src/main/java/com/microsoft/azure/maven/AbstractAzureMojo.java b/azure-maven-plugin-lib/src/main/java/com/microsoft/azure/maven/AbstractAzureMojo.java index ae66142707..1d32be9947 100755 --- a/azure-maven-plugin-lib/src/main/java/com/microsoft/azure/maven/AbstractAzureMojo.java +++ b/azure-maven-plugin-lib/src/main/java/com/microsoft/azure/maven/AbstractAzureMojo.java @@ -321,6 +321,7 @@ public void execute() throws MojoExecutionException { } catch (InterruptedException e) { // swallow this exception } + ProxyManager.getInstance().resetProxy(); ApacheSenderFactory.INSTANCE.create().close(); } } diff --git a/azure-toolkit-libs/azure-toolkit-common-lib/src/main/java/com/microsoft/azure/toolkit/lib/common/proxy/ProxyManager.java b/azure-toolkit-libs/azure-toolkit-common-lib/src/main/java/com/microsoft/azure/toolkit/lib/common/proxy/ProxyManager.java index b81b286b26..6d95583dc5 100644 --- a/azure-toolkit-libs/azure-toolkit-common-lib/src/main/java/com/microsoft/azure/toolkit/lib/common/proxy/ProxyManager.java +++ b/azure-toolkit-libs/azure-toolkit-common-lib/src/main/java/com/microsoft/azure/toolkit/lib/common/proxy/ProxyManager.java @@ -30,6 +30,7 @@ public class ProxyManager { // isSystemProxyUnset shows whether user specify the proxy through -Djava.net.useSystemProxies // see: https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html private static final boolean isSystemProxyUnset = StringUtils.isBlank(System.getProperty(PROPERTY_USE_SYSTEM_PROXY)); + private final ProxySelector defaultProxySelector = ProxySelector.getDefault(); public boolean isProxyEnabled() { return StringUtils.isNotBlank(Azure.az().config().getProxySource()); @@ -95,6 +96,10 @@ public PasswordAuthentication getPasswordAuthentication() { } } + public void resetProxy() { + ProxySelector.setDefault(this.defaultProxySelector); + } + private ProxyInfo getSystemProxy() { // we need to init at the program start before any internet access if (isSystemProxyUnset) {