在KeyVault客户端java中将代理设置为AuthenticationContext无效

在KeyVault客户端java中将代理设置为AuthenticationContext无效,java,azure,proxy,azure-keyvault,java-client,Java,Azure,Proxy,Azure Keyvault,Java Client,我想运行Java代码在Windows server中读取带有代理的Azure KeyVault 我看过很多帖子,但都能找到有效的解决方案。主要针对c#,但我想针对Java。我的代码在本地计算机上运行良好,但当我试图在需要设置代理的Pre-Prod Windows server中运行相同的代码时,该代码不起作用 AuthenticationContext context = null; AuthenticationResult result = null; Exec

我想运行Java代码在Windows server中读取带有代理的Azure KeyVault

我看过很多帖子,但都能找到有效的解决方案。主要针对c#,但我想针对Java。我的代码在本地计算机上运行良好,但当我试图在需要设置代理的Pre-Prod Windows server中运行相同的代码时,该代码不起作用

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();
AuthenticationContext=null;
AuthenticationResult=null;
ExecutorService=null;
试一试{
服务=Executors.newFixedThreadPool(1);
上下文=新的AuthenticationContext(授权、错误、服务);
//添加到2行以下,但看不到任何效果
Proxy Proxy=newproxy(Proxy.Type.HTTP,newinetsocketaddress(“Proxy.server.com”,80));
setProxy(proxy);
clientcredentials=newclientcredential(clientId,clientKey);
Future=context.acquireToken(
资源,凭据,空);
结果=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可以工作。

这是一个非常奇怪的现象。请检查windows服务器,看看是否可以从
proxy.server.com
获得任何答复?代理服务器在其他Rest API调用中工作正常,如下面的
String urlString=”https://myapiurl/api“代理=新代理(Proxy.Type.HTTP,新的InetSocketAddress(“Proxy.server.com”,80));HttpURLConnection conn=(HttpURLConnection)新的URL(urlString).openConnection(Proxy);
没有代理上面的代码无法从该windows服务器上运行。因此Azure Keyvault read java代码本应以相同的方式运行,但唉!我刚刚检查了Azure代码甚至没有到达该代理代码。在到达该代理代码之前,它因“未知主机”而失败从该windows服务器,但在我的本地计算机中,它正在使用代理和不使用代理。在Azure连接代码到达我正在添加代理详细信息的上下文创建部分之前,不确定如何向其提供代理信息。