Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring aws-cloud SNS http end point confirm subscription not working

In my spring boot aws-cloud SNS http end point confirm subscription is not working. When SNS confirmation comes following error coming in my application. Error :

[Request processing failed; nested exception is java.lang.IllegalArgumentException: Invoked method public abstract void org.springframework.cloud.aws.messaging.endpoint.NotificationStatus.confirmSubscription() is no accessor method!] with root cause
    java.lang.IllegalArgumentException: Invoked method public abstract void org.springframework.cloud.aws.messaging.endpoint.NotificationStatus.confirmSubscription() is no accessor method!
        at org.springframework.util.Assert.notNull(Assert.java:115) ~[spring-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
        at org.spring

My controller handler is :

     @NotificationSubscriptionMapping
        public void handleSubscriptionMessage( NotificationStatus status)   throws IOException {
            //Confirming SNS subscription
            status.confirmSubscription();
        }

My Pom contains following :

     <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-aws-messaging</artifactId>
          <version>1.0.4.RELEASE</version>
        </dependency>

        <!-- For Spring AWS autoconfiguration-->
        <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-aws-autoconfigure</artifactId>
          <version>1.0.4.RELEASE</version>
        </dependency>

I followed the explanation in this link

like image 762
Bill Goldberg Avatar asked Mar 16 '16 15:03

Bill Goldberg


People also ask

How do I confirm my subscription on SQS?

To confirm the subscription, you can use the Amazon SQS console or the ReceiveMessage action. Before you subscribe an endpoint to the topic, make sure that the queue can receive messages from the topic by setting the sqs:SendMessage permission for the queue.

What is SNS confirmation?

Usually, this means creating and deploying a web application (for example, a Java servlet if your endpoint host is running Linux with Apache and Tomcat) that processes the HTTP requests from Amazon SNS. When you subscribe an HTTP endpoint, Amazon SNS sends it a subscription confirmation request.

What is SNS endpoint?

Simple Notification Service – SNS is a web service that coordinates and manages the delivery or sending of messages to subscribing endpoints or clients. SNS provides the ability to create Topic which is a logical access point and communication channel.


2 Answers

Did you specify the custom resolver:

<mvc:annotation-driven>
    <mvc:argument-resolvers>
        <ref bean="notificationResolver" />
    </mvc:argument-resolvers>
</mvc:annotation-driven>

<aws-messaging:notification-argument-resolver id="notificationResolver" />

Also, I cannot see the controller mapping, but in tutorial there is a statement:

Currently it is not possible to define the mapping URL on the method level therefore the RequestMapping must be done at type level and must contain the full path of the endpoint.

like image 183
m.aibin Avatar answered Nov 01 '22 15:11

m.aibin


Putting this out for anyone who is after java config for this. Please note you have to use NotificationMessageHandlerMethodArgumentResolver which implements HandlerMethodArgumentResolver.

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.aws.messaging.endpoint.NotificationMessageHandlerMethodArgumentResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@EnableWebMvc
public class MvcConfig extends WebMvcConfigurerAdapter {

    @Autowired
    private NotificationMessageHandlerMethodArgumentResolver notificationResolver;

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(notificationMessageHandlerMethodArgumentResolver());
    }

    @Bean
    public NotificationMessageHandlerMethodArgumentResolver notificationMessageHandlerMethodArgumentResolver () {

        return new NotificationMessageHandlerMethodArgumentResolver();
    };

}
like image 41
Charith De Silva Avatar answered Nov 01 '22 15:11

Charith De Silva