AwsSnsController.java
2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.ui.ctrl;
import com.ui.model.req.AwsSnsReq;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;
import javax.servlet.http.HttpServletRequest;
/**
* Created by hui.xu on 2017/5/2.
* 亚马逊云订阅
*/
@Controller
@RequestMapping("api")
public class AwsSnsController {
/**
* 日志接口
*/
private Logger logger = LoggerFactory.getLogger(getClass());
private static final String AWS_SNS_HEAD_TYPE = "x-amz-sns-message-type";
private static final String NEED_TO_DEAL_WITH_TYPE = "SubscriptionConfirmation";
@Autowired
private RestTemplate restTemplate;
/**
* 处理亚马逊订阅消息
*
* @param request 用于获取请求头
* @param req 用户获取请求json对象
*/
@RequestMapping(value = "/aws/sns")
public void awsSns(HttpServletRequest request, @RequestBody AwsSnsReq req) {
try {
logger.info(" - awsSns - request -");
String headMessageType = request.getHeader(AWS_SNS_HEAD_TYPE);
logger.info(" - AwsSnsController - awsSns - header:" + headMessageType);
if (!StringUtils.equals(NEED_TO_DEAL_WITH_TYPE, headMessageType)) {
return;
}
if (req == null) {
logger.error(" - AwsSnsController - awsSns - json is emtry");
return;
}
String subscribeURL = req.getSubscribeURL();
if (StringUtils.isBlank(subscribeURL)) {
logger.error(" - AwsSnsController - awsSns - subscribeURL is emtry");
return;
}
logger.info(" - AwsSnsController - awsSns - subscribeURL is:" + subscribeURL);
//请求当前返回的Url
restTemplate.getForObject(subscribeURL, String.class);
logger.info(" - request - " + subscribeURL + " - success");
} catch (Exception e) {
logger.error(" - AwsSnsController - awsSns - error", e);
}
}
}