Example usage for com.amazonaws ClientConfiguration setProxyPort

List of usage examples for com.amazonaws ClientConfiguration setProxyPort

Introduction

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

Prototype

public void setProxyPort(int proxyPort) 

Source Link

Document

Sets the optional proxy port the client will connect through.

Usage

From source file:de.taimos.pipeline.aws.ProxyConfiguration.java

License:Apache License

private static void configureProxy(ClientConfiguration config, String env, int defaultPort) {
    Pattern pattern = Pattern.compile(PROXY_PATTERN);
    Matcher matcher = pattern.matcher(env);
    if (matcher.matches()) {
        if (matcher.group(3) != null) {
            config.setProxyUsername(matcher.group(3));
        }//  w  w  w . j  a va 2s .c  o m
        if (matcher.group(5) != null) {
            config.setProxyPassword(matcher.group(5));
        }
        config.setProxyHost(matcher.group(6));
        if (matcher.group(8) != null) {
            config.setProxyPort(Integer.parseInt(matcher.group(8)));
        } else {
            config.setProxyPort(defaultPort);
        }
    }
}

From source file:ec2watch.EC2Watch.java

License:Open Source License

private ClientConfiguration getClientConfig() {
    ClientConfiguration config = new ClientConfiguration();
    String proxyHost = System.getenv("PROXY_HOST");
    String proxyPort = System.getenv("PROXY_PORT");
    String proxyUser = System.getenv("PROXY_USER");
    String proxyPass = System.getenv("PROXY_PASSWORD");
    if (proxyHost != null && proxyPort != null) {
        config.setProxyHost(proxyHost);/*w w  w.  j  ava  2s.c om*/
        config.setProxyPort(Integer.valueOf(proxyPort));
        if (proxyUser != null) {
            config.setProxyUsername(proxyUser);
        }
        if (proxyPass != null) {
            config.setProxyPassword(proxyPass);
        }
    }
    return config;
}

From source file:hudson.plugins.ec2.EC2Cloud.java

License:Open Source License

/***
 * Connect to an EC2 instance.//from   ww w  .  j a v  a2s .  com
 * @return {@link AmazonEC2} client
 */
public synchronized static AmazonEC2 connect(AWSCredentialsProvider credentialsProvider, URL endpoint) {
    awsCredentialsProvider = credentialsProvider;
    ClientConfiguration config = new ClientConfiguration();
    ProxyConfiguration proxyConfig = Jenkins.getInstance().proxy;
    Proxy proxy = proxyConfig == null ? Proxy.NO_PROXY : proxyConfig.createProxy(endpoint.getHost());
    if (!proxy.equals(Proxy.NO_PROXY) && proxy.address() instanceof InetSocketAddress) {
        InetSocketAddress address = (InetSocketAddress) proxy.address();
        config.setProxyHost(address.getHostName());
        config.setProxyPort(address.getPort());
        if (null != proxyConfig.getUserName()) {
            config.setProxyUsername(proxyConfig.getUserName());
            config.setProxyPassword(proxyConfig.getPassword());
        }
    }
    AmazonEC2 client = new AmazonEC2Client(credentialsProvider.getCredentials(), config);
    client.setEndpoint(endpoint.toString());
    return client;
}

From source file:io.konig.camel.component.aws.s3.client.impl.S3ClientIAMOptimizedImpl.java

License:Apache License

/**
 * Getting the s3 aws client that is used.
 * @return Amazon S3 Client.//from   w  w  w . j  av a2s. c  o  m
 */
public AmazonS3 getS3Client() {
    AmazonS3 client = null;
    AmazonS3ClientBuilder clientBuilder = null;
    AmazonS3EncryptionClientBuilder encClientBuilder = null;
    ClientConfiguration clientConfiguration = null;
    if (configuration.hasProxyConfiguration()) {
        clientConfiguration = new ClientConfiguration();
        clientConfiguration.setProxyHost(configuration.getProxyHost());
        clientConfiguration.setProxyPort(configuration.getProxyPort());
        clientConfiguration.setMaxConnections(maxConnections);
    } else {
        clientConfiguration = new ClientConfiguration();
        clientConfiguration.setMaxConnections(maxConnections);
    }

    if (configuration.getAccessKey() != null || configuration.getSecretKey() != null) {
        LOG.trace("Do not pass in unnecessary static credentials when selecting the IAM credential option.");
    }

    if (!configuration.isUseEncryption()) {
        clientBuilder = AmazonS3ClientBuilder.standard()
                .withCredentials(new InstanceProfileCredentialsProvider(false));
    } else if (configuration.isUseEncryption()) {
        StaticEncryptionMaterialsProvider encryptionMaterialsProvider = new StaticEncryptionMaterialsProvider(
                configuration.getEncryptionMaterials());
        encClientBuilder = AmazonS3EncryptionClientBuilder.standard()
                .withClientConfiguration(clientConfiguration)
                .withEncryptionMaterials(encryptionMaterialsProvider)
                .withCredentials(new InstanceProfileCredentialsProvider(false));
    } else {
        clientBuilder = AmazonS3ClientBuilder.standard().withClientConfiguration(clientConfiguration)
                .withCredentials(new InstanceProfileCredentialsProvider(false));
    }

    if (!configuration.isUseEncryption()) {
        if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
            clientBuilder = clientBuilder.withRegion(Regions.valueOf(configuration.getRegion()));
        }
        clientBuilder = clientBuilder.withPathStyleAccessEnabled(configuration.isPathStyleAccess());
        client = clientBuilder.build();
    } else {
        if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
            encClientBuilder = encClientBuilder.withRegion(Regions.valueOf(configuration.getRegion()));
        }
        encClientBuilder = encClientBuilder.withPathStyleAccessEnabled(configuration.isPathStyleAccess());
        client = encClientBuilder.build();
    }

    return client;
}

