Authored by xuhui

订阅 Amazon SNS 主题

package com.ui.model.req;
import lombok.Data;
/**
* Created by hui.xu on 2017/5/2.
*/
@Data
public class AwsSnsReq {
private String Type;
private String MessageId;
private String Token;
private String TopicArn;
private String Message;
private String SubscribeURL;
private String Timestamp;
private String SignatureVersion;
private String Signature;
private String SigningCertURL;
}
\ No newline at end of file
... ...
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);
}
}
}
\ No newline at end of file
... ...
... ... @@ -85,6 +85,7 @@
<mvc:exclude-mapping path="/deliverMessagetxt/**"/>
<mvc:exclude-mapping path="/systemTest/**"/>
<mvc:exclude-mapping path="/recvMonitAlarm"/>
<mvc:exclude-mapping path="/api/aws/sns" />
<bean class="com.ui.interceptor.AuthInterceptor"/>
</mvc:interceptor>
... ...