Authored by chunhua.zhang

验证DNS的时候,支持传入HOST

... ... @@ -31,6 +31,8 @@ public class DNSConfig {
/**
* 初始化域名配置
*
* dns.config.url=api.yoho.cn/?method=app.resources.config.clientInitConfig&client_secret=bf8f49754dc7058349146f922640000c&client_type=android;service.yoho.cn/?method=app.resources.config.clientInitConfig&client_secret=bf8f49754dc7058349146f922640000c&client_type=android
*
* @param url 在配置文件中的格式为: host1/service1;host2/service2...
*/
public DNSConfig(String url, String dnsApiUrl) {
... ...
... ... @@ -11,6 +11,15 @@ public interface IRestTemplateNoEncode {
String doGet(final String uri);
/**
*  传入HOST
* @param uri
* @param host
* @return
*/
String doGet(final String uri, String host);
String doGetResponseCode(final String uri);
}
... ...
... ... @@ -280,7 +280,7 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService {
//检测该ip是否返回预期网页
String response = restTemplateNoEncode.doGet(
InterVar.HTTPS + ip + dnsConfig.getServices().get(host));
InterVar.HTTPS + ip + dnsConfig.getServices().get(host), host);
//验证返回网页是否正确 如果不含有该字符串则返回结果错误
if (-1 == response.indexOf(InterVar.M_YOHOBUY_COM_RESPONSE_PATTEN) || null == response) {
... ...
package com.monitor.other.dns.service.impl;
import org.springframework.http.HttpHeaders;
import com.google.common.collect.Lists;
import org.springframework.http.*;
import com.monitor.other.dns.service.IRestTemplateNoEncode;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
... ... @@ -14,8 +15,6 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.TrustStrategy;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
... ... @@ -36,6 +35,8 @@ import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Map;
import static java.util.Collections.singletonList;
/**
* Created by yoho on 2016/8/2.
*/
... ... @@ -151,6 +152,22 @@ public class RestTemplateNoEncodeImpl implements IRestTemplateNoEncode{
}
@Override
public String doGet(String uri, String host) {
HttpHeaders headers = new HttpHeaders();
headers.set("Host", host);
HttpEntity entity = new HttpEntity(headers);
String result = null;
try {
result = restTemplate.exchange(uri,HttpMethod.GET,entity,String.class).getBody();
} catch (Exception e) {
logger.error("doGet failed!", e);
}
return result;
}
@Override
public String doGetResponseCode(String uri) {
String result = null;
try {
... ...