software.amazon.awssdk.core.sync.RequestBody Java Examples

The following examples show how to use software.amazon.awssdk.core.sync.RequestBody. 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
Source File: InterceptorTestUtils.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
public static Context.ModifyHttpRequest modifyHttpRequestContext(SdkRequest request, SdkHttpRequest sdkHttpRequest) {
    Optional<RequestBody> requestBody = Optional.of(RequestBody.fromString("helloworld"));
    Optional<AsyncRequestBody> asyncRequestBody = Optional.of(AsyncRequestBody.fromString("helloworld"));

    return new Context.ModifyHttpRequest() {
        @Override
        public SdkHttpRequest httpRequest() {
            return sdkHttpRequest;
        }

        @Override
        public Optional<RequestBody> requestBody() {
            return requestBody;
        }

        @Override
        public Optional<AsyncRequestBody> asyncRequestBody() {
            return asyncRequestBody;
        }

        @Override
        public SdkRequest request() {
            return request;
        }
    };
}
 
Example #2
Source File: DefaultS3Presigner.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * Marshal the request and update the execution context with the result.
 */
private <T> void marshalRequestAndUpdateContext(ExecutionContext execCtx,
                                                Class<T> requestType,
                                                Function<T, SdkHttpFullRequest> requestMarshaller) {
    T sdkRequest = Validate.isInstanceOf(requestType, execCtx.interceptorContext().request(),
                                         "Interceptor generated unsupported type (%s) when %s was expected.",
                                         execCtx.interceptorContext().request().getClass(), requestType);

    SdkHttpFullRequest marshalledRequest = requestMarshaller.apply(sdkRequest);

    // TODO: The core SDK doesn't put the request body into the interceptor context. That should be fixed.
    Optional<RequestBody> requestBody = marshalledRequest.contentStreamProvider()
                                                         .map(ContentStreamProvider::newStream)
                                                         .map(is -> invokeSafely(() -> IoUtils.toByteArray(is)))
                                                         .map(RequestBody::fromBytes);

    execCtx.interceptorContext(execCtx.interceptorContext().copy(r -> r.httpRequest(marshalledRequest)
                                                                       .requestBody(requestBody.orElse(null))));
}
 
Example #3
Source File: LocalS3ClientTest.java    From edison-microservice with Apache License 2.0 6 votes vote down vote up
@Test
public void deleteShouldRemoveItemsFromBucket() {
    // given
    PutObjectRequest putObjectRequest = PutObjectRequest.builder()
            .bucket("someBucket")
            .key("someObject")
            .build();
    RequestBody requestBody = RequestBody.fromString("content");
    testee.putObject(putObjectRequest, requestBody);
    testee.deleteObjects(DeleteObjectsRequest.builder().bucket("someBucket").delete(Delete.builder().objects
            (ObjectIdentifier.builder().key("someObject").build()).build()).build());

    // when
    ListObjectsV2Request listObjectsV2Request = ListObjectsV2Request.builder()
            .bucket("someBucket")
            .build();
    ListObjectsV2Response listObjectsV2Response = testee.listObjectsV2(listObjectsV2Request);

    //then
    assertThat(listObjectsV2Response.contents().size(), is(0));
}
 
Example #4
Source File: ExecutionInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void sync_streamingInput_success_allInterceptorMethodsCalled() throws IOException {
    // Given
    ExecutionInterceptor interceptor = mock(NoOpInterceptor.class, CALLS_REAL_METHODS);
    ProtocolRestJsonClient client = client(interceptor);
    StreamingInputOperationRequest request = StreamingInputOperationRequest.builder().build();
    stubFor(post(urlPathEqualTo(STREAMING_INPUT_PATH)).willReturn(aResponse().withStatus(200).withBody("")));

    // When
    client.streamingInputOperation(request, RequestBody.fromBytes(new byte[] {0}));

    // Expect
    Context.BeforeTransmission beforeTransmissionArg = captureBeforeTransmissionArg(interceptor, false);
    assertThat(beforeTransmissionArg.requestBody().get().contentStreamProvider().newStream().read()).isEqualTo(0);
    assertThat(beforeTransmissionArg.httpRequest().firstMatchingHeader(Header.CONTENT_LENGTH).get())
        .contains(Long.toString(1L));
}
 
