Search in sources :

Example 1 with ClientOverrideConfiguration

use of software.amazon.awssdk.core.client.config.ClientOverrideConfiguration in project flink by apache.

the class AWSAsyncSinkUtilTest method testCreateKinesisAsyncClient.

@Test
public void testCreateKinesisAsyncClient() {
    Properties properties = TestUtil.properties(AWS_REGION, "eu-west-2");
    MockAsyncClientBuilder builder = mockKinesisAsyncClientBuilder();
    ClientOverrideConfiguration clientOverrideConfiguration = ClientOverrideConfiguration.builder().build();
    SdkAsyncHttpClient httpClient = NettyNioAsyncHttpClient.builder().build();
    AWSAsyncSinkUtil.createAwsAsyncClient(properties, builder, httpClient, clientOverrideConfiguration);
    verify(builder).overrideConfiguration(clientOverrideConfiguration);
    verify(builder).httpClient(httpClient);
    verify(builder).region(Region.of("eu-west-2"));
    verify(builder).credentialsProvider(argThat(cp -> cp instanceof DefaultCredentialsProvider));
    verify(builder, never()).endpointOverride(any());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) AwsAsyncClientBuilder(software.amazon.awssdk.awscore.client.builder.AwsAsyncClientBuilder) SdkClientConfiguration(software.amazon.awssdk.core.client.config.SdkClientConfiguration) SdkAdvancedClientOption(software.amazon.awssdk.core.client.config.SdkAdvancedClientOption) NettyNioAsyncHttpClient(software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient) Duration(java.time.Duration) SdkClientOption(software.amazon.awssdk.core.client.config.SdkClientOption) URI(java.net.URI) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) Region(software.amazon.awssdk.regions.Region) ClientAsyncConfiguration(software.amazon.awssdk.core.client.config.ClientAsyncConfiguration) Properties(java.util.Properties) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) DefaultCredentialsProvider(software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider) Mockito.verify(org.mockito.Mockito.verify) AWS_REGION(org.apache.flink.connector.aws.config.AWSConfigConstants.AWS_REGION) AwsClientBuilder(software.amazon.awssdk.awscore.client.builder.AwsClientBuilder) Mockito.never(org.mockito.Mockito.never) SdkClient(software.amazon.awssdk.core.SdkClient) AWS_ENDPOINT(org.apache.flink.connector.aws.config.AWSConfigConstants.AWS_ENDPOINT) AWSAsyncSinkUtil.formatFlinkUserAgentPrefix(org.apache.flink.connector.aws.util.AWSAsyncSinkUtil.formatFlinkUserAgentPrefix) ClientOverrideConfiguration(software.amazon.awssdk.core.client.config.ClientOverrideConfiguration) Mockito.mock(org.mockito.Mockito.mock) ClientOverrideConfiguration(software.amazon.awssdk.core.client.config.ClientOverrideConfiguration) DefaultCredentialsProvider(software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with ClientOverrideConfiguration

use of software.amazon.awssdk.core.client.config.ClientOverrideConfiguration in project flink by apache.

the class AWSAsyncSinkUtilTest method testCreateKinesisAsyncClientWithEndpointOverride.

@Test
public void testCreateKinesisAsyncClientWithEndpointOverride() {
    Properties properties = TestUtil.properties(AWS_REGION, "eu-west-2");
    properties.setProperty(AWS_ENDPOINT, "https://localhost");
    MockAsyncClientBuilder builder = mockKinesisAsyncClientBuilder();
    ClientOverrideConfiguration clientOverrideConfiguration = ClientOverrideConfiguration.builder().build();
    SdkAsyncHttpClient httpClient = NettyNioAsyncHttpClient.builder().build();
    AWSAsyncSinkUtil.createAwsAsyncClient(properties, builder, httpClient, clientOverrideConfiguration);
    verify(builder).endpointOverride(URI.create("https://localhost"));
}
Also used : ClientOverrideConfiguration(software.amazon.awssdk.core.client.config.ClientOverrideConfiguration) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with ClientOverrideConfiguration

use of software.amazon.awssdk.core.client.config.ClientOverrideConfiguration in project aws-doc-sdk-examples by awsdocs.

the class SendNotifications method handleVoiceMessage.

public String handleVoiceMessage(String myDom) throws JDOMException, IOException {
    String mobileNum = "";
    List<String> listVal = new ArrayList<>();
    listVal.add("application/json");
    Map<String, List<String>> values = new HashMap<>();
    values.put("Content-Type", listVal);
    ClientOverrideConfiguration config2 = ClientOverrideConfiguration.builder().headers(values).build();
    PinpointSmsVoiceClient client = PinpointSmsVoiceClient.builder().overrideConfiguration(config2).region(Region.US_EAST_1).build();
    SAXBuilder builder = new SAXBuilder();
    Document jdomDocument = builder.build(new InputSource(new StringReader(myDom)));
    org.jdom2.Element root = jdomDocument.getRootElement();
    // get a list of children elements.
    List<org.jdom2.Element> students = root.getChildren("Student");
    for (org.jdom2.Element element : students) {
        mobileNum = element.getChildText("Phone");
        sendVoiceMsg(client, mobileNum);
    }
    client.close();
    return mobileNum;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) InputSource(org.xml.sax.InputSource) HashMap(java.util.HashMap) ClientOverrideConfiguration(software.amazon.awssdk.core.client.config.ClientOverrideConfiguration) ArrayList(java.util.ArrayList) Document(org.jdom2.Document) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) List(java.util.List) PinpointSmsVoiceClient(software.amazon.awssdk.services.pinpointsmsvoice.PinpointSmsVoiceClient)

