Interface SnsMessageManager
- All Superinterfaces:
AutoCloseable,SdkAutoCloseable
- All Known Implementing Classes:
DefaultSnsMessageManager
builder().
This manager provides automatic validation of SNS message signatures received via HTTP/HTTPS endpoints, ensuring that messages originate from Amazon SNS and have not been modified during transmission. It supports both SignatureVersion1 (SHA1) and SignatureVersion2 (SHA256) as per AWS SNS standards.
The manager handles certificate retrieval, caching, and validation automatically, supporting different AWS regions and partitions (aws, aws-gov, aws-cn).
Basic usage with default configuration:
SnsMessageManager messageManager = SnsMessageManager.builder().build();
try {
SnsMessage validatedMessage = messageManager.parseMessage(messageBody);
String messageContent = validatedMessage.message();
String topicArn = validatedMessage.topicArn();
// Process the validated message
} catch (SdkClientException e) {
// Handle validation failure
logger.error("SNS message validation failed: {}", e.getMessage());
}
Advanced usage with custom HTTP client:
SnsMessageManager messageManager = SnsMessageManager.builder()
.httpClient(ApacheHttpClient.create())
.build();
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic SnsMessageManager.Builderbuilder()Creates a builder for configuring and creating anSnsMessageManager.voidclose()Close thisSnsMessageManager, releasing any resources it owned.parseMessage(InputStream messageStream) Parses and validates an SNS message from a stream.parseMessage(String messageContent) Parses and validates an SNS message from a string.
-
Method Details
-
builder
Creates a builder for configuring and creating anSnsMessageManager.- Returns:
- A new builder.
-
parseMessage
Parses and validates an SNS message from a stream.This method reads the JSON message payload, validates the signature, returns a parsed SNS message object with all message attributes if validation succeeds.
- Parameters:
messageStream- The binary stream representation of the SNS message.- Returns:
- The parsed SNS message.
-
parseMessage
Parses and validates an SNS message from a string.This method reads the JSON message payload, validates the signature, returns a parsed SNS message object with all message attributes if validation succeeds.
- Parameters:
messageContent- The string representation of the SNS message.- Returns:
- the parsed SNS message.
-
close
void close()Close thisSnsMessageManager, releasing any resources it owned.Note: if you provided your own
SdkHttpClient, you must close it separately.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSdkAutoCloseable
-