在KeyVaultClient Java中将代理设置为AuthenticationContext无效

我想运行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服务器中会显示“未知主机”异常。

hll008 回答:在KeyVaultClient Java中将代理设置为AuthenticationContext无效

我不确定以下方法是否有帮助,但是您可以尝试一下。

您可以尝试查找代理的直接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可能有效。

本文链接:https://www.f2er.com/3155370.html

大家都在问