use of com.amazonaws.services.s3.model.WriteGetObjectResponseRequest in project amazon-s3-object-lambda-default-configuration by aws-samples.
the class GetObjectResponseHandler method writeS3GetObjectErrorResponse.
public void writeS3GetObjectErrorResponse(HttpResponse<InputStream> presignedResponse) {
S3RequestError s3errorResponse;
try {
var xmlResponse = IOUtils.toString(presignedResponse.body());
s3errorResponse = new XMLErrorParser().parse(xmlResponse);
} catch (IOException | ParserConfigurationException | SAXException | NullPointerException e) {
this.logger.error("Error while reading the S3 error response body: " + e);
writeErrorResponse("Unexpected error while reading the S3 error response", Error.SERVER_ERROR);
return;
}
this.s3Client.writeGetObjectResponse(new WriteGetObjectResponseRequest().withRequestRoute(this.event.outputRoute()).withRequestToken(this.event.outputToken()).withErrorCode(s3errorResponse.getCode()).withContentLength(0L).withInputStream(new ByteArrayInputStream(new byte[0])).withErrorMessage(s3errorResponse.getMessage()).withStatusCode(presignedResponse.statusCode()));
}
use of com.amazonaws.services.s3.model.WriteGetObjectResponseRequest in project amazon-s3-object-lambda-default-configuration by aws-samples.
the class GetObjectResponseHandler method writeObjectResponse.
public void writeObjectResponse(HttpResponse<InputStream> presignedResponse, byte[] responseObjectByteArray) {
Checksum checksum;
try {
checksum = this.checksumGenerator.getChecksum(responseObjectByteArray);
} catch (Exception e) {
this.logger.error("Error while writing object response" + e);
writeErrorResponse("Error while writing object response.", Error.SERVER_ERROR);
return;
}
var checksumMap = new HashMap<String, String>();
checksumMap.put("algorithm", checksum.getAlgorithm());
checksumMap.put("digest", checksum.getChecksum());
var checksumObjectMetaData = new ObjectMetadata();
checksumObjectMetaData.setUserMetadata(checksumMap);
this.s3Client.writeGetObjectResponse(new WriteGetObjectResponseRequest().withRequestRoute(event.outputRoute()).withRequestToken(event.outputToken()).withInputStream(new ByteArrayInputStream(responseObjectByteArray)).withMetadata(checksumObjectMetaData).withStatusCode(presignedResponse.statusCode()));
}
use of com.amazonaws.services.s3.model.WriteGetObjectResponseRequest in project aws-sdk-java-v2 by aws.
the class S3ObjectLambdaOperationEndpointResolverTest method writeGetObjectResponse_regionIsS3External_shouldConvertEndpoint.
@Test
// TODO: Taken from the SEP but this test case is suspect. The SEP
@Disabled
public // endpoint s3.s3-external-1.amazonaws.com.
void writeGetObjectResponse_regionIsS3External_shouldConvertEndpoint() {
String requestRoute = "route";
String region = "s3-external-1";
String expectedHost = "route.s3-object-lambda.us-east-1.amazonaws.com";
WriteGetObjectResponseRequest request = WriteGetObjectResponseRequest.builder().requestRoute(requestRoute).build();
verifyObjectLambdaEndpoint("https", request, region, null, URI.create("https://" + expectedHost), S3Configuration.builder());
verifyObjectLambdaEndpoint("http", request, region, null, URI.create("http://" + expectedHost), S3Configuration.builder());
}
use of com.amazonaws.services.s3.model.WriteGetObjectResponseRequest in project aws-sdk-java-v2 by aws.
the class S3ObjectLambdaOperationEndpointResolverTest method writeGetObjectResponse_regionIsFipsInSuffix_shouldConvertEndpoint.
@Test
// SDK doesn't resolve fips endpoints correctly
@Disabled
public void writeGetObjectResponse_regionIsFipsInSuffix_shouldConvertEndpoint() {
String requestRoute = "route";
String region = "us-gov-east-1-fips";
String expectedHost = "route.s3-object-lambda-fips.us-gov-east-1.amazonaws.com";
WriteGetObjectResponseRequest request = WriteGetObjectResponseRequest.builder().requestRoute(requestRoute).build();
verifyObjectLambdaEndpoint("https", request, region, null, URI.create("https://" + expectedHost), S3Configuration.builder());
verifyObjectLambdaEndpoint("http", request, region, null, URI.create("http://" + expectedHost), S3Configuration.builder());
}
use of com.amazonaws.services.s3.model.WriteGetObjectResponseRequest in project aws-sdk-java-v2 by aws.
the class S3ObjectLambdaOperationEndpointResolverTest method verifyObjectLambdaEndpoint.
private void verifyObjectLambdaEndpoint(String protocol, S3Request request, String region, URI endpointOverride, URI expectedEndpoint, S3Configuration.Builder serviceConfigurationBuilder) {
URI defaultRequestEndpoint = ServiceMetadata.of("s3").endpointFor(Region.of(region));
String prefix = "";
if (request instanceof WriteGetObjectResponseRequest) {
prefix = ((WriteGetObjectResponseRequest) request).requestRoute() + ".";
}
defaultRequestEndpoint = URI.create(protocol + "://" + prefix + defaultRequestEndpoint.toString());
SdkHttpRequest httpRequest;
if (endpointOverride != null) {
endpointOverride = URI.create(protocol + "://" + prefix + endpointOverride.getHost());
httpRequest = InterceptorTestUtils.sdkHttpRequest(endpointOverride);
} else {
httpRequest = InterceptorTestUtils.sdkHttpRequest(defaultRequestEndpoint);
}
S3EndpointResolverContext context = S3EndpointResolverContext.builder().endpointOverride(endpointOverride).originalRequest(request).region(Region.of(region)).serviceConfiguration(serviceConfigurationBuilder.build()).request(httpRequest).build();
ConfiguredS3SdkHttpRequest configuredS3SdkHttpRequest = endpointResolver.applyEndpointConfiguration(context);
assertThat(configuredS3SdkHttpRequest.signingServiceModification().get()).isEqualTo("s3-object-lambda");
assertThat(configuredS3SdkHttpRequest.signingRegionModification()).isEmpty();
assertThat(configuredS3SdkHttpRequest.sdkHttpRequest().getUri()).isEqualTo(expectedEndpoint);
}
Aggregations