Example usage for com.amazonaws ClientConfiguration withProxyHost

List of usage examples for com.amazonaws ClientConfiguration withProxyHost

Introduction

In this page you can find the example usage for com.amazonaws ClientConfiguration withProxyHost.

Prototype

public ClientConfiguration withProxyHost(String proxyHost) 

Source Link

Document

Sets the optional proxy host the client will connect through and returns the updated ClientConfiguration object.

Usage

From source file:com.ge.predix.solsvc.blobstore.bootstrap.BlobstoreClientImpl.java

License:Apache License

/**
 *  -/*from   w ww .ja  v  a  2 s.co m*/
 */
@PostConstruct
public void init() {

    ClientConfiguration config = new ClientConfiguration();
    config.setProtocol(Protocol.HTTPS);
    if (this.blobstoreConfig.getProxyHost() != null && !"".equals(this.blobstoreConfig.getProxyHost())) { //$NON-NLS-1$
        this.log.info("Connnecting with proxy"); //$NON-NLS-1$
        if (this.blobstoreConfig.getProxyHost() != null) {
            config.withProxyHost(this.blobstoreConfig.getProxyHost());
        }
        if (this.blobstoreConfig.getProxyPort() != null) {
            config.withProxyPort(Integer.parseInt(this.blobstoreConfig.getProxyPort()));
        }
    }
    BasicAWSCredentials creds = new BasicAWSCredentials(this.blobstoreConfig.getAccessKey(),
            this.blobstoreConfig.getAccessKey());
    this.s3Client = new AmazonS3Client(creds, config);
    this.s3Client.setEndpoint(this.blobstoreConfig.getUrl());

}

From source file:com.noctarius.hazelcast.aws.HazelcastAwsDiscoveryStrategy.java

License:Open Source License

private void configureProxy(ClientConfiguration configuration) {
    String proxyHost = getOrNull(AwsProperties.PROXY_HOST);
    if (proxyHost == null) {
        return;/*ww w . j  a va 2 s .c om*/
    }

    int proxyPort = getOrDefault(AwsProperties.PROXY_PORT, 80);
    String proxyUsername = getOrNull(AwsProperties.PROXY_USERNAME);
    String proxyPassword = getOrNull(AwsProperties.PROXY_PASSWORD);

    configuration.withProxyHost(proxyHost).setProxyPort(proxyPort);
    configuration.withProxyUsername(proxyUsername);
    configuration.withProxyPassword(proxyPassword);
}

From source file:com.tango.BucketSyncer.StorageClients.S3Client.java

License:Apache License

public void createClient(MirrorOptions options) {
    ClientConfiguration clientConfiguration = new ClientConfiguration().withProtocol(Protocol.HTTP)
            .withMaxConnections(options.getMaxConnections());
    if (options.getHasProxy()) {
        clientConfiguration = clientConfiguration.withProxyHost(options.getProxyHost())
                .withProxyPort(options.getProxyPort());
    }// ww w . j  a  v a 2 s  . c  o m
    this.s3Client = new AmazonS3Client(options, clientConfiguration);
    if (options.hasEndpoint()) {
        s3Client.setEndpoint(options.getEndpoint());
    }
}

From source file:fi.yle.tools.aws.maven.S3Utils.java

License:Apache License

static ClientConfiguration getClientConfiguration(ProxyInfoProvider proxyInfoProvider) {
    ClientConfiguration clientConfiguration = new ClientConfiguration();

    if (proxyInfoProvider != null) {
        ProxyInfo proxyInfo = proxyInfoProvider.getProxyInfo("s3");
        if (proxyInfo != null) {
            clientConfiguration.withProxyHost(proxyInfo.getHost()).withProxyPort(proxyInfo.getPort());
        }/*w  w  w  .  j a v  a 2 s. com*/
    }

    return clientConfiguration;
}

From source file:lumbermill.internal.aws.KinesisClientFactory.java

License:Apache License

