|
@@ -1,7 +1,13 @@
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import io.netty.channel.Channel;
|
|
|
import wei.yigulu.iec104.nettyconfig.Iec104SlaverBuilder;
|
|
|
import wei.yigulu.iec104.util.SendDataFrameHelper;
|
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+
|
|
|
public class StartHttpServer {
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
//104端口
|
|
@@ -10,10 +16,11 @@ public class StartHttpServer {
|
|
|
Integer port2 = 2405;
|
|
|
Integer tem1;
|
|
|
Integer tem2;
|
|
|
- if (args.length == 1 || args.length > 2) {
|
|
|
- throw new RuntimeException("请输入两个端口,参数1为104Slver端口,参数2为配置页面端口");
|
|
|
+ File file = null;
|
|
|
+ if (args.length == 1 || args.length > 3) {
|
|
|
+ throw new RuntimeException("请输入两个端口,参数1为104Slver端口,参数2为配置页面端口,[参数3为配置文件路径]");
|
|
|
}
|
|
|
- if (args.length == 2) {
|
|
|
+ if (args.length == 2 || args.length == 3) {
|
|
|
try {
|
|
|
tem1 = Integer.parseInt(args[0]);
|
|
|
if (tem1 > 65535 || tem1 < 0) {
|
|
@@ -33,6 +40,18 @@ public class StartHttpServer {
|
|
|
if (tem1.intValue() == tem2.intValue()) {
|
|
|
throw new RuntimeException("参数1与参数2不能相同");
|
|
|
}
|
|
|
+ if (args.length == 3) {
|
|
|
+ try {
|
|
|
+ String fileUrl = args[2];
|
|
|
+ File file1 = new File(fileUrl);
|
|
|
+ if (file1.exists() && file1.isFile()) {
|
|
|
+ file = file1;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new RuntimeException("配置文件读取失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
port1 = tem1;
|
|
|
port2 = tem2;
|
|
|
}
|
|
@@ -47,6 +66,30 @@ public class StartHttpServer {
|
|
|
}
|
|
|
return null;
|
|
|
});
|
|
|
+ if (file != null) {
|
|
|
+ FileInputStream is = null;
|
|
|
+ StringBuilder stringBuilder = null;
|
|
|
+ try {
|
|
|
+ if (file.length() != 0) {
|
|
|
+ /**
|
|
|
+ * 文件有内容才去读文件
|
|
|
+ */
|
|
|
+ is = new FileInputStream(file);
|
|
|
+ InputStreamReader streamReader = new InputStreamReader(is);
|
|
|
+ BufferedReader reader = new BufferedReader(streamReader);
|
|
|
+ String line;
|
|
|
+ stringBuilder = new StringBuilder();
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
+ stringBuilder.append(line);
|
|
|
+ }
|
|
|
+ reader.close();
|
|
|
+ is.close();
|
|
|
+ RequestController.getInstance().batchImport(JSONObject.parseObject(stringBuilder.toString()));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
HttpServer httpServer = new HttpServer(port2);
|
|
|
httpServer.start();
|
|
|
}
|