Java Code Examples for com.amazonaws.ClientConfiguration

The following examples show how to use com.amazonaws.ClientConfiguration. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@SuppressWarnings("deprecation")
@Test
public void modifyTest() throws Exception {
    // Set up the buffer and do sanity checks
    buffer.clear();
    buffer.consumeRecord(ITEM1_MODIFY, ITEM1_MODIFY.getDynamodb().getSizeBytes().intValue(), ITEM1_MODIFY.getDynamodb().getSequenceNumber());
    assertEquals(ITEM1_MODIFY.getDynamodb().getSequenceNumber(), buffer.getFirstSequenceNumber());
    assertEquals(ITEM1_MODIFY.getDynamodb().getSequenceNumber(), buffer.getLastSequenceNumber());
    List<Record> buffered = buffer.getRecords();
    assertEquals(1, buffered.size());
    assertTrue(buffered.contains(ITEM1_MODIFY));

    // Emit record
    resetAll(DYNAMODB);
    DYNAMODB.putItemAsync(EasyMock.anyObject(PutItemRequest.class), anyObject(AsyncHandler.class));
    expectLastCall().andAnswer(SUCCESS_ANSWER);
    expectNew(AmazonDynamoDBAsyncClient.class, new Class<?>[] {AWSCredentialsProvider.class, ClientConfiguration.class, ExecutorService.class}, anyObject(AWSCredentialsProvider.class), anyObject(ClientConfiguration.class), anyObject(ExecutorService.class)).andReturn(DYNAMODB);
    DYNAMODB.setEndpoint(EasyMock.anyString());
    EasyMock.expectLastCall().anyTimes();
    replayAll(DYNAMODB);
    IEmitter<Record> instance = createEmitterInstance();
    assertTrue(instance.emit(new UnmodifiableBuffer<Record>(buffer)).isEmpty());
    verifyAll();
}
 
Example 2
private static ClientConfiguration createGatewayTimeoutRetryableConfiguration() {
  ClientConfiguration retryableConfig = new ClientConfiguration();
  RetryPolicy.RetryCondition retryCondition = new PredefinedRetryPolicies.SDKDefaultRetryCondition() {
    @Override
    public boolean shouldRetry(AmazonWebServiceRequest originalRequest, AmazonClientException exception,
                               int retriesAttempted) {
      if (super.shouldRetry(originalRequest, exception, retriesAttempted)) {
        return true;
      }
      if (exception != null && exception instanceof AmazonServiceException) {
        AmazonServiceException ase = (AmazonServiceException) exception;
        if (ase.getStatusCode() == SC_GATEWAY_TIMEOUT) {
          return true;
        }
      }
      return false;
    }
  };
  RetryPolicy retryPolicy = new RetryPolicy(retryCondition, PredefinedRetryPolicies.DEFAULT_BACKOFF_STRATEGY,
                                                   PredefinedRetryPolicies.DEFAULT_MAX_ERROR_RETRY, true);
  retryableConfig.setRetryPolicy(retryPolicy);
  return retryableConfig;
}
 
Example 3
Source Project: zipkin-aws   Source File: AwsClientTracing.java    License: Apache License 2.0 6 votes vote down vote up
public <Builder extends AwsClientBuilder, Client> Client build(
    AwsClientBuilder<Builder, Client> builder
) {
  if (builder == null) throw new NullPointerException("builder == null");
  if (builder instanceof AwsAsyncClientBuilder) {
    ExecutorFactory executorFactory = ((AwsAsyncClientBuilder) builder).getExecutorFactory();
    if (executorFactory == null) {
      ClientConfiguration clientConfiguration = builder.getClientConfiguration();
      if (clientConfiguration == null) {
        clientConfiguration = defaultClientConfigurationFactory.getConfig();
      }
      ((AwsAsyncClientBuilder) builder).setExecutorFactory(
          new TracingExecutorFactory(currentTraceContext, clientConfiguration)
      );
    } else {
      ((AwsAsyncClientBuilder) builder).setExecutorFactory(
          new TracingExecutorFactoryWrapper(currentTraceContext, executorFactory)
      );
    }
  }
  builder.withRequestHandlers(new TracingRequestHandler(httpTracing));
  return builder.build();
}
 
