Search in sources :

Example 1 with Checksum

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

Aggregations

ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 WriteGetObjectResponseRequest (com.amazonaws.services.s3.model.WriteGetObjectResponseRequest)1 Checksum (com.example.s3objectlambda.checksum.Checksum)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXException (org.xml.sax.SAXException)1