Authored by qinchao

提供接口

package com.ui.http;
import com.alibaba.fastjson.JSONObject;
import com.ui.config.SystemConfig;
import com.ui.model.BaseResponse;
import com.ui.model.req.User;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public class HttpRestClient {
... ... @@ -45,6 +30,19 @@ public class HttpRestClient {
}
}
public <T> T defaultPostJson(String uri, String requestJson,Class<T> responseType) {
try {
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
headers.setContentType(type);
HttpEntity<String> entity = new HttpEntity<String>(requestJson,headers);
return restTemplate.postForObject(systemConfig.getServiceUrl() + uri, entity, responseType);
} catch (Exception e) {
logger.error("postForObject failed!url:"+uri, e);
return null;
}
}
public <T> T defaultGet(String uri, Class<T> responseType,Map<String, ?> map) {
try {
StringBuilder url = new StringBuilder(uri);
... ...
... ... @@ -69,8 +69,7 @@ public class OuterIntfCtrl {
@RequestMapping("/writeMipsObjToOpsReids")
@ResponseBody
public void writeMipsObjToOpsReids(@RequestBody String ipsObjs) {
//httpClient..defaultPost()
httpClient.defaultPostJson("maliciousIp/writeMipsObjToOpsReids",ipsObjs,String.class);
}
/**
... ... @@ -81,7 +80,7 @@ public class OuterIntfCtrl {
@RequestMapping("/writeMipsInfoToOpsDb")
@ResponseBody
public void writeMipsInfoToOpsDb(@RequestBody String ipsObjs) {
httpClient.defaultPostJson("maliciousIp/writeMipsInfoToOpsDb",ipsObjs,String.class);
}
}
... ...
... ... @@ -87,6 +87,7 @@
<mvc:exclude-mapping path="/recvMonitAlarm"/>
<mvc:exclude-mapping path="/awsapi/sns" />
<mvc:exclude-mapping path="/testcommon/testUpLoadData" />
<mvc:exclude-mapping path="/outer/*" />
<bean class="com.ui.interceptor.AuthInterceptor"/>
</mvc:interceptor>
... ...
monitor.service.url=http://java-monitor-service:8080/monitor
monitor.service.url=http://java-monitor-service:8080/monitor/
search.aws.url=http://192.168.102.216:8080/
search.qq.url=http://192.168.102.224:8080/
search.filePath=D:/Data/productList.txt
\ No newline at end of file
... ...