Browse Source

增加最大连接数,提供wapper_post

menglu 3 years ago
parent
commit
d6a7145be1

+ 1 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/Application_ibms_data_sdk.java

@@ -12,6 +12,7 @@ public class Application_ibms_data_sdk {
 
 	public static void main(String[] args) throws Exception {
 		System.setProperty("fastjson.serializer_buffer_threshold", "64");
+		System.setProperty("http.maxConnections", "200");
 		SpringApplication.run(Application_ibms_data_sdk.class, args);
 	}
 

+ 38 - 4
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestApi.java

@@ -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);

+ 5 - 5
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestUtil.java

@@ -273,17 +273,17 @@ public class RestUtil {
 		}
 	}
 
-	public static String post(String param) {
+	public static Object post(String param) {
 		JSONArray path = JSON.parseArray(param);
 		String[] valuePath = new String[path.size()];
 		for (int i = 0; i < path.size(); i++) {
 			valuePath[i] = path.getString(i);
 		}
-		String result = RestUtil.post(valuePath);
+		Object result = RestUtil.post(valuePath);
 		return result;
 	}
 
-	public static String post(String[] valuePath) {
+	public static Object post(String[] valuePath) {
 		Repository Repository = RepositoryBase.instance;
 		try {
 			if (valuePath[valuePath.length - 1].equals("工单")) {
@@ -291,12 +291,12 @@ public class RestUtil {
 						.ReadJSONObject(new File(Constant.GetPath() + Constant.getSeperator() + "work_order_sample.json"));
 				JSONArray work_orders = new JSONArray();
 				work_orders.add(work_order);
-				return JSONObject.toJSONString(work_orders, SerializerFeature.WriteMapNullValue);
+				return work_orders;
 			} else {
 				Object valueObject = ComputeUtil.getValueObject(Repository, valuePath);
 				RecursiveUtil.refreshObject(Repository, valueObject);
 				Object valueJSON = ComputeUtil.getValueJSON(valueObject);
-				return JSONObject.toJSONString(valueJSON, SerializerFeature.WriteMapNullValue);
+				return valueJSON;
 			}
 		} catch (Exception e) {
 			e.printStackTrace();