AwsController.java
2.54 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
67
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;
import java.util.Enumeration;
/**
* Created by hui.xu on 2017/5/2.
*/
@Controller
@RequestMapping("awsapi")
public class AwsController {
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
*/
@RequestMapping(value = "/sns")
public void awsSns(HttpServletRequest request, @RequestBody AwsSnsReq req) {
try {
logger.info(" - AwsController - awsSns - request -");
String headMessageType = request.getHeader(AWS_SNS_HEAD_TYPE);
Enumeration<String> em = request.getHeaderNames();
while (em.hasMoreElements()) {
String headName = String.valueOf(em.nextElement());
String headValue = request.getHeader(headName);
logger.info(String.format(" - AwsController - awsSns - header=%s - value=%s", headName, headValue));
}
if (StringUtils.equals(NEED_TO_DEAL_WITH_TYPE, headMessageType)) {
if (req == null) {
logger.error(" - AwsController - awsSns - json is emtry");
return;
}
String subscribeURL = req.getSubscribeURL();
if (StringUtils.isBlank(subscribeURL)) {
logger.error(" - AwsController - awsSns - subscribeURL is emtry");
return;
}
logger.info(" - AwsController - awsSns - subscribeURL is:" + subscribeURL);
restTemplate.getForObject(subscribeURL, String.class);
logger.info(" - request - " + subscribeURL + " - success");
}else{
logger.info(" - AwsController - awsSns - message is:" + req.toString());
}
} catch (Exception e) {
logger.error(" - AwsController - awsSns - error", e);
}
}
}