Example 4
/**
 * {@inheritDoc}
 */
@Override
public AmazonElasticLoadBalancing createElbClient(String awsAccessId, String awsSecretKey) {
    AWSCredentials credentials = new BasicAWSCredentials(awsAccessId, awsSecretKey);
    ClientConfiguration configuration = createConfiguration();

    AmazonElasticLoadBalancing client = new AmazonElasticLoadBalancingClient(credentials, configuration);

    if (host != null) {
        client.setEndpoint(AmazonElasticLoadBalancing.ENDPOINT_PREFIX + "." + host);
    }

    client = new ExceptionHandleAwsClientWrapper().wrap(client);

    return client;
}
 
Example 5
Source Project: samza   Source File: KinesisConfig.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get KCL config for a given system stream.
 * @param system name of the system
 * @param stream name of the stream
 * @param appName name of the application
 * @return Stream scoped KCL configs required to build
 *         {@link KinesisClientLibConfiguration}
 */
public KinesisClientLibConfiguration getKinesisClientLibConfig(String system, String stream, String appName) {
  ClientConfiguration clientConfig = getAWSClientConfig(system);
  String workerId = appName + "-" + UUID.randomUUID();
  InitialPositionInStream startPos = InitialPositionInStream.LATEST;
  AWSCredentialsProvider provider = credentialsProviderForStream(system, stream);
  KinesisClientLibConfiguration kinesisClientLibConfiguration =
      new KinesisClientLibConfiguration(appName, stream, provider, workerId)
          .withRegionName(getRegion(system, stream).getName())
          .withKinesisClientConfig(clientConfig)
          .withCloudWatchClientConfig(clientConfig)
          .withDynamoDBClientConfig(clientConfig)
          .withInitialPositionInStream(startPos)
          .withCallProcessRecordsEvenForEmptyRecordList(true); // For health monitoring metrics.
  // First, get system scoped configs for KCL and override with configs set at stream scope.
  setKinesisClientLibConfigs(
      subset(String.format(CONFIG_SYSTEM_KINESIS_CLIENT_LIB_CONFIG, system)), kinesisClientLibConfiguration);
  setKinesisClientLibConfigs(subset(String.format(CONFIG_STREAM_KINESIS_CLIENT_LIB_CONFIG, system, stream)),
      kinesisClientLibConfiguration);
  return kinesisClientLibConfiguration;
}
 
Example 6
Source Project: datacollector   Source File: TestAWSUtil.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetClientConfigurationNotUsing() {
  ProxyConfig proxyConfig = new ProxyConfig();
  proxyConfig.useProxy = false; // other values will be ignored because this is false
  proxyConfig.proxyHost = "host";
  proxyConfig.proxyPort = 1234;
  proxyConfig.proxyUser = () -> "user";
  proxyConfig.proxyPassword = () -> "password";
  proxyConfig.proxyDomain = "domain";
  proxyConfig.proxyWorkstation = "workstation";

  ClientConfiguration clientConfig = AWSUtil.getClientConfiguration(proxyConfig);
  Assert.assertNull(clientConfig.getProxyHost());
  Assert.assertEquals(-1, clientConfig.getProxyPort());
  Assert.assertNull(clientConfig.getProxyUsername());
  Assert.assertNull(clientConfig.getProxyPassword());
  Assert.assertNull(clientConfig.getProxyDomain());
  Assert.assertNull(clientConfig.getProxyWorkstation());
}
 
Example 7
Source Project: kafka-connect-lambda   Source File: InvocationClientTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBuilderReflexiveProperties() {
    ClientConfiguration clientConfiguration = new ClientConfiguration();
    AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain();

    InvocationClient.Builder builder = new InvocationClient.Builder()
        .setFunctionArn("test-function-arn")
        .setRegion("us-test-region")
        .setInvocationMode(InvocationMode.ASYNC)
        .setFailureMode(InvocationFailure.DROP)
        .setInvocationTimeout(Duration.ofSeconds(123))
        .withClientConfiguration(clientConfiguration)
        .withCredentialsProvider(credentialsProvider);

    assertEquals("test-function-arn", builder.getFunctionArn());
    assertEquals("us-test-region", builder.getRegion());
    assertEquals(InvocationMode.ASYNC, builder.getInvocationMode());
    assertEquals(InvocationFailure.DROP, builder.getFailureMode());
    assertEquals(Duration.ofSeconds(123), builder.getInvocationTimeout());
    assertSame(clientConfiguration, builder.getClientConfiguration());
    assertSame(credentialsProvider, builder.getCredentialsProvider());
}
 
