Getting AmazonSNSException: End of list found where not expected error

Viewed 23

I'm always getting the error Caused by: com.amazonaws.services.sns.model.AmazonSNSException: End of list found where not expected (Service: AmazonSNS; Status Code: 400; Error Code: MalformedInput; Request ID: xxxx-a43f3b606664; Proxy: null) when I'm trying to publish the messages to sns topic. I tried both approaches, with & without message structure field. Kindly help

 private final ObjectMapper objectMapper;

    private final AmazonSNS sns;

    private final String topicArn;

    public XXXEventDispatcher(ObjectMapper objectMapper, Properties properties) {
        this.sns = AmazonSNSClientBuilder.standard()
                .withCredentials(
                        new AWSStaticCredentialsProvider(
                                new BasicAWSCredentials(properties.getProperty("aws.access.key"), properties.getProperty("aws.secret.key"))
                        )
                )
                .build();
        this.topicArn = properties.getProperty("xxx.topic.arn");
        this.objectMapper = objectMapper;
}


public void sendMessage(Map<String, String> attributes, AbstractXXXEvent event) {
        try {
            String result = String.format("{\"default\": \"%s\"}", objectMapper.writeValueAsString(event));

            PublishRequest request = new PublishRequest()
                    .withTopicArn(topicArn)
                    .addMessageAttributesEntry(SERVICE_INSTANCE_ID, new MessageAttributeValue()
                            .withStringValue(attributes.get(SERVICE_INSTANCE_ID)))
                    .withMessageStructure("json")
                    .withMessage(result);
            this.sns.publish(request);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
0 Answers
Related