|
@@ -14,6 +14,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.persagy.ibms.data.sdk.util.RepositoryBase;
|
|
|
import com.persagy.ibms.data.sdk.util.ToolUtil;
|
|
|
import com.persagy.ibms.data.sdk.websocket.AlarmWebSocketClient;
|
|
@@ -36,6 +39,21 @@ public class RestApi {
|
|
|
return "Hello World!" + "\n" + body;
|
|
|
}
|
|
|
|
|
|
+ @PostMapping(path = "/test_post_sleep")
|
|
|
+ public String test_post_sleep(@RequestBody String body, HttpServletRequest request) {
|
|
|
+ String ip = RestUtil.getIp(request);
|
|
|
+ log.info("ip:" + ip + " || test_post_sleep: " + body);
|
|
|
+ JSONObject param = JSON.parseObject(body);
|
|
|
+ String sleep = param.getString("sleep");
|
|
|
+ try {
|
|
|
+ long millisecond = Long.parseLong(sleep);
|
|
|
+ Thread.sleep(millisecond);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return body;
|
|
|
+ }
|
|
|
+
|
|
|
@GetMapping(path = "/test_get/{param}")
|
|
|
String test_get(@PathVariable("param") String param) {
|
|
|
return "Hello World!" + "\n" + param;
|
|
@@ -94,22 +112,38 @@ public class RestApi {
|
|
|
@PostMapping(path = { "/post", "/zkt-sdk/post" }, produces = "application/json;charset=UTF-8")
|
|
|
public String post(@RequestBody String param, HttpServletRequest request) {
|
|
|
String ip = RestUtil.getIp(request);
|
|
|
- log.info("ip:" + ip + " || post: " + param);
|
|
|
RepositoryBase.ip2param2time.putIfAbsent(ip, new ConcurrentHashMap<String, Date>());
|
|
|
ConcurrentHashMap<String, Date> param2time = RepositoryBase.ip2param2time.get(ip);
|
|
|
- if (!param2time.containsKey(param)) {
|
|
|
- param2time.put(param, new Date());
|
|
|
+ Date exist = param2time.putIfAbsent(param, new Date());
|
|
|
+ if (exist == null) {
|
|
|
+ log.info("ip:" + ip + " || post yes: " + param);
|
|
|
try {
|
|
|
- String result = RestUtil.post(param);
|
|
|
+ Object resultObject = RestUtil.post(param);
|
|
|
+ String result = JSONObject.toJSONString(resultObject, SerializerFeature.WriteMapNullValue);
|
|
|
return result;
|
|
|
} finally {
|
|
|
param2time.remove(param);
|
|
|
}
|
|
|
} else {
|
|
|
+ log.info("ip:" + ip + " || post no: " + param);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @PostMapping(path = { "/wrapper_post", "/zkt-sdk/wrapper_post" }, produces = "application/json;charset=UTF-8")
|
|
|
+ public String wrapper_post(@RequestBody String param, HttpServletRequest request) {
|
|
|
+ String ip = RestUtil.getIp(request);
|
|
|
+ log.info("ip:" + ip + " || wrapper_post : " + param);
|
|
|
+
|
|
|
+ JSONObject paramObject = JSON.parseObject(param);
|
|
|
+ String path = paramObject.get("path").toString();
|
|
|
+ Object Content = RestUtil.post(path);
|
|
|
+ JSONObject resultObject = new JSONObject();
|
|
|
+ resultObject.put("Content", Content);
|
|
|
+ String result = JSONObject.toJSONString(resultObject, SerializerFeature.WriteMapNullValue);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
@PostMapping(path = { "/post_filter_and_page", "/zkt-sdk/post_filter_and_page" }, produces = "application/json;charset=UTF-8")
|
|
|
public String post_filter_and_page(@RequestBody String param, HttpServletRequest request) {
|
|
|
String ip = RestUtil.getIp(request);
|