I'm using the AWS SDK for Android to download objects from S3 to my Android tablet. In an attempt to route traffic through a proxy (right now I'm using Charles Proxy on my local network as a test bed) to throttle the download speed of the S3 downloads, I'm using ClientConfiguration.setProxyHost and setProxyPort but the S3 TransferUtility appears to be ignoring the setting and going directly to AWS S3 not the proxy.
我正在使用AWS SDK for Android将对象从S3下载到我的Android平板电脑。试图通过代理路由流量(现在我在我的本地网络上使用Charles Proxy作为测试台)来限制S3下载的下载速度,我使用ClientConfiguration.setProxyHost和setProxyPort但是S3 TransferUtility似乎忽略了设置并直接转到AWS S3而不是代理。
The code without the proxy set works fine. Objects are downloaded successfully. The code with the proxy set behaves exactly the same, and the proxy doesn't show any connection from the tablet.
没有代理集的代码工作正常。对象下载成功。代理集的代码行为完全相同,代理不显示平板电脑的任何连接。
I have proven to myself that the proxy works by setting the proxy host and port in the Android tablet Wifi settings (setting proxy manually) and the proxy shows the AWS S3 connections traveling through the proxy successfully.
我已经证明代理的工作原理是在Android平板电脑Wifi设置中设置代理主机和端口(手动设置代理),代理显示成功通过代理的AWS S3连接。
At first, I thought the AmazonS3Client was ignoring my ClientConfiguration entirely but I've proven that when I set the ClientConfiguration.setProtocol from HTTPS to HTTP the AWS TransferUtility changes from http to https as the AWS endpoint.
起初,我认为AmazonS3Client完全忽略了我的ClientConfiguration,但我已经证明,当我将ClientConfiguration.setProtocol从HTTPS设置为HTTP时,AWS TransferUtility会从http更改为https作为AWS端点。
The code looks like every other sample code for setting the proxy that I can find using ClientConfiguration and TransferUtility.
代码看起来像每个其他示例代码,用于设置我可以使用ClientConfiguration和TransferUtility找到的代理。
ClientConfiguration getClientConfiguration() {
return new ClientConfiguration()
.withMaxConnections(2)
.withProxyHost("192.168.1.137")
.withProxyPort(8888)
.withConnectionTimeout(30 * 1000) // Wait 30 seconds to make a connection
.withSocketTimeout(0); // Keep open connections open indefinitely (we have very large downloads)
}
public S3Controller(Context context) {
java.util.logging.Logger.getLogger("com.amazonaws").setLevel(java.util.logging.Level.FINEST);
applicationContext = context.getApplicationContext();
clientConfig = getClientConfiguration();
s3Client = new AmazonS3Client(getCredentials(), clientConfig);
transferUtility = new TransferUtility(s3Client, applicationContext);
pendingTransfers = new PendingTransferQueue();
}
// ... later
// ......以后
TransferObserver observer = transferUtility.download(BuildConfig.S3_BUCKET, key, file);
As you can see I also tried setting the logging level of the amazonaws to FINEST in order to get some visibility on where the proxy is failing with no additional logging showing up.
正如您所看到的,我还尝试将amazonaws的日志记录级别设置为FINEST,以便在代理失败的位置获得一些可见性,而不会显示其他日志记录。
Any suggestion on why AWS SDK is ignoring my proxy or how I can set logging to find out more details on where it is failing?
有关为什么AWS SDK忽略我的代理或者如何设置日志记录以找出有关失败的更多详细信息的任何建议?
Thanks in advance.
提前致谢。
1 个解决方案
#1
1
So what I've found is that I can instantiate the class com.amazonaws.http.ApacheHttpClient and it will use the package protected HttpClientFactory that configures the proxy set in the clientConfig.
所以我发现我可以实例化com.amazonaws.http.ApacheHttpClient类,它将使用受保护的HttpClientFactory包来配置clientConfig中的代理集。
The creation of the AmazonS3Client uses a different constructor to pass in the HttpClient that has the proxy configured as below:
AmazonS3Client的创建使用不同的构造函数来传递具有如下配置的代理的HttpClient:
HttpClient httpClient = new ApacheHttpClient(clientConfig);
s3Client = new AmazonS3Client(getCredentialsProvider(), clientConfig, httpClient);
#1
1
So what I've found is that I can instantiate the class com.amazonaws.http.ApacheHttpClient and it will use the package protected HttpClientFactory that configures the proxy set in the clientConfig.
所以我发现我可以实例化com.amazonaws.http.ApacheHttpClient类,它将使用受保护的HttpClientFactory包来配置clientConfig中的代理集。
The creation of the AmazonS3Client uses a different constructor to pass in the HttpClient that has the proxy configured as below:
AmazonS3Client的创建使用不同的构造函数来传递具有如下配置的代理的HttpClient:
HttpClient httpClient = new ApacheHttpClient(clientConfig);
s3Client = new AmazonS3Client(getCredentialsProvider(), clientConfig, httpClient);