Showing
3 changed files
with
40 additions
and
3 deletions
@@ -12,4 +12,5 @@ public interface HttpRestClientService { | @@ -12,4 +12,5 @@ public interface HttpRestClientService { | ||
12 | 12 | ||
13 | public <T> T get(String path, Map request, Class<T> responseType); | 13 | public <T> T get(String path, Map request, Class<T> responseType); |
14 | 14 | ||
15 | + public <T> T getWithHost(String path, Map request, Class<T> responseType); | ||
15 | } | 16 | } |
@@ -110,4 +110,40 @@ public class HttpRestClientServiceImpl implements HttpRestClientService { | @@ -110,4 +110,40 @@ public class HttpRestClientServiceImpl implements HttpRestClientService { | ||
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | + | ||
114 | + @Override | ||
115 | + public <T> T getWithHost(String path, Map request, Class<T> responseType) { | ||
116 | + | ||
117 | + logger.debug("begin to do http get host. path:{}, request params:{}", path, request); | ||
118 | + | ||
119 | + //add accept json | ||
120 | + HttpHeaders headers = new HttpHeaders(); | ||
121 | + headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); | ||
122 | + headers.set("Host","erp.yoho.yohoops.org"); | ||
123 | + HttpEntity<?> entity = new HttpEntity<>(headers); | ||
124 | + | ||
125 | + //url | ||
126 | + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(path); | ||
127 | + | ||
128 | + //添加参数 | ||
129 | + if(request!=null){ | ||
130 | + Map<String, ?> params = (Map<String, ?>) request; | ||
131 | + if (params != null && params.size() > 0) { | ||
132 | + for (Map.Entry<String, ?> urlParam : params.entrySet()) { | ||
133 | + builder.queryParam(urlParam.getKey(), urlParam.getValue()); | ||
134 | + } | ||
135 | + } | ||
136 | + } | ||
137 | + | ||
138 | + final URI getURI = builder.build().encode().toUri(); | ||
139 | + | ||
140 | + try { | ||
141 | + HttpEntity<T> response = restTemplate.exchange(getURI, HttpMethod.GET, entity, responseType); | ||
142 | + logger.debug("end to do http get. path:{}, request params:{}. response body: {}", path, request, response.getBody()); | ||
143 | + return response.getBody(); | ||
144 | + } catch (Exception e) { | ||
145 | + logger.error("doPostStringJson failed!url:"+path, e); | ||
146 | + return null; | ||
147 | + } | ||
148 | + } | ||
113 | } | 149 | } |
@@ -77,13 +77,13 @@ public class MaliciousIpController { | @@ -77,13 +77,13 @@ public class MaliciousIpController { | ||
77 | public BaseResponse delMipsFromOpsRedis(String ip) { | 77 | public BaseResponse delMipsFromOpsRedis(String ip) { |
78 | if(StringUtils.isNotBlank(ip)){ | 78 | if(StringUtils.isNotBlank(ip)){ |
79 | //获取header信息, | 79 | //获取header信息, |
80 | - HttpHeaders headers = new HttpHeaders(); | ||
81 | - headers.add("Host","erp.yoho.yohoops.org"); | 80 | + /* HttpHeaders headers = new HttpHeaders(); |
81 | + headers.add("Host","erp.yoho.yohoops.org");*/ | ||
82 | String[] hosts=maliciousRedisHosts.split(","); | 82 | String[] hosts=maliciousRedisHosts.split(","); |
83 | String[] ports=maliciousRedisPorts.split(","); | 83 | String[] ports=maliciousRedisPorts.split(","); |
84 | for(int i=0;i<hosts.length;i++){ | 84 | for(int i=0;i<hosts.length;i++){ |
85 | String url="http://"+hosts[i]+":"+ports[i]+"/malIp?method=del&ips="; | 85 | String url="http://"+hosts[i]+":"+ports[i]+"/malIp?method=del&ips="; |
86 | - String removeReturnMsg = httpRestClientService.postForObject(url+ip, new HttpEntity<String>(headers), String.class); | 86 | + String removeReturnMsg = httpRestClientService.getWithHost(url+ip, null, String.class); |
87 | if(StringUtils.isBlank(removeReturnMsg)){ | 87 | if(StringUtils.isBlank(removeReturnMsg)){ |
88 | return new BaseResponse(201,"删除恶意ip返回结果为空,删除出现异常,主机:"+hosts[i]); | 88 | return new BaseResponse(201,"删除恶意ip返回结果为空,删除出现异常,主机:"+hosts[i]); |
89 | } | 89 | } |
-
Please register or login to post a comment