Example 8
Source Project: herd   Source File: ServiceSpringModuleConfig.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets a JMS connection factory.
 *
 * @return the JMS connection factory.
 */
@Bean
public ConnectionFactory jmsConnectionFactory()
{
    AwsParamsDto awsParamsDto = awsHelper.getAwsParamsDto();

    ClientConfiguration clientConfiguration = new ClientConfiguration();

    // Only set the proxy hostname and/or port if they're configured.
    if (StringUtils.isNotBlank(awsParamsDto.getHttpProxyHost()))
    {
        clientConfiguration.setProxyHost(awsParamsDto.getHttpProxyHost());
    }
    if (awsParamsDto.getHttpProxyPort() != null)
    {
        clientConfiguration.setProxyPort(awsParamsDto.getHttpProxyPort());
    }

    return SQSConnectionFactory.builder().withClientConfiguration(clientConfiguration).build();
}
 
Example 9
Source Project: flink   Source File: AWSUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates an Amazon Kinesis Client.
 * @param configProps configuration properties containing the access key, secret key, and region
 * @param awsClientConfig preconfigured AWS SDK client configuration
 * @return a new Amazon Kinesis Client
 */
public static AmazonKinesis createKinesisClient(Properties configProps, ClientConfiguration awsClientConfig) {
	// set a Flink-specific user agent
	awsClientConfig.setUserAgentPrefix(String.format(USER_AGENT_FORMAT,
			EnvironmentInformation.getVersion(),
			EnvironmentInformation.getRevisionInformation().commitId));

	// utilize automatic refreshment of credentials by directly passing the AWSCredentialsProvider
	AmazonKinesisClientBuilder builder = AmazonKinesisClientBuilder.standard()
			.withCredentials(AWSUtil.getCredentialsProvider(configProps))
			.withClientConfiguration(awsClientConfig);

	if (configProps.containsKey(AWSConfigConstants.AWS_ENDPOINT)) {
		// Set signingRegion as null, to facilitate mocking Kinesis for local tests
		builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(
												configProps.getProperty(AWSConfigConstants.AWS_ENDPOINT),
												null));
	} else {
		builder.withRegion(Regions.fromName(configProps.getProperty(AWSConfigConstants.AWS_REGION)));
	}
	return builder.build();
}
 
Example 10
Source Project: geowave   Source File: S3URLConnection.java    License: Apache License 2.0 6 votes vote down vote up
private ClientConfiguration buildClientConfig() {
  final String userAgent = System.getProperty(PROP_S3_HANDLER_USER_AGENT, null);
  final String protocol = System.getProperty(PROP_S3_HANDLER_PROTOCOL, "https");
  final String signerOverride = System.getProperty(PROP_S3_HANDLER_SIGNER_OVERRIDE, null);

  final ClientConfiguration clientConfig =
      new ClientConfiguration().withProtocol(
          "https".equalsIgnoreCase(protocol) ? Protocol.HTTPS : Protocol.HTTP);

  if (userAgent != null) {
    clientConfig.setUserAgent(userAgent);
  }
  if (signerOverride != null) {
    clientConfig.setSignerOverride(signerOverride);
  }

  return clientConfig;
}
 
Example 11
Source Project: herd   Source File: AwsClientFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a client for accessing Amazon EC2 service.
 *
 * @param awsParamsDto the AWS related parameters DTO that includes optional AWS credentials and proxy information
 *
 * @return the Amazon EC2 client
 */
@Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME)
public AmazonEC2 getEc2Client(AwsParamsDto awsParamsDto)
{
    // Get client configuration.
    ClientConfiguration clientConfiguration = awsHelper.getClientConfiguration(awsParamsDto);

    // If specified, use the AWS credentials passed in.
    if (StringUtils.isNotBlank(awsParamsDto.getAwsAccessKeyId()))
    {
        return AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(
            new BasicSessionCredentials(awsParamsDto.getAwsAccessKeyId(), awsParamsDto.getAwsSecretKey(), awsParamsDto.getSessionToken())))
            .withClientConfiguration(clientConfiguration).withRegion(awsParamsDto.getAwsRegionName()).build();
    }
    // Otherwise, use the default AWS credentials provider chain.
    else
    {
        return AmazonEC2ClientBuilder.standard().withClientConfiguration(clientConfiguration).withRegion(awsParamsDto.getAwsRegionName()).build();
    }
}
 
Example 12
public static void formatOptions(S3ImportOptions options) {

    ClientConfiguration configuration =
        new ClientConfiguration()
            .withMaxConnections(options.getMaxConnections())
            .withConnectionTimeout(options.getConnectionTimeout())
            .withSocketTimeout(options.getSocketTimeout());

    options.setClientConfiguration(configuration);

    if (options.getS3BucketUrl().toLowerCase().startsWith(AWS_S3_PREFIX)) {
      setAwsCredentials(options);
    }

    if (options.getAwsRegion() == null) {
      setAwsDefaultRegion(options);
    }
  }
 
Example 13
Source Project: bazel-buildfarm   Source File: AwsMetricsPublisher.java    License: Apache License 2.0 6 votes vote down vote up
private AmazonSNSAsync initSnsClient() {
  logger.log(Level.INFO, "Initializing SNS Client.");
  return AmazonSNSAsyncClientBuilder.standard()
      .withRegion(region)
      .withClientConfiguration(
          new ClientConfiguration().withMaxConnections(snsClientMaxConnections))
      .withCredentials(
          new AWSStaticCredentialsProvider(
              new AWSCredentials() {
                @Override
                public String getAWSAccessKeyId() {
                  return awsAccessKeyId;
                }

                @Override
                public String getAWSSecretKey() {
                  return awsSecretKey;
                }
              }))
      .build();
}
 
Example 14
Source Project: nifi   Source File: ClientSideCEncryptionStrategy.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create an encryption client.
 *
 * @param credentialsProvider AWS credentials provider.
 * @param clientConfiguration Client configuration
 * @param kmsRegion not used by this encryption strategy
 * @param keyIdOrMaterial client master key, always base64 encoded
 * @return AWS S3 client
 */
@Override
public AmazonS3Client createEncryptionClient(AWSCredentialsProvider credentialsProvider, ClientConfiguration clientConfiguration, String kmsRegion, String keyIdOrMaterial) {
    ValidationResult keyValidationResult = validateKey(keyIdOrMaterial);
    if (!keyValidationResult.isValid()) {
        throw new IllegalArgumentException("Invalid client key; " + keyValidationResult.getExplanation());
    }

    byte[] keyMaterial = Base64.decodeBase64(keyIdOrMaterial);
    SecretKeySpec symmetricKey = new SecretKeySpec(keyMaterial, "AES");
    StaticEncryptionMaterialsProvider encryptionMaterialsProvider = new StaticEncryptionMaterialsProvider(new EncryptionMaterials(symmetricKey));

    AmazonS3EncryptionClient client = new AmazonS3EncryptionClient(credentialsProvider, encryptionMaterialsProvider);

    return client;
}
 
Example 15
Source Project: file-service   Source File: FileClient.java    License: Apache License 2.0 6 votes vote down vote up
private void initAmazonS3() {
    BasicAWSCredentials credentials = new BasicAWSCredentials(
            fileClientConfig.getAccessKey(), fileClientConfig.getSecretKey());
    ClientConfiguration clientConfig = new ClientConfiguration();
    clientConfig.setSignerOverride("S3SignerType");
    String region = fileClientConfig.getRegion() == null ? FileClientConfiguration.US_EAST_1 : fileClientConfig.getRegion();
    this.amazonS3 = AmazonS3ClientBuilder.standard()
            .withCredentials(new AWSStaticCredentialsProvider(credentials))
            .withClientConfiguration(clientConfig)
            .withEndpointConfiguration(
                    new AwsClientBuilder.EndpointConfiguration(
                            fileClientConfig.getEndpoint(),
                            region))
            .withPathStyleAccessEnabled(fileClientConfig.getWithPath())
            .build();

}
 
