1 /*
2  * Copyright 2013-2019 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.cloud.aws.messaging.support;
18
19 import org.springframework.cloud.aws.messaging.config.annotation.NotificationMessage;
20 import org.springframework.cloud.aws.messaging.support.converter.NotificationRequestConverter;
21 import org.springframework.core.MethodParameter;
22 import org.springframework.messaging.Message;
23 import org.springframework.messaging.converter.MessageConverter;
24 import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver;
25
26 /**
27  * @author Alain Sahli
28  */

29 public class NotificationMessageArgumentResolver
30         implements HandlerMethodArgumentResolver {
31
32     private final MessageConverter converter;
33
34     public NotificationMessageArgumentResolver(MessageConverter converter) {
35         this.converter = new NotificationRequestConverter(converter);
36     }
37
38     @Override
39     public boolean supportsParameter(MethodParameter parameter) {
40         return parameter.hasParameterAnnotation(NotificationMessage.class);
41     }
42
43     @Override
44     public Object resolveArgument(MethodParameter par, Message<?> msg) throws Exception {
45         Object object = this.converter.fromMessage(msg, par.getParameterType());
46         NotificationRequestConverter.NotificationRequest nr = (NotificationRequestConverter.NotificationRequest) object;
47         return nr.getMessage();
48     }
49
50 }
51