private AmazonKinesisAsync getAsyncClient(MapWrap configuration) {

    Optional<ClientConfiguration> kinesisConfig = configuration.exists("kinesis_config")
            ? Optional.of(configuration.getObject("kinesis_config"))
            : Optional.empty();/*from w  w w.  j a v a  2 s .  c  o  m*/
    if (kinesisConfig.isPresent()) {
        return createClient(kinesisConfig.get(), configuration);

    }

    ClientConfiguration clientConfiguration = new ClientConfiguration()
            .withMaxConnections(configuration.asInt("max_connections", 10))
            .withRequestTimeout(configuration.asInt("request_timeout", 60000));
    if (System.getenv("https_proxy") != null) {
        URI proxy = URI.create(System.getenv("https_proxy"));
        LOGGER.info("Using proxy {}", proxy);
        clientConfiguration.withProxyHost(proxy.getHost()).withProxyPort(proxy.getPort());
    }
    return createClient(clientConfiguration, configuration);
}

From source file:org.adroitlogic.build.aws.maven.S3Utils.java

License:Apache License

static ClientConfiguration getClientConfiguration(ProxyInfoProvider proxyInfoProvider) {
    ClientConfiguration clientConfiguration = new ClientConfiguration();

    if (proxyInfoProvider != null) {
        ProxyInfo proxyInfo = proxyInfoProvider.getProxyInfo("s3");

        if (proxyInfo != null) {
            //System.out.println("Proxy Info : NTLM host: " + proxyInfo.getNtlmHost() + " domain: " + proxyInfo.getNtlmDomain() + " username: " + proxyInfo.getUserName() + " password: " + proxyInfo.getPassword() + " host: " + proxyInfo.getHost() + " port: " + proxyInfo.getPort());
            clientConfiguration.withProxyHost(proxyInfo.getHost()).withProxyPort(proxyInfo.getPort());
            if (proxyInfo.getUserName() != null) {
                clientConfiguration.setProxyUsername(proxyInfo.getUserName());
                clientConfiguration.setProxyPassword(proxyInfo.getPassword());
            }/*  w ww  .j  a va 2s.c o  m*/
            if (proxyInfo.getNtlmDomain() != null) {
                clientConfiguration.setProxyDomain(proxyInfo.getNtlmDomain());
            }
            if (proxyInfo.getNtlmHost() != null) {
                clientConfiguration.setProxyWorkstation(proxyInfo.getNtlmHost());
            }
        }
    }
    //clientConfiguration.setProtocol(com.amazonaws.Protocol.HTTP);

    return clientConfiguration;
}

From source file:org.apache.nifi.processors.aws.credentials.provider.factory.strategies.AssumeRoleCredentialsStrategy.java

License:Apache License

@Override
public AWSCredentialsProvider getDerivedCredentialsProvider(Map<PropertyDescriptor, String> properties,
        AWSCredentialsProvider primaryCredentialsProvider) {
    final String assumeRoleArn = properties.get(ASSUME_ROLE_ARN);
    final String assumeRoleName = properties.get(ASSUME_ROLE_NAME);
    String rawMaxSessionTime = properties.get(MAX_SESSION_TIME);
    rawMaxSessionTime = (rawMaxSessionTime != null) ? rawMaxSessionTime : MAX_SESSION_TIME.getDefaultValue();
    final Integer maxSessionTime = Integer.parseInt(rawMaxSessionTime.trim());
    final String assumeRoleExternalId = properties.get(ASSUME_ROLE_EXTERNAL_ID);
    STSAssumeRoleSessionCredentialsProvider.Builder builder;
    ClientConfiguration config = new ClientConfiguration();

    // If proxy variables are set, then create Client Configuration with those values
    if (proxyVariablesValidForAssumeRole(properties)) {
        final String assumeRoleProxyHost = properties.get(ASSUME_ROLE_PROXY_HOST);
        final Integer assumeRoleProxyPort = Integer.parseInt(properties.get(ASSUME_ROLE_PROXY_PORT));
        config.withProxyHost(assumeRoleProxyHost);
        config.withProxyPort(assumeRoleProxyPort);
    }/*from  w w w  .  j  a v  a  2 s  . c o m*/

    AWSSecurityTokenService securityTokenService = new AWSSecurityTokenServiceClient(primaryCredentialsProvider,
            config);
    builder = new STSAssumeRoleSessionCredentialsProvider.Builder(assumeRoleArn, assumeRoleName)
            .withStsClient(securityTokenService).withRoleSessionDurationSeconds(maxSessionTime);

    if (assumeRoleExternalId != null && !assumeRoleExternalId.isEmpty()) {
        builder = builder.withExternalId(assumeRoleExternalId);
    }

    final AWSCredentialsProvider credsProvider = builder.build();

    return credsProvider;
}

