Example usage for com.amazonaws.services.s3 AmazonS3Client setEndpoint

List of usage examples for com.amazonaws.services.s3 AmazonS3Client setEndpoint

Introduction

In this page you can find the example usage for com.amazonaws.services.s3 AmazonS3Client setEndpoint.

Prototype

@Override
@Deprecated
public synchronized void setEndpoint(String endpoint) 

Source Link

Usage

From source file:org.finra.dm.dao.impl.S3DaoImpl.java

License:Apache License

/**
 * Gets a new S3 client based on the specified parameters. The HTTP proxy information will be added if the host and port are specified in the parameters.
 *
 * @param params the parameters.//from   w w w .  j a v  a 2  s  .c  om
 *
 * @return the Amazon S3 client.
 */
private AmazonS3Client getAmazonS3(S3FileTransferRequestParamsDto params) {
    AmazonS3Client amazonS3Client;

    AWSCredentialsProvider awsCredentialsProvider = getAWSCredentialsProvider(params);
    if (StringUtils.isNotBlank(params.getHttpProxyHost())
            && StringUtils.isNotBlank(params.getHttpProxyPort().toString())) {
        // Create an S3 client with HTTP proxy information.
        amazonS3Client = new AmazonS3Client(awsCredentialsProvider, new ClientConfiguration()
                .withProxyHost(params.getHttpProxyHost()).withProxyPort(params.getHttpProxyPort()));
    } else {
        // Create an S3 client with no proxy information.
        amazonS3Client = new AmazonS3Client(awsCredentialsProvider);
    }

    // Set the optional endpoint if configured.
    if (StringUtils.isNotBlank(params.getS3Endpoint())) {
        LOGGER.info("Configured S3 Endpoint: " + params.getS3Endpoint());
        amazonS3Client.setEndpoint(params.getS3Endpoint());
    }

    // Return the newly created client.
    return amazonS3Client;
}

From source file:org.finra.herd.dao.impl.S3DaoImpl.java

License:Apache License

/**
 * Gets a new S3 client based on the specified parameters. The HTTP proxy information will be added if the host and port are specified in the parameters.
 *
 * @param params the parameters./*from  w ww. j  a v  a 2  s .  c  o m*/
 *
 * @return the Amazon S3 client.
 */
private AmazonS3Client getAmazonS3(S3FileTransferRequestParamsDto params) {
    AmazonS3Client amazonS3Client;

    ClientConfiguration clientConfiguration = new ClientConfiguration()
            .withRetryPolicy(retryPolicyFactory.getRetryPolicy());

    // Set the proxy configuration, if proxy is specified.
    if (StringUtils.isNotBlank(params.getHttpProxyHost()) && params.getHttpProxyPort() != null) {
        clientConfiguration.setProxyHost(params.getHttpProxyHost());
        clientConfiguration.setProxyPort(params.getHttpProxyPort());
    }

    // Sign all S3 API's with V4 signing.
    // AmazonS3Client.upgradeToSigV4 already has some scenarios where it will "upgrade" the signing approach to use V4 if not already present (e.g.
    // GetObjectRequest and KMS PutObjectRequest), but setting it here (especially when KMS is used) will ensure it isn't missed when required (e.g.
    // copying objects between KMS encrypted buckets). Otherwise, AWS will return a bad request error and retry which isn't desirable.
    clientConfiguration.setSignerOverride(SIGNER_OVERRIDE_V4);

    // Set the optional socket timeout, if configured.
    if (params.getSocketTimeout() != null) {
        clientConfiguration.setSocketTimeout(params.getSocketTimeout());
    }

    // Create an S3 client using passed in credentials and HTTP proxy information.
    if (StringUtils.isNotBlank(params.getAwsAccessKeyId()) && StringUtils.isNotBlank(params.getAwsSecretKey())
            && StringUtils.isNotBlank(params.getSessionToken())) {
        // Create an S3 client using basic session credentials.
        amazonS3Client = new AmazonS3Client(new BasicSessionCredentials(params.getAwsAccessKeyId(),
                params.getAwsSecretKey(), params.getSessionToken()), clientConfiguration);
    } else {
        // Create an S3 client using AWS credentials provider.
        amazonS3Client = new AmazonS3Client(getAWSCredentialsProvider(params), clientConfiguration);
    }

    // Set the optional endpoint, if specified.
    if (StringUtils.isNotBlank(params.getS3Endpoint())) {
        LOGGER.info("Configured S3 Endpoint: " + params.getS3Endpoint());
        amazonS3Client.setEndpoint(params.getS3Endpoint());
    }

    // Return the newly created client.
    return amazonS3Client;
}

From source file:org.gaul.yass.MainActivity.java

License:Open Source License

static AmazonS3Client getS3Client(YassPreferences preferences) {
    BasicAWSCredentials awsCreds = new BasicAWSCredentials(preferences.accessKey, preferences.secretKey);
    AmazonS3Client client = new AmazonS3Client(awsCreds, new ClientConfiguration());
    if (preferences.endpoint != null && !preferences.endpoint.isEmpty()) {
        client.setEndpoint(preferences.endpoint);
    }/*from   w  w w  . j  a  v a  2 s  . c om*/
    return client;
}

From source file:org.geowebcache.s3.S3BlobStoreInfo.java

License:Open Source License

/** @return {@link AmazonS3Client} constructed from this {@link S3BlobStoreInfo}. */
public AmazonS3Client buildClient() {
    ClientConfiguration clientConfig = new ClientConfiguration();
    if (null != useHTTPS) {
        clientConfig.setProtocol(useHTTPS ? Protocol.HTTPS : Protocol.HTTP);
    }//  ww  w. j a  v  a2  s .  c om
    if (null != maxConnections && maxConnections > 0) {
        clientConfig.setMaxConnections(maxConnections);
    }
    clientConfig.setProxyDomain(proxyDomain);
    clientConfig.setProxyWorkstation(proxyWorkstation);
    clientConfig.setProxyHost(proxyHost);
    if (null != proxyPort) {
        clientConfig.setProxyPort(proxyPort);
    }
    clientConfig.setProxyUsername(proxyUsername);
    clientConfig.setProxyPassword(proxyPassword);
    if (null != useGzip) {
        clientConfig.setUseGzip(useGzip);
    }
    log.debug("Initializing AWS S3 connection");
    AmazonS3Client client = new AmazonS3Client(getCredentialsProvider(), clientConfig);
    if (endpoint != null && !"".equals(endpoint)) {
        S3ClientOptions s3ClientOptions = new S3ClientOptions();
        s3ClientOptions.setPathStyleAccess(true);
        client.setS3ClientOptions(s3ClientOptions);
        client.setEndpoint(endpoint);
    }
    if (!client.doesBucketExist(bucket)) {
        client.createBucket(bucket);
    }
    return client;
}

From source file:org.gradle.internal.resource.transport.aws.s3.S3Client.java

License:Apache License

private AmazonS3Client createAmazonS3Client(AWSCredentials credentials) {
    AmazonS3Client amazonS3Client = new AmazonS3Client(credentials, createConnectionProperties());
    S3ClientOptions clientOptions = new S3ClientOptions();
    Optional<URI> endpoint = s3ConnectionProperties.getEndpoint();
    if (endpoint.isPresent()) {
        amazonS3Client.setEndpoint(endpoint.get().toString());
        clientOptions.withPathStyleAccess(true);
    }/*  w w  w  .j a v  a 2  s.  c  om*/
    amazonS3Client.setS3ClientOptions(clientOptions);
    return amazonS3Client;
}