我想运行 Java 代码以在 Windows 服务器中使用代理读取 Azure KeyVault。
我浏览了很多帖子,但可以找到任何可行的解决方案。主要针对 c#,但我想要针对 Java。我的代码在本地计算机上运行良好,但是当我尝试在预生产 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 服务器中,它显示“未知主机”异常。
最佳答案
我不确定以下内容是否有帮助,但您可以尝试一下。
您可以尝试找到代理的直接IP,并在代码中使用它:
InetAddress[] allByName = InetAddress.getAllByName("proxy.server.com");
for (InetAddress address : allByName) {
System.out.println(address.getHostAddress());
}
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(allByName[0].getHostAddress(),80););
或者
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(InetAddress.getByName("proxy.server.com"),80));
也许直接IP可以工作。
关于java - 在 KeyVaultClient java 中将代理设置为 AuthenticationContext 没有效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58722098/