From source file:org.apache.storm.s3.output.UploaderFactory.java

License:Apache License

public static Uploader buildUploader(Map conf) {
    Protocol protocol = Protocol.HTTPS;/*from   ww  w . jav a 2  s  .c o  m*/
    String proxy = null;
    int proxyPort = 0;
    if (conf.containsKey(S3_PROTOCOL)) {
        protocol = Protocol.valueOf((String) conf.get(S3_PROTOCOL));
    }
    if (conf.containsKey(S3_PROXY)) {
        proxy = (String) conf.get(S3_PROXY);
    }
    if (conf.containsKey(S3_PROXY_PORT)) {
        proxyPort = ((Long) conf.get(S3_PROXY_PORT)).intValue();
    }
    AWSCredentialsProvider provider = new DefaultAWSCredentialsProviderChain();
    AWSCredentials credentials = provider.getCredentials();
    ClientConfiguration config = new ClientConfiguration().withProtocol(protocol);
    if (proxy != null) {
        config.withProxyHost(proxy);
    }
    if (proxyPort != 0) {
        config.withProxyPort(proxyPort);
    }
    AmazonS3 client = new AmazonS3Client(credentials, config);
    if (conf.containsKey(S3_ENDPOINT)) {
        client.setEndpoint((String) conf.get(S3_ENDPOINT));
    }
    return getUploader(conf, client);
}

From source file:org.elasticsearch.cloud.aws.AwsEc2Service.java

License:Apache License

public synchronized AmazonEC2 client() {
    if (client != null) {
        return client;
    }/*  w ww.  jav a2 s  . c  om*/

    ClientConfiguration clientConfiguration = new ClientConfiguration();
    String protocol = componentSettings.get("protocol", "http").toLowerCase();
    if ("http".equals(protocol)) {
        clientConfiguration.setProtocol(Protocol.HTTP);
    } else if ("https".equals(protocol)) {
        clientConfiguration.setProtocol(Protocol.HTTPS);
    } else {
        throw new ElasticsearchIllegalArgumentException(
                "No protocol supported [" + protocol + "], can either be [http] or [https]");
    }
    String account = componentSettings.get("access_key", settings.get("cloud.account"));
    String key = componentSettings.get("secret_key", settings.get("cloud.key"));

    String proxyHost = componentSettings.get("proxy_host");
    if (proxyHost != null) {
        String portString = componentSettings.get("proxy_port", "80");
        Integer proxyPort;
        try {
            proxyPort = Integer.parseInt(portString, 10);
        } catch (NumberFormatException ex) {
            throw new ElasticsearchIllegalArgumentException(
                    "The configured proxy port value [" + portString + "] is invalid", ex);
        }
        clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort);
    }

    AWSCredentialsProvider credentials;

    if (account == null && key == null) {
        credentials = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(),
                new SystemPropertiesCredentialsProvider(), new InstanceProfileCredentialsProvider());
    } else {
        credentials = new AWSCredentialsProviderChain(
                new StaticCredentialsProvider(new BasicAWSCredentials(account, key)));
    }

    this.client = new AmazonEC2Client(credentials, clientConfiguration);

    if (componentSettings.get("ec2.endpoint") != null) {
        String endpoint = componentSettings.get("ec2.endpoint");
        logger.debug("using explicit ec2 endpoint [{}]", endpoint);
        client.setEndpoint(endpoint);
    } else if (componentSettings.get("region") != null) {
        String region = componentSettings.get("region").toLowerCase();
        String endpoint;
        if (region.equals("us-east-1") || region.equals("us-east")) {
            endpoint = "ec2.us-east-1.amazonaws.com";
        } else if (region.equals("us-west") || region.equals("us-west-1")) {
            endpoint = "ec2.us-west-1.amazonaws.com";
        } else if (region.equals("us-west-2")) {
            endpoint = "ec2.us-west-2.amazonaws.com";
        } else if (region.equals("ap-southeast") || region.equals("ap-southeast-1")) {
            endpoint = "ec2.ap-southeast-1.amazonaws.com";
        } else if (region.equals("ap-southeast-2")) {
            endpoint = "ec2.ap-southeast-2.amazonaws.com";
        } else if (region.equals("ap-northeast") || region.equals("ap-northeast-1")) {
            endpoint = "ec2.ap-northeast-1.amazonaws.com";
        } else if (region.equals("eu-west") || region.equals("eu-west-1")) {
            endpoint = "ec2.eu-west-1.amazonaws.com";
        } else if (region.equals("sa-east") || region.equals("sa-east-1")) {
            endpoint = "ec2.sa-east-1.amazonaws.com";
        } else {
            throw new ElasticsearchIllegalArgumentException(
                    "No automatic endpoint could be derived from region [" + region + "]");
        }
        if (endpoint != null) {
            logger.debug("using ec2 region [{}], with endpoint [{}]", region, endpoint);
            client.setEndpoint(endpoint);
        }
    }

    return this.client;

}

