java - 在 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 服务器中,它显示“未知主机”异常。
解决方案
我不确定以下是否会有所帮助,但您可以尝试一下。
您可以尝试找到代理的直接 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可能会起作用。
推荐阅读
- javascript - 如何根据另一个元素的宽度设置元素的宽度?
- reactjs - 使用 setInterval 反应倒计时
- asp.net-mvc - 如何在数据表行中插入按钮?
- python-3.x - 根据另一列中的分箱值在新列中创建标志
- http - Microsoft AD 应用程序验证失败:“microsoft-identity-association.json 的内容长度未设置或无效”
- python - Python:通过添加累积股息并取复合年增长率(CAGR)来计算总回报
- python - 四张表之间的SQL查询
- ios - 未定义符号:_OBJC_CLASS_$_FBSDKBasicUtility
- c# - 使用不同类型的节点从 JSON 创建类
- c# - 无法连接到 Linux 计算机上的 GRPC 服务