Example 4 with ClientOverrideConfiguration

use of software.amazon.awssdk.core.client.config.ClientOverrideConfiguration in project aws-doc-sdk-examples by awsdocs.

the class SendVoiceMessage method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage: " + "SendVoiceMessage <originationNumber> <destinationNumber> \n\n" + "Where:\n" + "  originationNumber - the phone number or short code that you specify has to be associated with your Amazon Pinpoint account. For best results, specify long codes in E.164 format (for example, +1-555-555-5654). " + "  destinationNumber - the recipient's phone number.  For best results, you should specify the phone number in E.164 format (for example, +1-555-555-5654). ";
    if (args.length != 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String originationNumber = args[0];
    String destinationNumber = args[1];
    System.out.println("Sending a voice message");
    // Set the content type to application/json
    List<String> listVal = new ArrayList<>();
    listVal.add("application/json");
    Map<String, List<String>> values = new HashMap<>();
    values.put("Content-Type", listVal);
    ClientOverrideConfiguration config2 = ClientOverrideConfiguration.builder().headers(values).build();
    PinpointSmsVoiceClient client = PinpointSmsVoiceClient.builder().overrideConfiguration(config2).region(Region.US_EAST_1).build();
    sendVoiceMsg(client, originationNumber, destinationNumber);
    client.close();
}
Also used : HashMap(java.util.HashMap) ClientOverrideConfiguration(software.amazon.awssdk.core.client.config.ClientOverrideConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) PinpointSmsVoiceClient(software.amazon.awssdk.services.pinpointsmsvoice.PinpointSmsVoiceClient)

Example 5 with ClientOverrideConfiguration

use of software.amazon.awssdk.core.client.config.ClientOverrideConfiguration in project aws-doc-sdk-examples by awsdocs.

the class AmazonPinpointTest method setUp.

@BeforeAll
public static void setUp() throws IOException {
    // Run tests on Real AWS Resources
    region = Region.US_EAST_1;
    pinpoint = PinpointClient.builder().region(region).build();
    s3Client = S3Client.builder().region(region).build();
    // Set the VoiceClient
    // Set the content type to application/json
    List<String> listVal = new ArrayList<>();
    listVal.add("application/json");
    Map<String, List<String>> values = new HashMap<>();
    values.put("Content-Type", listVal);
    ClientOverrideConfiguration config2 = ClientOverrideConfiguration.builder().headers(values).build();
    voiceClient = PinpointSmsVoiceClient.builder().overrideConfiguration(config2).region(Region.US_EAST_1).build();
    try (InputStream input = AmazonPinpointTest.class.getClassLoader().getResourceAsStream("config.properties")) {
        Properties prop = new Properties();
        if (input == null) {
            System.out.println("Sorry, unable to find config.properties");
            return;
        }
        // load a properties file from class path, inside static method
        prop.load(input);
        // Populate the data members required for all tests
        appName = prop.getProperty("appName");
        bucket = prop.getProperty("bucket");
        path = prop.getProperty("path");
        roleArn = prop.getProperty("roleArn");
        userId = prop.getProperty("userId");
        s3BucketName = prop.getProperty("s3BucketName");
        s3BucketName = prop.getProperty("s3BucketName");
        iamExportRoleArn = prop.getProperty("iamExportRoleArn");
        existingApplicationId = prop.getProperty("existingApplicationId");
        filePath = prop.getProperty("filePath");
        subject = prop.getProperty("subject");
        senderAddress = prop.getProperty("senderAddress");
        toAddress = prop.getProperty("toAddress");
        originationNumber = prop.getProperty("originationNumber");
        destinationNumber = prop.getProperty("destinationNumber");
        message = prop.getProperty("message");
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
Also used : ClientOverrideConfiguration(software.amazon.awssdk.core.client.config.ClientOverrideConfiguration)

Aggregations

ClientOverrideConfiguration (software.amazon.awssdk.core.client.config.ClientOverrideConfiguration)6 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 SdkAsyncHttpClient (software.amazon.awssdk.http.async.SdkAsyncHttpClient)2 PinpointSmsVoiceClient (software.amazon.awssdk.services.pinpointsmsvoice.PinpointSmsVoiceClient)2 StringReader (java.io.StringReader)1 URI (java.net.URI)1 Duration (java.time.Duration)1 AWS_ENDPOINT (org.apache.flink.connector.aws.config.AWSConfigConstants.AWS_ENDPOINT)1 AWS_REGION (org.apache.flink.connector.aws.config.AWSConfigConstants.AWS_REGION)1 AWSAsyncSinkUtil.formatFlinkUserAgentPrefix (org.apache.flink.connector.aws.util.AWSAsyncSinkUtil.formatFlinkUserAgentPrefix)1 Document (org.jdom2.Document)1 SAXBuilder (org.jdom2.input.SAXBuilder)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.never (org.mockito.Mockito.never)1