From source file:org.elasticsearch.cloud.aws.AwsEc2ServiceImpl.java

License:Apache License

protected static ClientConfiguration buildConfiguration(Logger logger, Settings settings) {
    ClientConfiguration clientConfiguration = new ClientConfiguration();
    // the response metadata cache is only there for diagnostics purposes,
    // but can force objects from every response to the old generation.
    clientConfiguration.setResponseMetadataCacheSize(0);
    clientConfiguration.setProtocol(CLOUD_EC2.PROTOCOL_SETTING.get(settings));

    if (PROXY_HOST_SETTING.exists(settings) || CLOUD_EC2.PROXY_HOST_SETTING.exists(settings)) {
        String proxyHost = CLOUD_EC2.PROXY_HOST_SETTING.get(settings);
        Integer proxyPort = CLOUD_EC2.PROXY_PORT_SETTING.get(settings);
        String proxyUsername = CLOUD_EC2.PROXY_USERNAME_SETTING.get(settings);
        String proxyPassword = CLOUD_EC2.PROXY_PASSWORD_SETTING.get(settings);

        clientConfiguration.withProxyHost(proxyHost).withProxyPort(proxyPort).withProxyUsername(proxyUsername)
                .withProxyPassword(proxyPassword);
    }//  w  w  w.j  av a 2 s .  com

    // #155: we might have 3rd party users using older EC2 API version
    String awsSigner = CLOUD_EC2.SIGNER_SETTING.get(settings);
    if (Strings.hasText(awsSigner)) {
        logger.debug("using AWS API signer [{}]", awsSigner);
        AwsSigner.configureSigner(awsSigner, clientConfiguration);
    }

    // Increase the number of retries in case of 5xx API responses
    final Random rand = Randomness.get();
    RetryPolicy retryPolicy = new RetryPolicy(RetryPolicy.RetryCondition.NO_RETRY_CONDITION,
            new RetryPolicy.BackoffStrategy() {
                @Override
                public long delayBeforeNextRetry(AmazonWebServiceRequest originalRequest,
                        AmazonClientException exception, int retriesAttempted) {
                    // with 10 retries the max delay time is 320s/320000ms (10 * 2^5 * 1 * 1000)
                    logger.warn("EC2 API request failed, retry again. Reason was:", exception);
                    return 1000L
                            * (long) (10d * Math.pow(2, retriesAttempted / 2.0d) * (1.0d + rand.nextDouble()));
                }
            }, 10, false);
    clientConfiguration.setRetryPolicy(retryPolicy);

    return clientConfiguration;
}