Daniel Kaplan
Daniel Kaplan

Reputation: 67484

Why isn't the AmazonS3Client using the proxy I set?

I'm running this code:

    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();
        }
    }

This works fine without a proxy, but if I turn on the proxy, I don't think it is being used. Here's how I can tell: I hit a break point in the if statement and changed the proxyHost from "proxy.com" (a host that exists) to "proxy.com2" (a host that does not exist). Everything ran fine as if I didn't turn the proxy code on. I would expect this to error if it was using my host.

How do I get the S3 client to use the proxy settings I give it?

I'm using 1.8.4 of the amazon sdk.

Upvotes: 1

Views: 1068

Answers (1)

Daniel Kaplan
Daniel Kaplan

Reputation: 67484

I changed my setProxyDomain to setProxyHost, and it started erroring like I expected.

Upvotes: 1

Related Questions