Example 16
Source Project: cs-actions   Source File: ServiceCatalogClientBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public static AWSServiceCatalog getServiceCatalogClientBuilder(
        String accessKeyId,
        String secretAccessKey,
        String proxyHost,
        Integer proxyPort,
        String proxyUsername,
        String proxyPassword,
        Integer connectTimeoutMs,
        Integer executionTimeoutMs,
        String region,
        boolean async) {

    ClientConfiguration clientConfiguration = new ClientConfiguration();
    clientConfiguration.setConnectionTimeout(connectTimeoutMs);
    clientConfiguration.setClientExecutionTimeout(executionTimeoutMs);

    if (!StringUtils.isEmpty(proxyHost)) {
        clientConfiguration.setProxyHost(proxyHost);
        clientConfiguration.setProxyPort(proxyPort);
        if (!StringUtils.isEmpty(proxyUsername)) {
            clientConfiguration.setProxyUsername(proxyUsername);
            clientConfiguration.setProxyPassword(proxyPassword);
        }
    }
    if (!async) {
        return AWSServiceCatalogClientBuilder.standard()
                .withRegion(region)
                .withClientConfiguration(clientConfiguration)
                .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKeyId, secretAccessKey)))
                .build();
    }
    return AWSServiceCatalogAsyncClientBuilder.standard()
            .withRegion(region)
            .withClientConfiguration(clientConfiguration)
            .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKeyId, secretAccessKey)))
            .build();


}
 
Example 17
Source Project: kinesis-log4j-appender   Source File: KinesisAppender.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set proxy configuration based on system properties. Some of the properties are standard
 * properties documented by Oracle (http.proxyHost, http.proxyPort, http.auth.ntlm.domain),
 * and others are from common convention (http.proxyUser, http.proxyPassword).
 *
 * Finally, for NTLM authentication the workstation name is taken from the environment as
 * COMPUTERNAME. We set this on the client configuration only if the NTLM domain was specified.
 */
private ClientConfiguration setProxySettingsFromSystemProperties(ClientConfiguration clientConfiguration) {

    final String proxyHost = System.getProperty("http.proxyHost");
    if(proxyHost != null) {
        clientConfiguration.setProxyHost(proxyHost);
    }

    final String proxyPort = System.getProperty("http.proxyPort");
    if(proxyPort != null) {
        clientConfiguration.setProxyPort(Integer.parseInt(proxyPort));
    }

    final String proxyUser = System.getProperty("http.proxyUser");
    if(proxyUser != null) {
        clientConfiguration.setProxyUsername(proxyUser);
    }

    final String proxyPassword = System.getProperty("http.proxyPassword");
    if(proxyPassword != null) {
        clientConfiguration.setProxyPassword(proxyPassword);
    }

    final String proxyDomain = System.getProperty("http.auth.ntlm.domain");
    if(proxyDomain != null) {
        clientConfiguration.setProxyDomain(proxyDomain);
    }

    final String workstation = System.getenv("COMPUTERNAME");
    if(proxyDomain != null && workstation != null) {
        clientConfiguration.setProxyWorkstation(workstation);
    }

    return clientConfiguration;
}
 
Example 18
/**
 * Basic constructor which is recommended when extending this class.
 *
 * @param disable Whether to disable Glue usage. Useful for users that wish to rely on their handlers' schema inference.
 * @param sourceType The source type, used in diagnostic logging.
 */
public GlueMetadataHandler(boolean disable, String sourceType)
{
    super(sourceType);
    if (disable) {
        //The current instance does not want to leverage Glue for metadata
        awsGlue = null;
    }
    else {
        awsGlue = AWSGlueClientBuilder.standard()
                .withClientConfiguration(new ClientConfiguration().withConnectionTimeout(CONNECT_TIMEOUT))
                .build();
    }
}
 
