簡體   English   中英

為什么AmazonS3Client不使用我設置的代理?

[英]Why isn't the AmazonS3Client using the proxy I set?

我正在運行以下代碼:

    String urlString = rootUrl + "/" + path;

    AWSCredentials myCredentials = new BasicAWSCredentials(EnvironmentVariables.AWS_ACCESS_KEY, EnvironmentVariables.AWS_SECRET_KEY);
    ClientConfiguration clientConfiguration = new ClientConfiguration();
    if ("true".equalsIgnoreCase(EnvironmentVariables.proxySet)) {
        logger.info("EnvironmentVariables.proxyHost=" + EnvironmentVariables.proxyHost);
        clientConfiguration.setProxyDomain(EnvironmentVariables.proxyHost);
        logger.info("EnvironmentVariables.proxyPort=" + EnvironmentVariables.proxyPort);
        clientConfiguration.setProxyPort(Integer.valueOf(EnvironmentVariables.proxyPort));
    }

    TransferManager tx = null;
    try {

        tx = new TransferManager(new AmazonS3Client(myCredentials, clientConfiguration));
        ObjectMetadata objectMetadata = new ObjectMetadata();
        objectMetadata.setContentType(pathToContentType(path));
        Upload upload = tx.upload(bucketName, path, data, objectMetadata);



        upload.waitForUploadResult();

        return new URL(urlString);

    } catch (InterruptedException e) {
        throw new IllegalStateException("Interrupted when uploading the image to S3", e);
    } catch (MalformedURLException e) {
        throw new IllegalStateException("Invalid URL: " + urlString, e);
    } finally {
        if (tx != null) {
            tx.shutdownNow();
        }
    }

在沒有代理的情況下,這種方法可以正常工作,但是如果我打開代理,則認為它沒有被使用。 我可以這樣說:我在if語句中遇到一個斷點,並將proxyHost從“ proxy.com”(存在的主機)更改為“ proxy.com2”(不存在的主機)。 一切正常,好像我沒有打開代理代碼。 如果使用我的主機,我會期望這會出錯。

如何使S3客戶端使用我提供的代理設置?

我正在使用1.8.4的亞馬遜SDK。

我將setProxyDomain更改為setProxyHost ,它開始出現錯誤,與我預期的一樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM