Authored by qinchao

删除恶意ip时携带header

... ... @@ -12,5 +12,5 @@ public interface HttpRestClientService {
public <T> T get(String path, Map request, Class<T> responseType);
public <T> T getWithHost(String path, Map request, Class<T> responseType);
public <T> T getWithHeaderHost(String path, Map request, Class<T> responseType);
}
... ...
... ... @@ -112,14 +112,14 @@ public class HttpRestClientServiceImpl implements HttpRestClientService {
@Override
public <T> T getWithHost(String path, Map request, Class<T> responseType) {
public <T> T getWithHeaderHost(String path, Map request, Class<T> responseType) {
logger.debug("begin to do http get host. path:{}, request params:{}", path, request);
//add accept json
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
headers.set("Host","erp.yoho.yohoops.org");
// headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
headers.set("Host", "erp.yoho.yohoops.org");
HttpEntity<?> entity = new HttpEntity<>(headers);
//url
... ... @@ -136,13 +136,14 @@ public class HttpRestClientServiceImpl implements HttpRestClientService {
}
final URI getURI = builder.build().encode().toUri();
logger.debug("begin to do http get host. url:{}", getURI);
try {
HttpEntity<T> response = restTemplate.exchange(getURI, HttpMethod.GET, entity, responseType);
logger.debug("end to do http get. path:{}, request params:{}. response body: {}", path, request, response.getBody());
return response.getBody();
} catch (Exception e) {
logger.error("doPostStringJson failed!url:"+path, e);
logger.error("getWithHeaderHost failed!url:"+path, e);
return null;
}
}
... ...
... ... @@ -83,7 +83,7 @@ public class MaliciousIpController {
String[] ports=maliciousRedisPorts.split(",");
for(int i=0;i<hosts.length;i++){
String url="http://"+hosts[i]+":"+ports[i]+"/malIp?method=del&ips=";
String removeReturnMsg = httpRestClientService.getWithHost(url+ip, null, String.class);
String removeReturnMsg = httpRestClientService.getWithHeaderHost(url + ip, null, String.class);
if(StringUtils.isBlank(removeReturnMsg)){
return new BaseResponse(201,"删除恶意ip返回结果为空,删除出现异常,主机:"+hosts[i]);
}
... ...