Example 19
@Provides
protected ApiGateway provideAmazonApiGateway(AWSCredentialsProvider credsProvider,
                                             RetryPolicy.BackoffStrategy backoffStrategy,
                                             @Named("region") String region) {

    final RetryPolicy retrypolicy = new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION, backoffStrategy, 5, true);

    final ClientConfiguration clientConfig = new ClientConfiguration().withUserAgent(USER_AGENT).withRetryPolicy(retrypolicy);

    return new AmazonApiGateway(getEndpoint(region)).with(credsProvider).with(clientConfig).getApiGateway();
}
 
Example 20
Source Project: nifi   Source File: MockAWSProcessor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create client using credentials provider. This is the preferred way for creating clients
 */
@Override
protected AmazonS3Client createClient(final ProcessContext context, final AWSCredentialsProvider credentialsProvider, final ClientConfiguration config) {
    getLogger().info("Creating client with credentials provider");
    final AmazonS3Client s3 = new AmazonS3Client(credentialsProvider, config);
    return s3;
}
 
Example 21
Source Project: Flink-CEPplus   Source File: KinesisProxyTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testClientConfigOverride() {

	Properties configProps = new Properties();
	configProps.setProperty(AWSConfigConstants.AWS_REGION, "us-east-1");
	configProps.setProperty(AWSUtil.AWS_CLIENT_CONFIG_PREFIX + "socketTimeout", "9999");

	KinesisProxyInterface proxy = KinesisProxy.create(configProps);

	AmazonKinesis kinesisClient = Whitebox.getInternalState(proxy, "kinesisClient");
	ClientConfiguration clientConfiguration = Whitebox.getInternalState(kinesisClient,
		"clientConfiguration");
	assertEquals(9999, clientConfiguration.getSocketTimeout());
}
 
Example 22
Source Project: pipeline-aws-plugin   Source File: ProxyTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldParseProxyWithoutPort() throws Exception {
	EnvVars vars = new EnvVars();
	vars.put(ProxyConfiguration.HTTPS_PROXY, "http://127.0.0.1/");
	ClientConfiguration config = new ClientConfiguration();
	config.setProtocol(Protocol.HTTPS);
	ProxyConfiguration.configure(vars, config);

	Assert.assertNull(config.getProxyUsername());
	Assert.assertNull(config.getProxyPassword());
	Assert.assertEquals("127.0.0.1", config.getProxyHost());
	Assert.assertEquals(443, config.getProxyPort());
}
 
Example 23
Source Project: flink   Source File: KinesisProxy.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create the Kinesis client, using the provided configuration properties and default {@link ClientConfiguration}.
 * Derived classes can override this method to customize the client configuration.
 * @param configProps
 * @return
 */
protected AmazonKinesis createKinesisClient(Properties configProps) {

	ClientConfiguration awsClientConfig = new ClientConfigurationFactory().getConfig();
	AWSUtil.setAwsClientConfigProperties(awsClientConfig, configProps);
	return AWSUtil.createKinesisClient(configProps, awsClientConfig);
}
 
Example 24
Source Project: flink   Source File: KinesisProxyTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testClientConfigOverride() {

	Properties configProps = new Properties();
	configProps.setProperty(AWSConfigConstants.AWS_REGION, "us-east-1");
	configProps.setProperty(AWSUtil.AWS_CLIENT_CONFIG_PREFIX + "socketTimeout", "9999");

	KinesisProxyInterface proxy = KinesisProxy.create(configProps);

	AmazonKinesis kinesisClient = Whitebox.getInternalState(proxy, "kinesisClient");
	ClientConfiguration clientConfiguration = Whitebox.getInternalState(kinesisClient,
		"clientConfiguration");
	assertEquals(9999, clientConfiguration.getSocketTimeout());
}
 
Example 25
Source Project: getting-started   Source File: GettingStarted.java    License: MIT License 5 votes vote down vote up
private static RequestExecutionBuilder buildRequest(final Request request) {
  try {
    return new AmazonHttpClient(new ClientConfiguration()).requestExecutionBuilder()
        .executionContext(new ExecutionContext(true)).request(request)
        .errorResponseHandler(new ErrorResponseHandler(false));
  } catch (AmazonServiceException exception) {
    System.out.println("Unexpected status code in response: " + exception.getStatusCode());
    System.out.println("Content: " + exception.getRawResponseContent());
    throw new RuntimeException("Failed request. Aborting.");
  }
}
 