Example #5
Source File: AmazonMachineLearningIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private static void setUpS3() {
    s3 = S3Client.builder()
                 .credentialsProvider(CREDENTIALS_PROVIDER_CHAIN)
                 .region(Region.US_EAST_1)
                 .build();

    s3.createBucket(CreateBucketRequest.builder().bucket(BUCKET_NAME).build());

    Waiter.run(() -> s3.putObject(PutObjectRequest.builder()
                                                  .bucket(BUCKET_NAME)
                                                  .key(KEY)
                                                  .acl(ObjectCannedACL.PUBLIC_READ)
                                                  .build(),
                                  RequestBody.fromBytes(DATA.getBytes())))
          .ignoringException(NoSuchBucketException.class)
          .orFail();
}
 
Example #6
Source File: LocalS3ClientTest.java    From edison-microservice with Apache License 2.0 6 votes vote down vote up
@Test
public void getObjectShouldReturnStreamWithData() throws Exception {
    // given
    testee.putObject(PutObjectRequest.builder()
                    .bucket("someBucket")
                    .key("someKey")
                    .build(),
            RequestBody.fromString("testdata"));
    //when
    ResponseInputStream<GetObjectResponse> inputStream = testee.getObject(GetObjectRequest.builder()
            .bucket("someBucket")
            .key("someKey")
            .build());

    //then
    String data = IoUtils.toUtf8String(inputStream);
    assertThat(data, is("testdata"));
}
 
Example #7
Source File: S3SyncClientResource.java    From quarkus-quickstarts with Apache License 2.0 6 votes vote down vote up
@POST
@Path("upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@MultipartForm FormData formData) throws Exception {

    if (formData.fileName == null || formData.fileName.isEmpty()) {
        return Response.status(Status.BAD_REQUEST).build();
    }

    if (formData.mimeType == null || formData.mimeType.isEmpty()) {
        return Response.status(Status.BAD_REQUEST).build();
    }

    PutObjectResponse putResponse = s3.putObject(buildPutRequest(formData),
            RequestBody.fromFile(uploadToTemp(formData.data)));
    if (putResponse != null) {
        return Response.ok().status(Status.CREATED).build();
    } else {
        return Response.serverError().build();
    }
}
 
Example #8
Source File: DefaultS3Presigner.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * Get the HTTP full request from the execution context.
 */
private SdkHttpFullRequest getHttpFullRequest(ExecutionContext execCtx) {
    SdkHttpRequest requestFromInterceptor = execCtx.interceptorContext().httpRequest();
    Optional<RequestBody> bodyFromInterceptor = execCtx.interceptorContext().requestBody();

    return SdkHttpFullRequest.builder()
                             .method(requestFromInterceptor.method())
                             .protocol(requestFromInterceptor.protocol())
                             .host(requestFromInterceptor.host())
                             .port(requestFromInterceptor.port())
                             .encodedPath(requestFromInterceptor.encodedPath())
                             .rawQueryParameters(requestFromInterceptor.rawQueryParameters())
                             .headers(requestFromInterceptor.headers())
                             .contentStreamProvider(bodyFromInterceptor.map(RequestBody::contentStreamProvider)
                                                                       .orElse(null))
                             .build();
}
 
Example #9
Source File: AddContentMd5HeaderInterceptor.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public Optional<RequestBody> modifyHttpContent(Context.ModifyHttpRequest context,
                                               ExecutionAttributes executionAttributes) {

    if (!BLACKLIST_METHODS.contains(context.request().getClass()) && context.requestBody().isPresent()
        && !context.httpRequest().firstMatchingHeader(CONTENT_MD5).isPresent()) {

        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            IoUtils.copy(context.requestBody().get().contentStreamProvider().newStream(), baos);
            executionAttributes.putAttribute(CONTENT_MD5_ATTRIBUTE, Md5Utils.md5AsBase64(baos.toByteArray()));
            return context.requestBody();
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }

    return context.requestBody();
}
 
Example #10
Source File: AccessPointsIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void transfer_Succeeds_UsingAccessPoint() {
    StringJoiner apArn = new StringJoiner(":");
    apArn.add("arn").add("aws").add("s3").add("us-west-2").add(accountId).add("accesspoint").add(AP_NAME);

    s3.putObject(PutObjectRequest.builder()
                                 .bucket(apArn.toString())
                                 .key(KEY)
                                 .build(), RequestBody.fromString("helloworld"));

    String objectContent = s3.getObjectAsBytes(GetObjectRequest.builder()
                                                               .bucket(apArn.toString())
                                                               .key(KEY)
                                                               .build()).asUtf8String();

    assertThat(objectContent).isEqualTo("helloworld");
}
 
