|
@@ -19,7 +19,7 @@ import java.util.Map;
|
|
|
* @date 2024/5/22 15:14
|
|
|
* @package org.jeecg.modules.iotedgeCollectData.service
|
|
|
* @project interlock_server
|
|
|
- * @des 调用IoTEdge接口
|
|
|
+ * @des 调用IoTEdge接口 (有几率会出现Reader time out的情况,暂未解决)
|
|
|
*/
|
|
|
@Service
|
|
|
public class RestClientService {
|
|
@@ -50,13 +50,7 @@ public class RestClientService {
|
|
|
MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
headers.setContentType(type);
|
|
|
HttpEntity<String> httpEntity = new HttpEntity<String>(jsonObject.toString(), headers);
|
|
|
- ResponseEntity<JSONObject> response = null;
|
|
|
- try {
|
|
|
- response = restTemplate.postForEntity(url, httpEntity, JSONObject.class);
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("query error: " + e.getMessage());
|
|
|
- response = restTemplate.postForEntity(url, httpEntity, JSONObject.class);
|
|
|
- }
|
|
|
+ ResponseEntity<JSONObject> response = restTemplate.postForEntity(url, httpEntity, JSONObject.class);
|
|
|
String accessToken = (String) response.getBody().get("accessToken");
|
|
|
return accessToken;
|
|
|
}
|
|
@@ -76,13 +70,7 @@ public class RestClientService {
|
|
|
headers.setContentType(type);
|
|
|
headers.add("Authorization", "Bearer " + accessToken);
|
|
|
HttpEntity<String> httpEntity = new HttpEntity<String>(null, headers);
|
|
|
- ResponseEntity<JSONObject> response = null;
|
|
|
- try {
|
|
|
- response = restTemplate.exchange(url, HttpMethod.GET,httpEntity, JSONObject.class);
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("query error: " + e.getMessage());
|
|
|
- response = restTemplate.exchange(url, HttpMethod.GET,httpEntity, JSONObject.class);
|
|
|
- }
|
|
|
+ ResponseEntity<JSONObject> response = restTemplate.exchange(url, HttpMethod.GET,httpEntity, JSONObject.class);
|
|
|
return response.getBody();
|
|
|
}
|
|
|
|
|
@@ -102,13 +90,7 @@ public class RestClientService {
|
|
|
headers.setContentType(type);
|
|
|
headers.add("Authorization", "Bearer " + accessToken);
|
|
|
HttpEntity<String> httpEntity = new HttpEntity<String>(null, headers);
|
|
|
- ResponseEntity<JSONObject> response = null;
|
|
|
- try {
|
|
|
- response = restTemplate.exchange(url, HttpMethod.GET,httpEntity, JSONObject.class);
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("query error: " + e.getMessage());
|
|
|
- response = restTemplate.exchange(url, HttpMethod.GET,httpEntity, JSONObject.class);
|
|
|
- }
|
|
|
+ ResponseEntity<JSONObject> response = restTemplate.exchange(url, HttpMethod.GET,httpEntity, JSONObject.class);
|
|
|
return response.getBody();
|
|
|
}
|
|
|
|
|
@@ -128,13 +110,7 @@ public class RestClientService {
|
|
|
headers.setContentType(type);
|
|
|
headers.add("Authorization", "Bearer " + accessToken);
|
|
|
HttpEntity<String> httpEntity = new HttpEntity<String>(null, headers);
|
|
|
- ResponseEntity<JSONObject> response = null;
|
|
|
- try {
|
|
|
- response = restTemplate.exchange(url, HttpMethod.GET,httpEntity, JSONObject.class);
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("query error: " + e.getMessage());
|
|
|
- response = restTemplate.exchange(url, HttpMethod.GET,httpEntity, JSONObject.class);
|
|
|
- }
|
|
|
+ ResponseEntity<JSONObject> response = restTemplate.exchange(url, HttpMethod.GET,httpEntity, JSONObject.class);
|
|
|
return response.getBody();
|
|
|
}
|
|
|
|
|
@@ -194,13 +170,7 @@ public class RestClientService {
|
|
|
//jsonObject.put("variables",jsonObject1);
|
|
|
//jsonObject.put("attachments",list);
|
|
|
HttpEntity<String> httpEntity = new HttpEntity<String>(requestList.toString(), headers);
|
|
|
- ResponseEntity<String> response = null;
|
|
|
- try {
|
|
|
- response = restTemplate.exchange(url, HttpMethod.POST,httpEntity, String.class);
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("query error: " + e.getMessage());
|
|
|
- response = restTemplate.exchange(url, HttpMethod.POST,httpEntity, String.class);
|
|
|
- }
|
|
|
+ ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST,httpEntity, String.class);
|
|
|
return response;
|
|
|
}
|
|
|
|