Azure存储 - Java代码中的代理设置

发布于 2025-02-13 06:25:39 字数 1441 浏览 0 评论 0原文

在Java服务中,我正在尝试将文件上传到Azure存储目录中;因此,我已经编写了这样的代码:

import com.azure.core.util.*;
import com.azure.storage.file.share.*;
import com.azure.storage.file.share.models.*;

 //Create connexion string
String connectStr ="DefaultEndpointsProtocol=https;AccountName=" + accountName + ";AccountKey=" + accountKey + ";EndpointSuffix=" + endpoint;
            
//ShareDirectoryClient
            
ShareDirectoryClient dirClient = new     ShareFileClientBuilder().connectionString(connectStr).shareName(shareName).resourcePath(directoryName).configuration(proxyOptions).buildDirectoryClient();
            
// Create empty file
dirClient.createFile(fileName, body.length());

HTTPS请求必须通过代理服务器,因此,我会得到此错误:

“无法运行'sendfiledirectoryproxytest' 反应器。core.exceptions$ reactiveException:io.netty.channel.abstractChannel $ enrotatedConnectException:连接时机发布:没有其他信息:“

我无法设置/使用全局设置。 要在Java代码中设置代理,我尝试了几件事,例如使用配置类:

Configuration configuration = new Configuration();
configuration.put("java.net.useSystemProxies", "true");
configuration.put("https.proxyHost", "xxxxxxxxx");
configuration.put("https.proxyPort", "xxxx");
            
ShareDirectoryClient dirClient = new     ShareFileClientBuilder().connectionString(connectStr).shareName(shareName).resourcePath(directoryName).configuration(configuration).buildDirectoryClient();
            

但是它没有解决问题。 我确定这很简单,任何帮助都将不胜感激。 谢谢。查尔斯·德·圣安德烈。

In a java service, I'm trying to upload a file in an azure storage directory; therefore I've written a code like this :

import com.azure.core.util.*;
import com.azure.storage.file.share.*;
import com.azure.storage.file.share.models.*;

 //Create connexion string
String connectStr ="DefaultEndpointsProtocol=https;AccountName=" + accountName + ";AccountKey=" + accountKey + ";EndpointSuffix=" + endpoint;
            
//ShareDirectoryClient
            
ShareDirectoryClient dirClient = new     ShareFileClientBuilder().connectionString(connectStr).shareName(shareName).resourcePath(directoryName).configuration(proxyOptions).buildDirectoryClient();
            
// Create empty file
dirClient.createFile(fileName, body.length());

The HTTPS request must goes through a proxy server, so, I get this error :

"Could not run 'sendFileInDirectoryProxyTest'
reactor.core.Exceptions$ReactiveException: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: "

I can't set/use a global setting.
To set a proxy in the Java code, I've tried several things, like using the Configuration Class :

Configuration configuration = new Configuration();
configuration.put("java.net.useSystemProxies", "true");
configuration.put("https.proxyHost", "xxxxxxxxx");
configuration.put("https.proxyPort", "xxxx");
            
ShareDirectoryClient dirClient = new     ShareFileClientBuilder().connectionString(connectStr).shareName(shareName).resourcePath(directoryName).configuration(configuration).buildDirectoryClient();
            

But it did not solve the issue.
I'm sure it is pretty simple, any help would be appreciated.
Thanks. Charles de Saint Andre.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流殇 2025-02-20 06:25:39

您需要配置ProxyOptions并将其设置在HTTPClientBuilder上。我们所有的存储客户端构建器都有一个.httpclient()方法,该方法接受客户端,您可以使用NetTyAsyAsyncclientBuilder()构建具有所有默认设备 +代理选项的客户端,该选项具有.proxyoptions()方法。请尝试一下,让我知道您是否还有其他问题。
示例: azure-sdk-for-java/sdk/storage/azure-storage-blob在main ·azure/azure-sdk-for-java (github.com)

You need to configure ProxyOptions and set them on the httpClientBuilder. All our Storage client builders have a .httpClient() method that accepts a client, and you can build a client with all defaults + the proxy options using a NettyAsyncClientBuilder(), which has a .proxyOptions() method. Please give that a try and let me know if you have any more issues.
Sample : azure-sdk-for-java/sdk/storage/azure-storage-blob at main · Azure/azure-sdk-for-java (github.com)

吾家有女初长成 2025-02-20 06:25:39

ProxyOptions()不适用于HTTPS代理服务器。

ProxyOptions proxyOptions = ProxyOptions.fromConfiguration(Configuration.getGlobalConfiguration());

// Build the HttpClient with the proxy options if available
HttpClient httpClient = new NettyAsyncHttpClientBuilder().proxy(proxyOptions).build();
ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder().clientId(clientid).clientSecret(clientsecretvalue).tenantId(tenantid).proxyOptions(proxyOptions).build();
return clientSecretCredential;

ProxyOptions() is not work with HTTPS proxy server.

ProxyOptions proxyOptions = ProxyOptions.fromConfiguration(Configuration.getGlobalConfiguration());

// Build the HttpClient with the proxy options if available
HttpClient httpClient = new NettyAsyncHttpClientBuilder().proxy(proxyOptions).build();
ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder().clientId(clientid).clientSecret(clientsecretvalue).tenantId(tenantid).proxyOptions(proxyOptions).build();
return clientSecretCredential;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文