简体   繁体   English

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

[英]Azure Storage - Proxy Setting in Java Code

In a java service, I'm trying to upload a file in an azure storage directory;在 java 服务中,我正在尝试在 azure 存储目录中上传文件; 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: HTTPS 请求必须通过代理服务器,所以,我收到此错误:

"Could not run 'sendFileInDirectoryProxyTest' reactor.core.Exceptions$ReactiveException: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: " “无法运行‘sendFileInDirectoryProxyTest’reactor.core.Exceptions$ReactiveException:io.netty.channel.AbstractChannel$AnnotatedConnectException:连接超时:没有更多信息:”

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:要在 Java 代码中设置代理,我尝试了几件事,例如使用配置 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.查尔斯·德·圣安德烈。

You need to configure ProxyOptions and set them on the httpClientBuilder.您需要配置 ProxyOptions 并在 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.我们所有的存储客户端构建器都有一个接受客户端的 .httpClient() 方法,您可以使用 NettyAsyncClientBuilder() 构建一个具有所有默认值 + 代理选项的客户端,它有一个 .proxyOptions() 方法。 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)示例: azure-sdk-for-java/sdk/storage/azure-storage-blob at main · Azure/azure-sdk-for-java (github.com)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM