diff --git a/script/cmconfig.json.template b/script/cmconfig.json.template index 3bd3bd1..65b49cf 100644 --- a/script/cmconfig.json.template +++ b/script/cmconfig.json.template @@ -11,9 +11,9 @@ "withBdledgerClient": "", "enableEventPersistence": false, "enableSsl": "./ssl/chained.pem:./ssl/domain.pem", - "textFileSuffixes": ".yjs,.json,.txt,.css,.js,.html,.md,.conf,.csv" - "wsPluginActions": "org.bdware.metering.MeteringAction" - "clientToAgentPlugins": "" - "clientToClusterPlugins": "" + "textFileSuffixes": ".yjs,.json,.txt,.css,.js,.html,.md,.conf,.csv", + "wsPluginActions": "org.bdware.metering.MeteringAction", + "clientToAgentPlugins": "", + "clientToClusterPlugins": "", "tcpPlugins": "" } \ No newline at end of file diff --git a/src/main/java/org/bdware/server/action/CMActions.java b/src/main/java/org/bdware/server/action/CMActions.java index 4fa1e46..664b14e 100644 --- a/src/main/java/org/bdware/server/action/CMActions.java +++ b/src/main/java/org/bdware/server/action/CMActions.java @@ -34,9 +34,9 @@ import java.util.*; public class CMActions implements OnHashCallback { private static final String PARAM_ACTION = "action"; - private static final JsonObject MISSING_ARGUMENT = JsonUtil.parseString("{\"action\":\"onExecuteResult\",\"executeTime\":-1," + private static final JsonObject MISSING_ARGUMENT = JsonUtil.parseStringAsJsonObject("{\"action\":\"onExecuteResult\",\"executeTime\":-1," + "\"status\":\"Error\",\"result\":\"missing arguments\"}"); - private static final JsonObject INVALID_DOI = JsonUtil.parseString( + private static final JsonObject INVALID_DOI = JsonUtil.parseStringAsJsonObject( "{\"action\":\"onExecuteResult\",\"executeTime\":-1," + "\"status\":\"Error\",\"result\":\"invalid contract doi\"}"); private static final Logger LOGGER = LogManager.getLogger(CMActions.class); @@ -247,7 +247,7 @@ public class CMActions implements OnHashCallback { } // JsonObject jo = - // JsonParser.parseString(args.get("arg").getAsString()).getAsJsonObject(); + // JsonParser.parseStringAsJsonObject(args.get("arg").getAsString()).getAsJsonObject(); // if (!jo.has("action")) { // resultCallback.onResult(MISSING_ARGUMENT); // return; @@ -475,7 +475,7 @@ public class CMActions implements OnHashCallback { String data = "failed"; String contractID = ""; String operation = ""; - //JsonElement mask = JsonParser.parseString(""); + //JsonElement mask = JsonParser.parseStringAsJsonObject(""); if (args.has("contractID") && args.has("operation") && args.has("arg")) { contractID = args.get("contractID").getAsString(); System.out.println(contractID); @@ -1852,7 +1852,7 @@ public class CMActions implements OnHashCallback { LOGGER.debug("startContractConfig"); // TODO private contract // if (args.has("isPrivate") && args.get("isPrivate").getAsBoolean()) { - // args.add("pubkey", JsonParser.parseString(handler.getPubKey())); + // args.add("pubkey", JsonParser.parseStringAsJsonObject(handler.getPubKey())); // } boolean type = args.get("type").getAsString().equalsIgnoreCase("TCP"); String contract = args.get("contractName").getAsString(); diff --git a/src/main/java/org/bdware/server/action/FileActions.java b/src/main/java/org/bdware/server/action/FileActions.java index c0e863f..c2b602e 100644 --- a/src/main/java/org/bdware/server/action/FileActions.java +++ b/src/main/java/org/bdware/server/action/FileActions.java @@ -1607,7 +1607,7 @@ public class FileActions { ret.put("ypk", new File(ypkPath).getName()); ret.put( "permissions", - JsonUtil.parseString(CMActions.manager.parseYpkPermissions(ypkPath))); + JsonUtil.parseStringAsJsonObject(CMActions.manager.parseYpkPermissions(ypkPath))); } catch (Exception e) { ByteArrayOutputStream bo = new ByteArrayOutputStream(); e.printStackTrace(new PrintStream(bo)); diff --git a/src/main/java/org/bdware/server/action/MasterWSAction.java b/src/main/java/org/bdware/server/action/MasterWSAction.java index 3deeae1..59e79c7 100644 --- a/src/main/java/org/bdware/server/action/MasterWSAction.java +++ b/src/main/java/org/bdware/server/action/MasterWSAction.java @@ -175,7 +175,7 @@ public class MasterWSAction { requestConnect.put("connectAll", true); } NetworkManager.instance.sendToNodeCenter(JsonUtil.toJson(requestConnect)); // 向NC发 - LOGGER.debug(JsonUtil.toJson(requestConnect)); + LOGGER.debug(JsonUtil.toPrettyJson(requestConnect)); boolean isSuccess = waitForConnection(nodeNames); if (!isSuccess) { return; diff --git a/src/main/java/org/bdware/server/action/TemporyTestAction.java b/src/main/java/org/bdware/server/action/TemporyTestAction.java index 181faf5..0155bd9 100644 --- a/src/main/java/org/bdware/server/action/TemporyTestAction.java +++ b/src/main/java/org/bdware/server/action/TemporyTestAction.java @@ -173,7 +173,7 @@ public class TemporyTestAction { c.setScript(args.get("script").getAsString()); c.setOwner(args.get("owner").getAsString()); ContractManager.instance.allocateKeyIfNotExists(c); - JsonObject jo = JsonUtil.parseObject(c); + JsonObject jo = JsonUtil.parseObjectAsJsonObject(c); jo.addProperty("action", "onAllocateKeyPair"); resultCallback.onResult(jo.toString()); } diff --git a/src/main/java/org/bdware/server/action/p2p/MasterClientTCPAction.java b/src/main/java/org/bdware/server/action/p2p/MasterClientTCPAction.java index 6045ad9..19b69aa 100644 --- a/src/main/java/org/bdware/server/action/p2p/MasterClientTCPAction.java +++ b/src/main/java/org/bdware/server/action/p2p/MasterClientTCPAction.java @@ -203,18 +203,17 @@ public class MasterClientTCPAction { } public void run1() { - // logger.info( - // "f " - // + new - // SimpleDateFormat("yyyy-MM-dd.HH:mm:ss") - // - // .format(System.currentTimeMillis())); + LOGGER.debug( + String.format( + "f %s", + new SimpleDateFormat("yyyy-MM-dd.HH:mm:ss") + .format(System.currentTimeMillis()))); Map ping = new HashMap<>(); ping.put("action", "masterPing"); handler.sendMsg(JsonUtil.toJson(ping)); } }; - if (checkAliveTask == null) + if (null == checkAliveTask) checkAliveTask = new TimerTask() { @Override diff --git a/src/main/java/org/bdware/server/tcp/TCPClientFrameHandler.java b/src/main/java/org/bdware/server/tcp/TCPClientFrameHandler.java index 242abcf..3a9bd6e 100644 --- a/src/main/java/org/bdware/server/tcp/TCPClientFrameHandler.java +++ b/src/main/java/org/bdware/server/tcp/TCPClientFrameHandler.java @@ -112,7 +112,7 @@ public class TCPClientFrameHandler extends SimpleChannelInboundHandler { ByteBuf bb = (ByteBuf) frame; JsonObject arg; try { - arg = JsonUtil.parseObject(new InputStreamReader(new ByteBufInputStream(bb))); + arg = JsonUtil.parseReaderAsJsonObject(new InputStreamReader(new ByteBufInputStream(bb))); } catch (Exception e) { e.printStackTrace(); Response response = new Response(); @@ -180,10 +180,10 @@ public class TCPClientFrameHandler extends SimpleChannelInboundHandler { } if (isOpen()) { try { - JsonObject jo = JsonUtil.parseObject(json); + JsonObject jo = JsonUtil.parseStringAsJsonObject(json); } catch (Exception e) { e.printStackTrace(); - System.out.println("============[MasterClientFrameHandler]JsonParse Error:" + json); + LOGGER.warn("JsonParse Error: " + e.getMessage() + "\n\t" + json); } ByteBuf buf = Unpooled.wrappedBuffer(json.getBytes()); ctx.channel().writeAndFlush(buf); diff --git a/src/main/java/org/bdware/server/trustedmodel/MasterProxy.java b/src/main/java/org/bdware/server/trustedmodel/MasterProxy.java index a42f271..64b6ffe 100644 --- a/src/main/java/org/bdware/server/trustedmodel/MasterProxy.java +++ b/src/main/java/org/bdware/server/trustedmodel/MasterProxy.java @@ -78,7 +78,7 @@ public class MasterProxy implements MasterStub { new ResultCallback() { @Override public void onResult(String ret) { - JsonObject result = JsonUtil.parseString(ret); + JsonObject result = JsonUtil.parseStringAsJsonObject(ret); ContractManager.instance.extractEventsFromContractResult( null, result, client, request, start); LOGGER.debug( @@ -105,7 +105,7 @@ public class MasterProxy implements MasterStub { new ContractResult( ContractResult.Status.Error, new JsonPrimitive("canceled because of queue too long")); - cb.onResult(JsonUtil.parseObject(cr)); + cb.onResult(JsonUtil.parseObjectAsJsonObject(cr)); CongestionControl.masterProxyLoad.decrementAndGet(); return; } @@ -114,7 +114,7 @@ public class MasterProxy implements MasterStub { new ResultCallback() { @Override public void onResult(String str) { - cb.onResult(JsonUtil.parseString(str)); + cb.onResult(JsonUtil.parseStringAsJsonObject(str)); CongestionControl.masterProxyLoad.decrementAndGet(); } }); diff --git a/src/main/java/org/bdware/units/function/CommunicationManager.java b/src/main/java/org/bdware/units/function/CommunicationManager.java index 897ed6b..c2a5fe9 100644 --- a/src/main/java/org/bdware/units/function/CommunicationManager.java +++ b/src/main/java/org/bdware/units/function/CommunicationManager.java @@ -81,7 +81,7 @@ public class CommunicationManager extends BaseFunctionManager { } public void handle(String str, String sender) { -// JsonObject jsonObject = (JsonObject) JsonParser.parseString(str); +// JsonObject jsonObject = (JsonObject) JsonParser.parseStringAsJsonObject(str); // if(jsonObject.has("action")) { // String action = jsonObject.get("action").getAsString(); // switch (action) {