From source file:io.konig.camel.component.aws.s3.client.impl.S3ClientStandardImpl.java

License:Apache License

/**
 * Getting the s3 aws client that is used.
 * @return Amazon S3 Client.//from www .  java  2s . c  o m
 */
public AmazonS3 getS3Client() {
    AmazonS3 client = null;
    AmazonS3ClientBuilder clientBuilder = null;
    AmazonS3EncryptionClientBuilder encClientBuilder = null;
    ClientConfiguration clientConfiguration = null;

    if (configuration.hasProxyConfiguration()) {
        clientConfiguration = new ClientConfiguration();
        clientConfiguration.setProxyHost(configuration.getProxyHost());
        clientConfiguration.setProxyPort(configuration.getProxyPort());
        clientConfiguration.setMaxConnections(maxConnections);
    } else {
        clientConfiguration = new ClientConfiguration();
        clientConfiguration.setMaxConnections(maxConnections);
    }

    if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) {
        AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(),
                configuration.getSecretKey());
        AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
        if (!configuration.isUseEncryption()) {
            clientBuilder = AmazonS3ClientBuilder.standard().withClientConfiguration(clientConfiguration)
                    .withCredentials(credentialsProvider);
        } else if (configuration.isUseEncryption()) {
            StaticEncryptionMaterialsProvider encryptionMaterialsProvider = new StaticEncryptionMaterialsProvider(
                    configuration.getEncryptionMaterials());
            encClientBuilder = AmazonS3EncryptionClientBuilder.standard()
                    .withClientConfiguration(clientConfiguration).withCredentials(credentialsProvider)
                    .withEncryptionMaterials(encryptionMaterialsProvider);
        } else {
            clientBuilder = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider);
        }

        if (!configuration.isUseEncryption()) {
            if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
                clientBuilder = clientBuilder.withRegion(Regions.valueOf(configuration.getRegion()));
            }
            clientBuilder = clientBuilder.withPathStyleAccessEnabled(configuration.isPathStyleAccess());
            client = clientBuilder.build();
        } else {
            if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
                encClientBuilder = encClientBuilder.withRegion(Regions.valueOf(configuration.getRegion()));
            }
            encClientBuilder = encClientBuilder.withPathStyleAccessEnabled(configuration.isPathStyleAccess());
            client = encClientBuilder.build();
        }
    } else {
        if (!configuration.isUseEncryption()) {
            clientBuilder = AmazonS3ClientBuilder.standard();
        } else if (configuration.isUseEncryption()) {
            StaticEncryptionMaterialsProvider encryptionMaterialsProvider = new StaticEncryptionMaterialsProvider(
                    configuration.getEncryptionMaterials());
            encClientBuilder = AmazonS3EncryptionClientBuilder.standard()
                    .withClientConfiguration(clientConfiguration)
                    .withEncryptionMaterials(encryptionMaterialsProvider);
        } else {
            clientBuilder = AmazonS3ClientBuilder.standard().withClientConfiguration(clientConfiguration);
        }

        if (!configuration.isUseEncryption()) {
            if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
                clientBuilder = clientBuilder.withRegion(Regions.valueOf(configuration.getRegion()));
            }
            clientBuilder = clientBuilder.withPathStyleAccessEnabled(configuration.isPathStyleAccess());
            client = clientBuilder.build();
        } else {
            if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
                encClientBuilder = encClientBuilder.withRegion(Regions.valueOf(configuration.getRegion()));
            }
            encClientBuilder = encClientBuilder.withPathStyleAccessEnabled(configuration.isPathStyleAccess());
            client = encClientBuilder.build();
        }
    }
    return client;
}

From source file:io.relution.jenkins.awssqs.factories.SQSFactoryImpl.java

License:Apache License