Example #11
Source File: S3PinotFS.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
@Override
public boolean mkdir(URI uri)
    throws IOException {
  LOGGER.info("mkdir {}", uri);
  try {
    Preconditions.checkNotNull(uri, "uri is null");
    String path = normalizeToDirectoryPrefix(uri);
    // Bucket root directory already exists and cannot be created
    if (path.equals(DELIMITER)) {
      return true;
    }

    PutObjectRequest putObjectRequest = PutObjectRequest.builder().bucket(uri.getHost()).key(path).build();

    PutObjectResponse putObjectResponse = _s3Client.putObject(putObjectRequest, RequestBody.fromBytes(new byte[0]));

    return putObjectResponse.sdkHttpResponse().isSuccessful();
  } catch (Throwable t) {
    throw new IOException(t);
  }
}
 
Example #12
Source File: LocalS3ClientTest.java    From synapse with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldListObjectsInBucket() {
    // given
    PutObjectRequest putObjectRequest = PutObjectRequest.builder()
            .bucket("someBucket")
            .key("someObject")
            .build();
    RequestBody requestBody = RequestBody.fromString("content");
    testee.putObject(putObjectRequest, requestBody);
    // when
    ListObjectsV2Request listObjectsV2Request = ListObjectsV2Request.builder()
            .bucket("someBucket")
            .build();
    ListObjectsV2Response listObjectsV2Response = testee.listObjectsV2(listObjectsV2Request);

    //then
    assertThat(listObjectsV2Response.contents().size(), is(1));
    assertThat(listObjectsV2Response.contents().get(0).key(), is("someObject"));
}
 
Example #13
Source File: SyncClientInterface.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a simple method for operations with streaming input and output members.
 * Streaming input member that reads data from a file and a streaming output member that write response content to a file.
 */
private MethodSpec streamingInputOutputFileSimpleMethod(OperationModel opModel,
                                                        TypeName responseType,
                                                        ClassName requestType) {
    return MethodSpec.methodBuilder(opModel.getMethodName())
                     .returns(responseType)
                     .addModifiers(Modifier.PUBLIC, Modifier.DEFAULT)
                     .addParameter(requestType, opModel.getInput().getVariableName())
                     .addParameter(ClassName.get(Path.class), "sourcePath")
                     .addParameter(ClassName.get(Path.class), "destinationPath")
                     .addJavadoc(opModel.getDocs(model, ClientType.SYNC, SimpleMethodOverload.FILE))
                     .addExceptions(getExceptionClasses(model, opModel))
                     .addStatement("return $L($L, $T.fromFile(sourcePath), $T.toFile(destinationPath))",
                                   opModel.getMethodName(),
                                   opModel.getInput().getVariableName(),
                                   ClassName.get(RequestBody.class),
                                   ClassName.get(ResponseTransformer.class))
                     .build();
}
 
Example #14
Source File: S3PresignerIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void completeMultipartUpload_CanBePresigned() throws IOException {
    String objectKey = generateRandomObjectKey();
    S3TestUtils.addCleanupTask(S3PresignerIntegrationTest.class,
                               () -> client.deleteObject(r -> r.bucket(testBucket).key(objectKey)));

    CreateMultipartUploadResponse create = client.createMultipartUpload(createMultipartUploadRequest(objectKey));
    S3TestUtils.addCleanupTask(S3PresignerIntegrationTest.class,
                               () -> client.abortMultipartUpload(abortMultipartUploadRequest(objectKey, create.uploadId())));

    UploadPartResponse uploadPartResponse = client.uploadPart(uploadPartRequest(objectKey, create),
                                                              RequestBody.fromString(testObjectContent));
    String etag = uploadPartResponse.eTag();

    PresignedCompleteMultipartUploadRequest presignedRequest =
        presigner.presignCompleteMultipartUpload(
            r -> r.signatureDuration(Duration.ofDays(1))
                  .completeMultipartUploadRequest(createMultipartUploadRequest(objectKey, create, etag)));

    assertThat(execute(presignedRequest, presignedRequest.signedPayload().get().asUtf8String())
                   .httpResponse().isSuccessful()).isTrue();

    String content = client.getObjectAsBytes(r -> r.bucket(testBucket).key(objectKey)).asUtf8String();
    assertThat(content).isEqualTo(testObjectContent);
}
 
