Search in sources :

Example 1 with StringInputStream

use of com.amazonaws.util.StringInputStream in project pipeline-aws-plugin by jenkinsci.

the class JSONParameterFileParserTests method parseParameters.

@Test
public void parseParameters() throws IOException {
    JSONParameterFileParser parser = new JSONParameterFileParser();
    String json = "[{\"ParameterKey\": \"bar\", \"ParameterValue\": \"foo\"}]";
    Collection<Parameter> parameters = parser.parseParams(new StringInputStream(json));
    Assertions.assertThat(parameters).containsExactlyInAnyOrder(new Parameter().withParameterKey("bar").withParameterValue("foo"));
}
Also used : StringInputStream(com.amazonaws.util.StringInputStream) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Test(org.junit.Test)

Example 2 with StringInputStream

use of com.amazonaws.util.StringInputStream in project pipeline-aws-plugin by jenkinsci.

the class JSONParameterFileParserTests method parseKeyParameters.

@Test
public void parseKeyParameters() throws IOException {
    JSONParameterFileParser parser = new JSONParameterFileParser();
    String json = "[{\"ParameterKey\": \"bar\", \"UsePreviousValue\": true}]";
    Collection<Parameter> parameters = parser.parseParams(new StringInputStream(json));
    Assertions.assertThat(parameters).containsExactlyInAnyOrder(new Parameter().withParameterKey("bar").withUsePreviousValue(true));
}
Also used : StringInputStream(com.amazonaws.util.StringInputStream) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Test(org.junit.Test)

Example 3 with StringInputStream

use of com.amazonaws.util.StringInputStream in project pipeline-aws-plugin by jenkinsci.

the class YAMLParameterFileParserTests method parseParameterCollection.

@Test
public void parseParameterCollection() throws IOException {
    YAMLParameterFileParser parser = new YAMLParameterFileParser();
    String json = "bar:\n  - foo1\n  - foo2";
    Collection<Parameter> parameters = parser.parseParams(new StringInputStream(json));
    Assertions.assertThat(parameters).containsExactlyInAnyOrder(new Parameter().withParameterKey("bar").withParameterValue("foo1,foo2"));
}
Also used : StringInputStream(com.amazonaws.util.StringInputStream) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Test(org.junit.Test)

Example 4 with StringInputStream

use of com.amazonaws.util.StringInputStream in project spring-integration-aws by spring-projects.

the class S3MessageHandlerTests method testUploadInputStream.

@Test
public void testUploadInputStream() throws IOException {
    Expression actualKeyExpression = TestUtils.getPropertyValue(this.s3MessageHandler, "keyExpression", Expression.class);
    this.s3MessageHandler.setKeyExpression(null);
    InputStream payload = new StringInputStream("a");
    Message<?> message = MessageBuilder.withPayload(payload).setHeader("s3Command", S3MessageHandler.Command.UPLOAD.name()).setHeader("key", "myStream").build();
    assertThatThrownBy(() -> this.s3SendChannel.send(message)).hasCauseExactlyInstanceOf(IllegalStateException.class).hasMessageContaining("Specify a 'keyExpression' for non-java.io.File payloads");
    this.s3MessageHandler.setKeyExpression(actualKeyExpression);
    this.s3SendChannel.send(message);
    ArgumentCaptor<PutObjectRequest> putObjectRequestArgumentCaptor = ArgumentCaptor.forClass(PutObjectRequest.class);
    verify(this.amazonS3, atLeastOnce()).putObject(putObjectRequestArgumentCaptor.capture());
    PutObjectRequest putObjectRequest = putObjectRequestArgumentCaptor.getValue();
    assertThat(putObjectRequest.getBucketName()).isEqualTo(S3_BUCKET_NAME);
    assertThat(putObjectRequest.getKey()).isEqualTo("myStream");
    assertThat(putObjectRequest.getFile()).isNull();
    assertThat(putObjectRequest.getInputStream()).isNotNull();
    ObjectMetadata metadata = putObjectRequest.getMetadata();
    assertThat(metadata.getContentMD5()).isEqualTo(Md5Utils.md5AsBase64(payload));
    assertThat(metadata.getContentLength()).isEqualTo(1);
    assertThat(metadata.getContentType()).isEqualTo(MediaType.APPLICATION_JSON_VALUE);
    assertThat(metadata.getContentDisposition()).isEqualTo("test.json");
}
Also used : StringInputStream(com.amazonaws.util.StringInputStream) ValueExpression(org.springframework.integration.expression.ValueExpression) Expression(org.springframework.expression.Expression) ByteArrayInputStream(java.io.ByteArrayInputStream) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) StringInputStream(com.amazonaws.util.StringInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.junit.Test)