Example 26
Source Project: java-specialagent   Source File: AwsTest.java    License: Apache License 2.0 5 votes vote down vote up
private static AmazonDynamoDB buildClient() {
  final EndpointConfiguration endpointConfiguration = new EndpointConfiguration("http://localhost:8000", "us-west-2");
  final BasicAWSCredentials awsCreds = new BasicAWSCredentials("access_key_id", "secret_key_id");
  return AmazonDynamoDBClientBuilder
    .standard()
    .withEndpointConfiguration(endpointConfiguration)
    .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
    .withClientConfiguration(new ClientConfiguration().withConnectionTimeout(1))
    .build();
}
 
Example 27
Source Project: development   Source File: EC2Communication.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Return amazon interface
 * 
 * @return AmazonEC2 client ec2
 */

AmazonEC2 getEC2() {
    if (ec2 == null) {
        String endpoint = ENDPOINT_PREFIX + ph.getRegion()
                + ENDPOINT_SUFFIX;
        String proxyHost = System.getProperty(HTTPS_PROXY_HOST);
        String proxyPort = System.getProperty(HTTPS_PROXY_PORT);
        String proxyUser = System.getProperty(HTTPS_PROXY_USER);
        String proxyPassword = System.getProperty(HTTPS_PROXY_PASSWORD);

        int proxyPortInt = 0;
        try {
            proxyPortInt = Integer.parseInt(proxyPort);
        } catch (NumberFormatException e) {
            // ignore
        }
        ClientConfiguration clientConfiguration = new ClientConfiguration();
        if (!isNonProxySet(endpoint)) {
            if (proxyHost != null) {
                clientConfiguration.setProxyHost(proxyHost);
            }
            if (proxyPortInt > 0) {
                clientConfiguration.setProxyPort(proxyPortInt);
            }
            if (proxyUser != null && proxyUser.length() > 0) {
                clientConfiguration.setProxyUsername(proxyUser);
            }
            if (proxyPassword != null && proxyPassword.length() > 0) {
                clientConfiguration.setProxyPassword(proxyPassword);
            }
        }
        ec2 = getEC2(credentialsProvider, clientConfiguration);
        ec2.setEndpoint(endpoint);
    }
    return ec2;
}
 
Example 28
/**
 * Create client using AWSCredentials
 *
 * @deprecated use {@link #createClient(ProcessContext, AWSCredentialsProvider, ClientConfiguration)} instead
 */
@Override
protected AWSLambdaClient createClient(final ProcessContext context, final AWSCredentials credentials, final ClientConfiguration config) {
    getLogger().info("Creating client using aws credentials");

    return new AWSLambdaClient(credentials, config);
}
 
Example 29
Source Project: pipeline-aws-plugin   Source File: ProxyTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSetNonProxyHosts() throws Exception {
	EnvVars vars = new EnvVars();
	vars.put(ProxyConfiguration.NO_PROXY, "127.0.0.1,localhost");
	vars.put(ProxyConfiguration.HTTPS_PROXY, "http://127.0.0.1:8888/");
	ClientConfiguration config = new ClientConfiguration();
	config.setProtocol(Protocol.HTTPS);
	ProxyConfiguration.configure(vars, config);

	Assert.assertEquals("127.0.0.1|localhost", config.getNonProxyHosts());
}
 
Example 30
@Test
public void testBuild_happy() throws Exception {
    AWSCredentialsProvider credentials = new AWSStaticCredentialsProvider(new BasicAWSCredentials("foo", "bar"));

    GenericApiGatewayClient client = new GenericApiGatewayClientBuilder()
            .withClientConfiguration(new ClientConfiguration())
            .withCredentials(credentials)
            .withEndpoint("https://foobar.execute-api.us-east-1.amazonaws.com")
            .withRegion(Region.getRegion(Regions.fromName("us-east-1")))
            .withApiKey("12345")
            .build();

    Assert.assertEquals("Wrong service name","execute-api", client.getServiceNameIntern());
}