简体   繁体   English

使用 Spring 将文件上传到 AWS S3

[英]Upload files to AWS S3 using Spring Boot works fine without Proxy but fails with Proxy

Uploading files to AWS S3 using spring boot works great when it executed without proxy and when I add proxy in the VM args it fails with following error,使用 spring 将文件上传到 AWS S3 启动在没有代理的情况下执行时效果很好,当我在 VM args 中添加代理时它失败并出现以下错误,

Internal Server Error (Service: Amazon S3; Status Code: 500; Error Code: 500 Internal Server Error; Request ID: null; S3 Extended Request ID: null; Proxy: 192.168.1.171)

Below are the vm arguments that I have provided,下面是我提供的vm arguments,

-Dhttp.proxyHost=192.168.1.171 -Dhttp.proxyPort=9999 -Dhttps.proxyHost=192.168.1.171 -Dhttps.proxyPort=9999

When I started to execute the package the AWS SDK auto initialize the proxy as it finds in the args list and it prints in the console当我开始执行 package 时,AWS SDK 自动初始化代理,因为它在 args 列表中找到它并在控制台中打印

com.amazonaws.http.AmazonHttpClient - Configuring Proxy. Proxy Host: 192.168.1.171 Proxy Port: 9999

I can not remove the proxy because I am using Oauth2 authentication in spring security.我无法删除代理,因为我在 spring 安全性中使用 Oauth2 身份验证。 Is there any way that I can disable auto initializing the proxy in AWS SDK?有什么方法可以禁用自动初始化 AWS SDK 中的代理?

In effect to communicate over a network "endpoints" are an address, but links require "connections" so it may be more of a connection/connected "host conflict" by configuration.实际上,通过网络进行通信的“端点”是一个地址,但链接需要“连接”,因此通过配置它可能更多是连接/连接的“主机冲突”。 For example i could have both a webserver and a DB that takes requests via http direct but it depends if they are configured for each other and/or to be connected through an irq to network to anything else.例如,我可以同时拥有一个网络服务器和一个通过 http 直接接收请求的数据库,但这取决于它们是否相互配置和/或通过 irq 连接到网络到其他任何东西。

I was able to resolve the issue after contacting AWS, I had to configure the method “setNoneProxyHosts (String nonProxyHosts)” method in the ClientConfiguration class.联系 AWS 后我能够解决问题,我必须在 ClientConfiguration class 中配置方法“setNoneProxyHosts (String nonProxyHosts)”方法。 This sets the optional hosts the client will access without going through the proxy.这将设置客户端无需通过代理即可访问的可选主机。 The parameter – “nonProxyHosts” takes the hosts the client will access without going through the proxy.参数 – “nonProxyHosts” 采用客户端无需通过代理即可访问的主机。 Please follow this link here for more information about the class and the method: https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/ClientConfiguration.html#setNonProxyHosts-java.lang.String-有关 class 和方法的更多信息,请点击此处的链接: https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/ClientConfiguration.html#setNonProxyHosts-java.lang.String-

Based on the instructions provided by AWS Support I had amended the config and added following;根据 AWS Support 提供的说明,我修改了配置并添加了以下内容;

 public ClientConfiguration clientConfiguration() { final ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setNonProxyHosts("*.s3.<ZONE>.amazonaws.com|*.s3-<ZONE>.amazonaws.com"); return clientConfiguration; }

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

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