...
|
...
|
@@ -38,32 +38,47 @@ public class WapUrlAlarm |
|
|
@Resource(name = "javaapiRestTemplate")
|
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
private int maxTime=5;
|
|
|
/**
|
|
|
* 十分钟监控一次
|
|
|
* 失败到 maxTime 才报警
|
|
|
*/
|
|
|
@Scheduled(cron = "0 2/10 * * * ?")
|
|
|
public void alarm() {
|
|
|
//发送拦截短信
|
|
|
String mobile_user = getUsersInfoUtil.getMobileByAlarmGroup(AlarmGroupContants.GROUP_NAME_USER_LOGIN);
|
|
|
try {
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(WATCH_URL);
|
|
|
//WATCH_URL 包含了特殊字符,但不需要编码转义:build(true)
|
|
|
URI uri = builder.build(true).encode().toUri();
|
|
|
// String alarmData = restTemplate.getForObject(uri, String.class);
|
|
|
for(int i=1;i<=maxTime;i++){
|
|
|
//发送拦截短信
|
|
|
String mobile_user = getUsersInfoUtil.getMobileByAlarmGroup(AlarmGroupContants.GROUP_NAME_USER_LOGIN);
|
|
|
try {
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(WATCH_URL);
|
|
|
//WATCH_URL 包含了特殊字符,但不需要编码转义:build(true)
|
|
|
URI uri = builder.build(true).encode().toUri();
|
|
|
// String alarmData = restTemplate.getForObject(uri, String.class);
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.add("Content-Type", "text/html");
|
|
|
headers.add("Cache-Control", "max-age=0");
|
|
|
HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
|
|
|
ResponseEntity<String> responseEntity = restTemplate.exchange(uri, HttpMethod.GET, requestEntity, String.class);
|
|
|
HttpStatus status = responseEntity.getStatusCode();
|
|
|
if (200!=status.value()){
|
|
|
alarm("联盟跳转页面访问异常url="+WATCH_URL+",code="+status.value(),mobile_user);
|
|
|
}
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.add("Content-Type", "text/html");
|
|
|
headers.add("Cache-Control", "max-age=0");
|
|
|
HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
|
|
|
ResponseEntity<String> responseEntity = restTemplate.exchange(uri, HttpMethod.GET, requestEntity, String.class);
|
|
|
HttpStatus status = responseEntity.getStatusCode();
|
|
|
if (200!=status.value()){
|
|
|
alarm("联盟跳转页面访问异常url="+WATCH_URL+",code="+status.value(),mobile_user);
|
|
|
}
|
|
|
//如果正常了,则跳出循环
|
|
|
break;
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
i++;
|
|
|
logger.error("WapUrlAlarm watchurl 联盟跳转 第"+i+"次 error",e);
|
|
|
if(i==maxTime){
|
|
|
alarm("联盟跳转页面访问异常url="+WATCH_URL+",探测异常访问超时",mobile_user);
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
logger.error("WapUrlAlarm watchurl 联盟跳转 error",e);
|
|
|
alarm("联盟跳转页面访问异常url="+WATCH_URL+",探测异常访问超时",mobile_user);
|
|
|
try{
|
|
|
Thread.sleep(1000);//等1秒再试
|
|
|
}catch (Exception ee){
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
...
|
...
|
|