fix: plugin null bugs

This commit is contained in:
CaiHQ 2021-11-08 14:18:41 +08:00
parent 1a444240a0
commit 305cd51854

View File

@ -131,10 +131,10 @@ public class CMHttpServer {
FileActions.setTextFileSuffixes(cmdConf.textFileSuffixes); FileActions.setTextFileSuffixes(cmdConf.textFileSuffixes);
// plugins // plugins
CMHttpHandler.wsPluginActions = cmdConf.wsPluginActions.split(","); CMHttpHandler.wsPluginActions = parseStrAsList(cmdConf.wsPluginActions);
MasterClientFrameHandler.clientToAgentPlugins = cmdConf.clientToAgentPlugins.split(","); MasterClientFrameHandler.clientToAgentPlugins = parseStrAsList(cmdConf.clientToAgentPlugins);
NodeCenterClientHandler.clientToClusterPlugins = cmdConf.clientToClusterPlugins.split(","); NodeCenterClientHandler.clientToClusterPlugins = parseStrAsList(cmdConf.clientToClusterPlugins);
TCPClientFrameHandler.tcpPlugins = cmdConf.tcpPlugins.split(","); TCPClientFrameHandler.tcpPlugins = parseStrAsList(cmdConf.tcpPlugins);
if (!cmdConf.debug.isEmpty()) { if (!cmdConf.debug.isEmpty()) {
try { try {
@ -152,6 +152,12 @@ public class CMHttpServer {
} }
} }
private static String[] parseStrAsList(String str) {
if (str == null)
return new String[]{};
return str.split(",");
}
private static void addDirToPath(String s) { private static void addDirToPath(String s) {
try { try {
LOGGER.info("add to path: " + s); LOGGER.info("add to path: " + s);
@ -251,7 +257,9 @@ public class CMHttpServer {
// if (ContractManager.reconnectPort < 0) ContractManager.reconnectPort = 1630; // if (ContractManager.reconnectPort < 0) ContractManager.reconnectPort = 1630;
File[] pluginJar = new File("./pluginLib/") File[] pluginJar = new File("./pluginLib/")
.listFiles(pathname -> pathname.getName().endsWith(".jar")); .listFiles(pathname -> pathname.getName().endsWith(".jar"));
URL[] urls = new URL[pluginJar.length]; URL[] urls;
if (pluginJar != null && pluginJar.length > 0) {
urls = new URL[pluginJar.length];
for (int i = 0; i < pluginJar.length; i++) { for (int i = 0; i < pluginJar.length; i++) {
try { try {
urls[i] = pluginJar[i].toURI().toURL(); urls[i] = pluginJar[i].toURI().toURL();
@ -260,6 +268,9 @@ public class CMHttpServer {
e.printStackTrace(); e.printStackTrace();
} }
} }
} else {
urls = new URL[]{};
}
pluginLoader = new URLClassLoader(urls, CMHttpServer.class.getClassLoader()); pluginLoader = new URLClassLoader(urls, CMHttpServer.class.getClassLoader());
if (port >= 18000 && port < 18100) { if (port >= 18000 && port < 18100) {
ContractManager.cPort = new ContractPort(1615 + (port - 18000) * 30); ContractManager.cPort = new ContractPort(1615 + (port - 18000) * 30);