Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NullPointerException caused by s3:TestEvent #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<groupId>org.sherzberg.graylog.plugins</groupId>
<artifactId>graylog-plugin-s3</artifactId>
<version>2.4.1-SNAPSHOT</version>
<version>2.5.0</version>
<packaging>jar</packaging>

<name>${project.artifactId}</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void run() {

String message;
while ((message = reader.readLine()) != null) {
LOG.debug("S3 Event message : {}", message);
S3Record s3Record = new S3Record();
s3Record.s3Bucket = n.getS3Bucket();
s3Record.s3ObjectKey = n.getS3ObjectKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ public String getS3ObjectKey() {
return s3ObjectKey;
}

@Override
public String toString() {
return "S3SNSNotification{" +
"receiptHandle='" + receiptHandle + '\'' +
", s3Bucket='" + s3Bucket + '\'' +
", s3ObjectKey='" + s3ObjectKey + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,33 @@ public S3SNSNotificationParser() {

public List<S3SNSNotification> parse(Message message) {
List<S3SNSNotification> notifications = Lists.newArrayList();
String messageBody = message.getBody();

try {
SQSMessage envelope = om.readValue(message.getBody(), SQSMessage.class);
SQSMessage envelope = om.readValue(messageBody, SQSMessage.class);

if (envelope.message == null) {
return Collections.emptyList();
}

S3EventNotification s3EventNotification = S3EventNotification.parseJson(envelope.message);
List<S3EventNotification.S3EventNotificationRecord> records = s3EventNotification.getRecords();

notifications.addAll(s3EventNotification.getRecords().stream().map(record -> new S3SNSNotification(
if (records == null) {
if (!envelope.message.contains("s3:TestEvent")){
LOG.warn("Consumed SNS notification does not have any record: {}", envelope.message);
}
return Collections.emptyList();
}

notifications.addAll(records.stream().map(record -> new S3SNSNotification(
message.getReceiptHandle(),
record.getS3().getBucket().getName(),
record.getS3().getObject().getUrlDecodedKey()
)).collect(Collectors.toList()));
} catch (Exception e) {
LOG.error("Could not parse SNS notification: " + message.getBody(), e);
throw new RuntimeException("Could not parse SNS notification: " + message.getBody(), e);
LOG.error("Could not parse SNS notification: " + messageBody, e);
throw new RuntimeException("Could not parse SNS notification: " + messageBody, e);
}

return notifications;
Expand Down