Authored by chunhua.zhang

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

@@ -31,6 +31,8 @@ public class DNSConfig { @@ -31,6 +31,8 @@ public class DNSConfig {
31 /** 31 /**
32 * 初始化域名配置 32 * 初始化域名配置
33 * 33 *
  34 + * 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
  35 + *
34 * @param url 在配置文件中的格式为: host1/service1;host2/service2... 36 * @param url 在配置文件中的格式为: host1/service1;host2/service2...
35 */ 37 */
36 public DNSConfig(String url, String dnsApiUrl) { 38 public DNSConfig(String url, String dnsApiUrl) {
@@ -11,6 +11,15 @@ public interface IRestTemplateNoEncode { @@ -11,6 +11,15 @@ public interface IRestTemplateNoEncode {
11 11
12 String doGet(final String uri); 12 String doGet(final String uri);
13 13
  14 + /**
  15 + *  传入HOST
  16 + * @param uri
  17 + * @param host
  18 + * @return
  19 + */
  20 + String doGet(final String uri, String host);
  21 +
  22 +
14 String doGetResponseCode(final String uri); 23 String doGetResponseCode(final String uri);
15 24
16 } 25 }
@@ -280,7 +280,7 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService { @@ -280,7 +280,7 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService {
280 280
281 //检测该ip是否返回预期网页 281 //检测该ip是否返回预期网页
282 String response = restTemplateNoEncode.doGet( 282 String response = restTemplateNoEncode.doGet(
283 - InterVar.HTTPS + ip + dnsConfig.getServices().get(host)); 283 + InterVar.HTTPS + ip + dnsConfig.getServices().get(host), host);
284 284
285 //验证返回网页是否正确 如果不含有该字符串则返回结果错误 285 //验证返回网页是否正确 如果不含有该字符串则返回结果错误
286 if (-1 == response.indexOf(InterVar.M_YOHOBUY_COM_RESPONSE_PATTEN) || null == response) { 286 if (-1 == response.indexOf(InterVar.M_YOHOBUY_COM_RESPONSE_PATTEN) || null == response) {
1 package com.monitor.other.dns.service.impl; 1 package com.monitor.other.dns.service.impl;
2 2
3 -import org.springframework.http.HttpHeaders; 3 +import com.google.common.collect.Lists;
  4 +import org.springframework.http.*;
4 import com.monitor.other.dns.service.IRestTemplateNoEncode; 5 import com.monitor.other.dns.service.IRestTemplateNoEncode;
5 import org.apache.http.config.Registry; 6 import org.apache.http.config.Registry;
6 import org.apache.http.config.RegistryBuilder; 7 import org.apache.http.config.RegistryBuilder;
@@ -14,8 +15,6 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; @@ -14,8 +15,6 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
14 import org.apache.http.ssl.SSLContextBuilder; 15 import org.apache.http.ssl.SSLContextBuilder;
15 import org.apache.http.ssl.TrustStrategy; 16 import org.apache.http.ssl.TrustStrategy;
16 import org.slf4j.LoggerFactory; 17 import org.slf4j.LoggerFactory;
17 -import org.springframework.http.HttpMethod;  
18 -import org.springframework.http.ResponseEntity;  
19 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; 18 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
20 import org.springframework.stereotype.Service; 19 import org.springframework.stereotype.Service;
21 import org.springframework.web.client.RestTemplate; 20 import org.springframework.web.client.RestTemplate;
@@ -36,6 +35,8 @@ import java.security.cert.CertificateException; @@ -36,6 +35,8 @@ import java.security.cert.CertificateException;
36 import java.security.cert.X509Certificate; 35 import java.security.cert.X509Certificate;
37 import java.util.Map; 36 import java.util.Map;
38 37
  38 +import static java.util.Collections.singletonList;
  39 +
39 /** 40 /**
40 * Created by yoho on 2016/8/2. 41 * Created by yoho on 2016/8/2.
41 */ 42 */
@@ -151,6 +152,22 @@ public class RestTemplateNoEncodeImpl implements IRestTemplateNoEncode{ @@ -151,6 +152,22 @@ public class RestTemplateNoEncodeImpl implements IRestTemplateNoEncode{
151 } 152 }
152 153
153 @Override 154 @Override
  155 + public String doGet(String uri, String host) {
  156 +
  157 + HttpHeaders headers = new HttpHeaders();
  158 + headers.set("Host", host);
  159 + HttpEntity entity = new HttpEntity(headers);
  160 +
  161 + String result = null;
  162 + try {
  163 + result = restTemplate.exchange(uri,HttpMethod.GET,entity,String.class).getBody();
  164 + } catch (Exception e) {
  165 + logger.error("doGet failed!", e);
  166 + }
  167 + return result;
  168 + }
  169 +
  170 + @Override
154 public String doGetResponseCode(String uri) { 171 public String doGetResponseCode(String uri) {
155 String result = null; 172 String result = null;
156 try { 173 try {