Example #15
Source File: PutObject.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static String putS3Object(S3Client s3, String bucketName, String objectKey, String objectPath) {

        try {
            //Put a file into the bucket
            PutObjectResponse response = s3.putObject(PutObjectRequest.builder()
                            .bucket(bucketName)
                            .key(objectKey)
                            .build(),
                    RequestBody.fromBytes(getObjectFile(objectPath)));

            return response.eTag();
        } catch (S3Exception | FileNotFoundException e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
        return "";
    }
 
Example #16
Source File: BucketAccelerateIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testAccelerateEndpoint() throws Exception {

    String status = s3.getBucketAccelerateConfiguration(GetBucketAccelerateConfigurationRequest.builder()
                                                                                               .bucket(US_BUCKET_NAME)
                                                                                               .build())
                      .statusAsString();

    if (status == null || !status.equals("Enabled")) {
        enableAccelerateOnBucket();
    }

    // PutObject
    File uploadFile = new RandomTempFile(KEY_NAME, 1000);
    try {
        accelerateClient.putObject(PutObjectRequest.builder()
                                                   .bucket(US_BUCKET_NAME)
                                                   .key(KEY_NAME)
                                                   .build(),
                                   RequestBody.fromFile(uploadFile));
    } catch (Exception e) {
        // We really only need to verify the request is using the accelerate endpoint
    }
}
 
Example #17
Source File: EndpointAddressInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private Context.ModifyHttpRequest context(SdkRequest request, SdkHttpRequest sdkHttpRequest) {
    return new Context.ModifyHttpRequest() {
        @Override
        public SdkHttpRequest httpRequest() {
            return sdkHttpRequest;
        }

        @Override
        public Optional<RequestBody> requestBody() {
            return null;
        }

        @Override
        public Optional<AsyncRequestBody> asyncRequestBody() {
            return null;
        }

        @Override
        public SdkRequest request() {
            return request;
        }
    };
}
 
Example #18
Source File: S3BundlePersistenceProvider.java    From nifi-registry with Apache License 2.0 6 votes vote down vote up
private synchronized void createOrUpdateBundleVersion(final BundlePersistenceContext context, final InputStream contentStream)
        throws BundlePersistenceException {
    final String key = getKey(context.getCoordinate());
    LOGGER.debug("Saving bundle version to S3 in bucket '{}' with key '{}'", new Object[]{s3BucketName, key});

    final PutObjectRequest request = PutObjectRequest.builder()
            .bucket(s3BucketName)
            .key(key)
            .build();

    final RequestBody requestBody = RequestBody.fromInputStream(contentStream, context.getSize());
    try {
        s3Client.putObject(request, requestBody);
        LOGGER.debug("Successfully saved bundle version to S3 bucket '{}' with key '{}'", new Object[]{s3BucketName, key});
    } catch (Exception e) {
        throw new BundlePersistenceException("Error saving bundle version to S3 due to: " + e.getMessage(), e);
    }
}
 
Example #19
Source File: AccessPointsIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void transfer_Succeeds_UsingAccessPoint_CrossRegion() {
    S3Client s3DifferentRegion =
        s3ClientBuilder().region(Region.US_EAST_1).serviceConfiguration(c -> c.useArnRegionEnabled(true)).build();

    StringJoiner apArn = new StringJoiner(":");
    apArn.add("arn").add("aws").add("s3").add("us-west-2").add(accountId).add("accesspoint").add(AP_NAME);

    s3DifferentRegion.putObject(PutObjectRequest.builder()
                                                .bucket(apArn.toString())
                                                .key(KEY)
                                                .build(), RequestBody.fromString("helloworld"));

    String objectContent = s3DifferentRegion.getObjectAsBytes(GetObjectRequest.builder()
                                                                              .bucket(apArn.toString())
                                                                              .key(KEY)
                                                                              .build()).asUtf8String();

    assertThat(objectContent).isEqualTo("helloworld");
}
 
Example #20
Source File: LocalS3ClientTest.java    From edison-microservice with Apache License 2.0 6 votes vote down vote up
@Test
public void getObjectShouldCreateFileWithData() throws Exception {
    // given
    testee.putObject(PutObjectRequest.builder()
                    .bucket("someBucket")
                    .key("someKey")
                    .build(),
            RequestBody.fromString("testdata"));
    //when
    Path tempFile = Files.createTempFile("test", "tmp");
    testee.getObject(GetObjectRequest.builder()
                    .bucket("someBucket")
                    .key("someKey")
                    .build(),
            tempFile);

    //then
    List<String> lines = Files.readAllLines(tempFile);
    assertThat(lines.get(0), is("testdata"));
}
 
Example #21
Source File: SyncClientInterface.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * @return Simple method for streaming input operations to read data from a file.
 */
private MethodSpec uploadFromFileSimpleMethod(OperationModel opModel, TypeName responseType, ClassName requestType) {
    return MethodSpec.methodBuilder(opModel.getMethodName())
                     .returns(responseType)
                     .addModifiers(Modifier.PUBLIC, Modifier.DEFAULT)
                     .addParameter(requestType, opModel.getInput().getVariableName())
                     .addParameter(ClassName.get(Path.class), "filePath")
                     .addJavadoc(opModel.getDocs(model, ClientType.SYNC, SimpleMethodOverload.FILE))
                     .addExceptions(getExceptionClasses(model, opModel))
                     .addStatement("return $L($L, $T.fromFile($L))", opModel.getMethodName(),
                                   opModel.getInput().getVariableName(),
                                   ClassName.get(RequestBody.class),
                                   "filePath")
                     .build();
}
 
Example #22
Source File: CreateMultipartUploadRequestInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void createMultipartRequest_shouldModifyHttpContent() {
    Context.ModifyHttpRequest modifyHttpRequest =
        InterceptorTestUtils.modifyHttpRequestContext(CreateMultipartUploadRequest.builder().build());
    Optional<RequestBody> requestBody =
        interceptor.modifyHttpContent(modifyHttpRequest,
                                      new ExecutionAttributes());
    assertThat(modifyHttpRequest.requestBody().get()).isNotEqualTo(requestBody.get());
}
 
Example #23
Source File: PutObjectHeaderTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void putObjectFile_headerShouldContainContentType() throws IOException {
    File file = new RandomTempFile("test.html", 10);
    stubFor(any(urlMatching(".*"))
                .willReturn(response()));
    s3Client.putObject(putObjectRequest, RequestBody.fromFile(file));
    verify(putRequestedFor(anyUrl()).withHeader(CONTENT_TYPE, equalTo("text/html")));
}
 
Example #24
Source File: PutObjectHeaderTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void putObjectBytes_headerShouldContainContentType() {
    stubFor(any(urlMatching(".*"))
                .willReturn(response()));
    s3Client.putObject(PutObjectRequest.builder().bucket("test").key("test").build(), RequestBody.fromBytes("Hello World".getBytes()));
    verify(putRequestedFor(anyUrl()).withHeader(CONTENT_TYPE, equalTo(Mimetype.MIMETYPE_OCTET_STREAM)));
}
 
Example #25
Source File: BaseSyncClientHandler.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private <InputT extends SdkRequest, OutputT, ReturnT> ReturnT doExecute(
    ClientExecutionParams<InputT, OutputT> executionParams,
    ExecutionContext executionContext,
    HttpResponseHandler<Response<ReturnT>> responseHandler) {

    InputT inputT = (InputT) finalizeSdkRequest(executionContext).request();

    InterceptorContext sdkHttpFullRequestContext = finalizeSdkHttpFullRequest(executionParams,
                                                                              executionContext,
                                                                              inputT,
                                                                              clientConfiguration);

    SdkHttpFullRequest marshalled = (SdkHttpFullRequest) sdkHttpFullRequestContext.httpRequest();

    // TODO Pass requestBody as separate arg to invoke
    Optional<RequestBody> requestBody = sdkHttpFullRequestContext.requestBody();

    if (requestBody.isPresent()) {
        marshalled = marshalled.toBuilder()
                               .contentStreamProvider(requestBody.get().contentStreamProvider())
                               .build();
    }

    return invoke(marshalled,
                  inputT,
                  executionContext,
                  responseHandler);
}
 
Example #26
Source File: SyncChecksumValidationInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void modifyHttpContent_putObjectRequest_checksumDisabled_shouldNotModify() {
    ExecutionAttributes executionAttributes = getExecutionAttributesWithChecksumDisabled();
    Context.ModifyHttpRequest modifyHttpRequest =
        InterceptorTestUtils.modifyHttpRequestContext(GetObjectRequest.builder().build());

    Optional<RequestBody> requestBody = interceptor.modifyHttpContent(modifyHttpRequest,
                                                                      executionAttributes);
    assertThat(requestBody).isEqualTo(modifyHttpRequest.requestBody());
}
 
Example #27
Source File: AWSFileStore.java    From para with Apache License 2.0 5 votes vote down vote up
@Override
public String store(String path, InputStream data) {
	if (StringUtils.startsWith(path, "/")) {
		path = path.substring(1);
	}
	if (StringUtils.isBlank(path) || data == null) {
		return null;
	}
	int maxFileSizeMBytes = Config.getConfigInt("para.s3.max_filesize_mb", 10);
	try {
		if (data.available() > 0 && data.available() <= (maxFileSizeMBytes * 1024 * 1024)) {
			Map<String, String> om = new HashMap<String, String>(3);
			om.put(HttpHeaders.CACHE_CONTROL, "max-age=15552000, must-revalidate");	// 180 days
			if (path.endsWith(".gz")) {
				om.put(HttpHeaders.CONTENT_ENCODING, "gzip");
				path = path.substring(0, path.length() - 3);
			}
			PutObjectRequest por = PutObjectRequest.builder().
					bucket(bucket).key(path).
					metadata(om).
					acl(ObjectCannedACL.PUBLIC_READ).
					storageClass(StorageClass.REDUCED_REDUNDANCY).build();
			s3.putObject(por, RequestBody.fromInputStream(data, data.available())); //.bucket, path, data, om
			return Utils.formatMessage(S3_URL, new DefaultAwsRegionProviderChain().getRegion().id(), bucket, path);
		}
	} catch (IOException e) {
		logger.error(null, e);
	} finally {
		try {
			data.close();
		} catch (IOException ex) {
			logger.error(null, ex);
		}
	}
	return null;
}
 
Example #28
Source File: SyncStreamingRequestMarshallerTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void contentLengthHeaderIsSet_forEmptyContent() {
    StreamingRequestMarshaller marshaller = createMarshaller(RequestBody.empty(), true, true, true);
    SdkHttpFullRequest httpFullRequest = marshaller.marshall(object);

    assertThat(httpFullRequest.firstMatchingHeader(Header.CONTENT_LENGTH)).isPresent();
    assertContentLengthValue(httpFullRequest, 0L);
    assertThat(httpFullRequest.firstMatchingHeader(Header.TRANSFER_ENCODING)).isEmpty();
}
 
Example #29
Source File: MarshallingTestRunner.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
void runTest(TestCase testCase) throws Exception {
    resetWireMock();
    ShapeModelReflector shapeModelReflector = createShapeModelReflector(testCase);
    if (!model.getShapes().get(testCase.getWhen().getOperationName() + "Request").isHasStreamingMember()) {
        clientReflector.invokeMethod(testCase, shapeModelReflector.createShapeObject());
    } else {
        clientReflector.invokeMethod(testCase,
                                     shapeModelReflector.createShapeObject(),
                                     RequestBody.fromString(shapeModelReflector.getStreamingMemberValue()));
    }
    LoggedRequest actualRequest = getLoggedRequest();
    testCase.getThen().getMarshallingAssertion().assertMatches(actualRequest);
}
 
Example #30
Source File: SyncChecksumValidationInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void modifyHttpContent_nonPutObjectRequest_shouldNotModify() {
    ExecutionAttributes executionAttributes = getExecutionAttributes();
    Context.ModifyHttpRequest modifyHttpRequest =
        InterceptorTestUtils.modifyHttpRequestContext(GetObjectRequest.builder().build());
    Optional<RequestBody> requestBody = interceptor.modifyHttpContent(modifyHttpRequest,
                                                                      executionAttributes);

    assertThat(requestBody).isEqualTo(modifyHttpRequest.requestBody());
}