Example 5 with StringInputStream

use of com.amazonaws.util.StringInputStream in project amazon-cognito-android by aws.

the class RegisterDeviceRequestMarshaller method marshall.

public Request<RegisterDeviceRequest> marshall(RegisterDeviceRequest registerDeviceRequest) {
    if (registerDeviceRequest == null) {
        throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }
    Request<RegisterDeviceRequest> request = new DefaultRequest<RegisterDeviceRequest>(registerDeviceRequest, "AmazonCognitoSync");
    String target = "AWSCognitoSyncService.RegisterDevice";
    request.addHeader("X-Amz-Target", target);
    request.setHttpMethod(HttpMethodName.POST);
    String uriResourcePath = "/identitypools/{IdentityPoolId}/identity/{IdentityId}/device";
    uriResourcePath = uriResourcePath.replace("{IdentityPoolId}", (registerDeviceRequest.getIdentityPoolId() == null) ? "" : StringUtils.fromString(registerDeviceRequest.getIdentityPoolId()));
    uriResourcePath = uriResourcePath.replace("{IdentityId}", (registerDeviceRequest.getIdentityId() == null) ? "" : StringUtils.fromString(registerDeviceRequest.getIdentityId()));
    uriResourcePath = uriResourcePath.replaceAll("//", "/");
    if (uriResourcePath.contains("?")) {
        String queryString = uriResourcePath.substring(uriResourcePath.indexOf("?") + 1);
        uriResourcePath = uriResourcePath.substring(0, uriResourcePath.indexOf("?"));
        for (String s : queryString.split("[;&]")) {
            String[] nameValuePair = s.split("=");
            if (nameValuePair.length == 2) {
                if (!(nameValuePair[1].isEmpty()))
                    request.addParameter(nameValuePair[0], nameValuePair[1]);
            }
        }
    }
    request.setResourcePath(uriResourcePath);
    try {
        StringWriter stringWriter = new StringWriter();
        AwsJsonWriter jsonWriter = JsonUtils.getJsonWriter(stringWriter);
        jsonWriter.beginObject();
        if (registerDeviceRequest.getPlatform() != null) {
            jsonWriter.name("Platform").value(registerDeviceRequest.getPlatform());
        }
        if (registerDeviceRequest.getToken() != null) {
            jsonWriter.name("Token").value(registerDeviceRequest.getToken());
        }
        jsonWriter.endObject();
        jsonWriter.close();
        String snippet = stringWriter.toString();
        byte[] content = snippet.getBytes(UTF8);
        request.setContent(new StringInputStream(snippet));
        request.addHeader("Content-Length", Integer.toString(content.length));
        request.addHeader("Content-Type", "application/x-amz-json-1.0");
    } catch (Throwable t) {
        throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }
    return request;
}
Also used : AwsJsonWriter(com.amazonaws.util.json.AwsJsonWriter) StringInputStream(com.amazonaws.util.StringInputStream) DefaultRequest(com.amazonaws.DefaultRequest) StringWriter(java.io.StringWriter) AmazonClientException(com.amazonaws.AmazonClientException)

Aggregations

StringInputStream (com.amazonaws.util.StringInputStream)9 Test (org.junit.Test)7 Parameter (com.amazonaws.services.cloudformation.model.Parameter)4 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)3 AmazonClientException (com.amazonaws.AmazonClientException)2 DefaultRequest (com.amazonaws.DefaultRequest)2 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)2 S3Object (com.amazonaws.services.s3.model.S3Object)2 AwsJsonWriter (com.amazonaws.util.json.AwsJsonWriter)2 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 MockFlowFile (org.apache.nifi.util.MockFlowFile)2 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)1 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 Expression (org.springframework.expression.Expression)1 ValueExpression (org.springframework.integration.expression.ValueExpression)1