Authored by 鲁尚清

Merge branch 'master' of http://192.168.1.136:82/monitor_v3/anji-plus-report int…

…o master-ajreport-lushangqing
... ... @@ -296,14 +296,19 @@ public class DataSourceServiceImpl implements DataSourceService {
*/
public List<JSONObject> executeHttp(DataSourceDto dto) {
analysisHttpConfig(dto);
String apiUrl = dto.getApiUrl();
HttpMethod httpMethod = HttpMethod.valueOf(dto.getMethod());
if(Objects.equals(HttpMethod.GET, httpMethod)){
Map<String, Object> contextData = dto.getContextData();
if(!contextData.isEmpty()){
JSONObject o = (JSONObject)JSONObject.toJSON(contextData);
dto.setDynSentence(o.toJSONString());
List<String> params = new ArrayList<>();
contextData.forEach((k,v)->{
params.add(String.format("%s=%s",k,String.valueOf(v)));
});
String element = "&";
if(apiUrl.indexOf('?') == -1){
element = "?";
}
apiUrl += element + String.join("&",params);
}
HttpHeaders headers = new HttpHeaders();
headers.setAll(JSONObject.parseObject(dto.getHeader(), Map.class));
... ... @@ -311,7 +316,7 @@ public class DataSourceServiceImpl implements DataSourceService {
ResponseEntity<Object> exchange;
List<JSONObject> result = new ArrayList<>();
try {
exchange = restTemplate.exchange(dto.getApiUrl(),httpMethod , entity, Object.class);
exchange = restTemplate.exchange(apiUrl,httpMethod , entity, Object.class);
} catch (HttpClientErrorException error){
int rawStatusCode = error.getRawStatusCode();
// 401 接口请求无权限
... ...