Search in sources :

Example 1 with S3RequestError

use of com.example.s3objectlambda.error.S3RequestError 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()));
}
Also used : WriteGetObjectResponseRequest(com.amazonaws.services.s3.model.WriteGetObjectResponseRequest) S3RequestError(com.example.s3objectlambda.error.S3RequestError) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLErrorParser(com.example.s3objectlambda.error.XMLErrorParser) SAXException(org.xml.sax.SAXException)

Aggregations

WriteGetObjectResponseRequest (com.amazonaws.services.s3.model.WriteGetObjectResponseRequest)1 S3RequestError (com.example.s3objectlambda.error.S3RequestError)1 XMLErrorParser (com.example.s3objectlambda.error.XMLErrorParser)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXException (org.xml.sax.SAXException)1