|
|
@ -276,53 +276,85 @@ public class EXAUtils { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public List<Object> getGroup(String EXA_IP) throws URISyntaxException, IOException { |
|
|
|
|
|
List<Object> result = new ArrayList<>(); |
|
|
|
|
|
try { |
|
|
|
|
|
// 目标 RPC 服务的 URL
|
|
|
|
|
|
String url = "http://" + EXA_IP + ":9000/exawebapi/exagroup/getgroups"; |
|
|
|
|
|
//创建HttpClient对象
|
|
|
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault(); |
|
|
|
|
|
/* |
|
|
|
|
|
* 由于GET请求的参数都是拼装在URL地址后方,所以我们要构建一个URL,带参数 |
|
|
|
|
|
*/ |
|
|
|
|
|
URIBuilder uriBuilder = new URIBuilder(url); |
|
|
|
|
|
|
|
|
|
|
|
/** 添加参数 */ |
|
|
|
|
|
// uriBuilder.addParameter("ItemNames", itemNames);
|
|
|
|
|
|
|
|
|
|
|
|
//创建请求对象
|
|
|
public List<List<String>> getGroup(String EXA_IP) throws IOException { |
|
|
HttpGet httpGet = new HttpGet(uriBuilder.build()); |
|
|
String requestPathAddItem = "http://" + EXA_IP + ":9000/exawebapi/EXAItem/GetAllGroups"; |
|
|
|
|
|
String result = Request.Post(requestPathAddItem) |
|
|
|
|
|
.addHeader("Content-type", "application/json") |
|
|
|
|
|
.execute().returnContent().asString(Charset.forName("utf-8")); |
|
|
|
|
|
// Add validation for empty or null response
|
|
|
|
|
|
if (result == null || result.isEmpty()) { |
|
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 传输的类型
|
|
|
try { |
|
|
httpGet.addHeader("Content-Type", "application/json"); |
|
|
// Handle potential escaped quotes in response
|
|
|
//发送请求,请求响应结果
|
|
|
if (result.startsWith("\"") && result.endsWith("\"")) { |
|
|
CloseableHttpResponse response = httpClient.execute(httpGet); |
|
|
result = result.substring(1, result.length() - 1).replace("\\\"", "\"").replace("\\\\", "\\"); |
|
|
//获取服务器返回的状态码
|
|
|
|
|
|
int statusCode = response.getStatusLine().getStatusCode(); |
|
|
|
|
|
System.out.println("服务端返回成功的状态码为:" + statusCode); |
|
|
|
|
|
HttpEntity entity = response.getEntity(); |
|
|
|
|
|
String body = EntityUtils.toString(entity).replaceAll("\\\\", ""); |
|
|
|
|
|
System.out.println("服务端返回的数据为:" + body); |
|
|
|
|
|
if (body.startsWith("\"") && body.endsWith("\"")) { |
|
|
|
|
|
// 步骤3:去掉双引号
|
|
|
|
|
|
body = body.substring(1, body.length() - 1); // 去掉首尾的双引号
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create(); |
|
|
EXAGroupRespVO vo = JSON.parseObject(result, EXAGroupRespVO.class); |
|
|
Type listType = new TypeToken<List<Object>>() { |
|
|
List<List<String>> jsonResult = new ArrayList<>(); |
|
|
}.getType(); |
|
|
if(vo.getReturnValue().equals(1L)){ |
|
|
result = gson.fromJson(body, listType); |
|
|
jsonResult = JSON.parseObject(vo.getGroupsJson(), new com.alibaba.fastjson.TypeReference<List<List<String>>>() {}); |
|
|
|
|
|
} |
|
|
//关闭资源
|
|
|
return jsonResult; |
|
|
response.close(); |
|
|
|
|
|
httpClient.close(); |
|
|
|
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
|
|
|
System.err.println("Failed to parse group data: " + e.getMessage()); |
|
|
|
|
|
System.err.println("Response was: " + result); |
|
|
|
|
|
// Return empty list instead of null to prevent NullPointerException
|
|
|
|
|
|
return new ArrayList<>(); |
|
|
} |
|
|
} |
|
|
return result; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// public List<Object> getGroup(String EXA_IP) throws URISyntaxException, IOException {
|
|
|
|
|
|
// List<Object> result = new ArrayList<>();
|
|
|
|
|
|
// try {
|
|
|
|
|
|
// // 目标 RPC 服务的 URL
|
|
|
|
|
|
// String url = "http://" + EXA_IP + ":9000/exawebapi/EXAItem/GetAllGroups";
|
|
|
|
|
|
// //创建HttpClient对象
|
|
|
|
|
|
// CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
|
|
|
// /*
|
|
|
|
|
|
// * 由于GET请求的参数都是拼装在URL地址后方,所以我们要构建一个URL,带参数
|
|
|
|
|
|
// */
|
|
|
|
|
|
// URIBuilder uriBuilder = new URIBuilder(url);
|
|
|
|
|
|
//
|
|
|
|
|
|
// /** 添加参数 */
|
|
|
|
|
|
//// uriBuilder.addParameter("ItemNames", itemNames);
|
|
|
|
|
|
//
|
|
|
|
|
|
// //创建请求对象
|
|
|
|
|
|
// HttpGet httpGet = new HttpGet(uriBuilder.build());
|
|
|
|
|
|
//
|
|
|
|
|
|
// // 传输的类型
|
|
|
|
|
|
// httpGet.addHeader("Content-Type", "application/json");
|
|
|
|
|
|
// //发送请求,请求响应结果
|
|
|
|
|
|
// CloseableHttpResponse response = httpClient.execute(httpGet);
|
|
|
|
|
|
// //获取服务器返回的状态码
|
|
|
|
|
|
// int statusCode = response.getStatusLine().getStatusCode();
|
|
|
|
|
|
// System.out.println("服务端返回成功的状态码为:" + statusCode);
|
|
|
|
|
|
// HttpEntity entity = response.getEntity();
|
|
|
|
|
|
// String body = EntityUtils.toString(entity).replaceAll("\\\\", "");
|
|
|
|
|
|
// System.out.println("服务端返回的数据为:" + body);
|
|
|
|
|
|
// if (body.startsWith("\"") && body.endsWith("\"")) {
|
|
|
|
|
|
// // 步骤3:去掉双引号
|
|
|
|
|
|
// body = body.substring(1, body.length() - 1); // 去掉首尾的双引号
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create();
|
|
|
|
|
|
// Type listType = new TypeToken<List<Object>>() {
|
|
|
|
|
|
// }.getType();
|
|
|
|
|
|
// result = gson.fromJson(body, listType);
|
|
|
|
|
|
//
|
|
|
|
|
|
// //关闭资源
|
|
|
|
|
|
// response.close();
|
|
|
|
|
|
// httpClient.close();
|
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
|
//
|
|
|
|
|
|
// }
|
|
|
|
|
|
// return result;
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
public String deletePoint(String EXA_IP, String ItemName) { |
|
|
public String deletePoint(String EXA_IP, String ItemName) { |
|
|
String requestPathDeleteItem = "http://" + EXA_IP + ":9000/exawebapi/exaitem/DeleteItem?ItemName=" + ItemName; |
|
|
String requestPathDeleteItem = "http://" + EXA_IP + ":9000/exawebapi/exaitem/DeleteItem?ItemName=" + ItemName; |
|
|
// 创建HttpClient
|
|
|
// 创建HttpClient
|
|
|
|