【发布时间】:2020-03-02 11:05:08
【问题描述】:
我想运行我的 Java 代码以在 Windows 服务器中使用代理读取 Azure KeyVault。
我浏览了很多帖子,但可以找到任何可行的解决方案。主要用于 c#,但我想要用于 Java。我的代码在我的本地机器上运行良好,但是当我尝试在需要设置代理的 Pre-Prod Windows 服务器中运行相同的代码时不起作用。
AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
context = new AuthenticationContext(authorization, false, service);
//added below 2 lines but don't see any effect
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.server.com", 80));
context.setProxy(proxy);
ClientCredential credentials = new ClientCredential(clientId, clientKey);
Future<AuthenticationResult> future = context.acquireToken(
resource, credentials, null);
result = future.get();
当我在本地机器上运行代码时,无论有没有代理设置,它都运行良好,但在那个 Windows 服务器中,它显示“未知主机”异常。
【问题讨论】:
-
这是一个很奇怪的现象。能否请您登录windows服务器看看是否可以得到
proxy.server.com的任何回复? -
该代理服务器在其他 Rest API 调用中运行良好,如下面的
String urlString = "https://myapiurl/api"; Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.server.com", 80)); HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection(proxy);没有代理,上面的代码无法在该 Windows 服务器上运行。所以 Azure Keyvault 读取的 java 代码应该以同样的方式工作,但是唉!
标签: java azure proxy azure-keyvault java-client