private ClientConfiguration getClientConfiguration(final io.relution.jenkins.awssqs.interfaces.SQSQueue queue) {
    final ClientConfiguration config = new ClientConfiguration();

    // Check to see if Jenkins is up yet
    Jenkins jenkins = Jenkins.getInstance();
    ProxyConfiguration proxyConfig = jenkins.proxy;
    Proxy proxy = proxyConfig == null ? Proxy.NO_PROXY : proxyConfig.createProxy(queue.getEndpoint());
    if (!proxy.equals(Proxy.NO_PROXY) && proxy.address() instanceof InetSocketAddress) {
        InetSocketAddress address = (InetSocketAddress) proxy.address();
        config.setProxyHost(address.getHostName());
        config.setProxyPort(address.getPort());
        config.setNonProxyHosts("169.254.169.254");
        if (null != proxyConfig.getUserName()) {
            config.setProxyUsername(proxyConfig.getUserName());
            config.setProxyPassword(proxyConfig.getPassword());
        }//  w  w w  .j ava  2s.  c o  m
        io.relution.jenkins.awssqs.logging.Log.info("Proxy settings for SQS: %s:%s", config.getProxyHost(),
                config.getProxyPort());
    }
    return config;
}

From source file:jp.classmethod.aws.gradle.AwsPluginExtension.java

License:Apache License

public <T extends AmazonWebServiceClient> T createClient(Class<T> serviceClass, String profileName,
        ClientConfiguration config) {/* ww w .ja va  2  s  . co  m*/
    AWSCredentialsProvider credentialsProvider = newCredentialsProvider(profileName);
    ClientConfiguration configToUse = config == null ? new ClientConfiguration() : config;
    if (this.proxyHost != null && this.proxyPort > 0) {
        configToUse.setProxyHost(this.proxyHost);
        configToUse.setProxyPort(this.proxyPort);
    }
    return createClient(serviceClass, credentialsProvider, configToUse);
}

From source file:jp.primecloud.auto.aws.amazon.AmazonAwsClientFactory.java

License:Open Source License

protected ClientConfiguration createConfiguration() {
    ClientConfiguration configuration = new ClientConfiguration();

    // Proxy/*from   w w w  .  j ava  2s  .c om*/
    if (proxyHost != null && proxyPort != null) {
        configuration.setProxyHost(proxyHost);
        configuration.setProxyPort(proxyPort);

        if (proxyUser != null && proxyPassword != null) {
            configuration.setProxyUsername(proxyUser);
            configuration.setProxyPassword(proxyPassword);
        }
    }

    // ???
    configuration.setMaxErrorRetry(0);

    return configuration;
}

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

License:Apache License

public void init() {
    ClientConfiguration awsConfig = new ClientConfiguration();
    if (System.getenv("https_proxy") != null) {
        URI proxy = URI.create(System.getenv("https_proxy"));
        awsConfig.setProxyHost(proxy.getHost());
        awsConfig.setProxyPort(proxy.getPort());
    }//w  w  w .j av a2  s  . c  o  m

    //awsConfig.setConnectionTimeout(2000);
    //awsConfig.setRequestTimeout(2000);
    //awsConfig.setSocketTimeout(2000);
    //awsConfig.setClientExecutionTimeout(2000);

    AWSCredentialsProvider credentials = new DefaultAWSCredentialsProviderChain();
    if (roleArn.isPresent()) {
        credentials = new STSAssumeRoleSessionCredentialsProvider(credentials, roleArn.get(), "lumbermills3",
                awsConfig);
    }
    s3Client = new AmazonS3Client(credentials, awsConfig);

}

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

License:Apache License

@Override
protected void connectToRepository(Repository repository, AuthenticationInfo authenticationInfo,
        ProxyInfoProvider proxyInfoProvider) throws AuthenticationException {
    if (this.amazonS3 == null) {
        AuthenticationInfoAWSCredentialsProviderChain credentialsProvider = new AuthenticationInfoAWSCredentialsProviderChain(
                authenticationInfo);/*from w ww  . j a va 2  s. c  o m*/
        ClientConfiguration clientConfiguration = S3Utils.getClientConfiguration(proxyInfoProvider);

        this.bucketName = S3Utils.getBucketName(repository);
        this.baseDirectory = S3Utils.getBaseDirectory(repository);

        if (proxyInfoProvider != null) {
            ProxyInfo pi = proxyInfoProvider.getProxyInfo("s3");
            if (pi != null) {
                clientConfiguration.setProxyHost(pi.getHost());
                clientConfiguration.setProxyPort(pi.getPort());
                clientConfiguration.setProxyUsername(pi.getUserName());
                clientConfiguration.setProxyPassword(pi.getPassword());
                clientConfiguration.setProxyDomain(pi.getNtlmDomain());
                clientConfiguration.setProxyWorkstation(pi.getNtlmHost());
            }
        }

        this.amazonS3 = new AmazonS3Client(credentialsProvider, clientConfiguration);
        Region region = Region.fromLocationConstraint(this.amazonS3.getBucketLocation(this.bucketName));
        this.amazonS3.setEndpoint(region.getEndpoint());
    }
}