private static void receiveMessageResultMd5Check ( ReceiveMessageResult receiveMessageResult ) { if ( receiveMessageResult . getMessages ( ) != null ) { for ( Message messageReceived : receiveMessageResult . getMessages ( ) ) { String messageBody = messageReceived . getBody ( ) ; String bodyMd5Returned = messageReceived . getMD5OfBody ( ) ; String clientSideBodyMd5 = calculateMessageBodyMd5 ( messageBody ) ; if ( ! clientSideBodyMd5 . equals ( bodyMd5Returned ) ) { throw new AmazonClientException ( String . format ( MD5_MISMATCH_ERROR_MESSAGE , MESSAGE_BODY , clientSideBodyMd5 , bodyMd5Returned ) ) ; } Map < String , MessageAttributeValue > messageAttr = messageReceived . getMessageAttributes ( ) ; if ( messageAttr != null && ! messageAttr . isEmpty ( ) ) { String attrMd5Returned = messageReceived . getMD5OfMessageAttributes ( ) ; String clientSideAttrMd5 = calculateMessageAttributesMd5 ( messageAttr ) ; if ( ! clientSideAttrMd5 . equals ( attrMd5Returned ) ) { throw new AmazonClientException ( String . format ( MD5_MISMATCH_ERROR_MESSAGE , MESSAGE_ATTRIBUTES , clientSideAttrMd5 , attrMd5Returned ) ) ; } } } } }
Throw an exception if the MD5 checksums included in the ReceiveMessageResult do not match the client - side calculation on the received messages .