diff --git a/build.gradle b/build.gradle index 9a41398..b18c757 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = "org.bdware.sc" -version = "1.8.7" +version = "1.8.9" tasks.withType(JavaCompile) { // options.compilerArgs << '-Xlint:none' // options.compilerArgs << '-Xlint:deprecation' << "-Werror" @@ -68,7 +68,7 @@ jar { // while develop at local use "false" configurations.runtimeClasspath.filter { it.getAbsolutePath().contains("/lib/") - // false + // false }.collect { it.isDirectory() ? it : zipTree(it) } diff --git a/src/main/java/org/bdware/sc/engine/hook/DOOPAfterExecHandler.java b/src/main/java/org/bdware/sc/engine/hook/DOOPAfterExecHandler.java index 3e06b87..ff111d4 100644 --- a/src/main/java/org/bdware/sc/engine/hook/DOOPAfterExecHandler.java +++ b/src/main/java/org/bdware/sc/engine/hook/DOOPAfterExecHandler.java @@ -9,7 +9,7 @@ import org.bdware.doip.codec.doipMessage.DoipResponseCode; import org.bdware.doip.codec.operations.BasicOperations; import org.bdware.sc.JSEngine; import org.bdware.sc.boundry.ScriptReturnException; -import org.bdware.sc.engine.JSONTool; +import org.bdware.sc.conn.ByteUtil; import org.bdware.sc.entity.DoipMessagePacker; import org.bdware.sc.node.AnnotationHook; import org.bdware.sc.node.ArgPacks; @@ -41,7 +41,11 @@ public class DOOPAfterExecHandler implements AnnotationHook { } else { // pack if (!(argPacks.ret instanceof DoipMessage)) { - JsonObject jsonObjectRes = ((JsonElement)argPacks.ret).getAsJsonObject(); + JsonObject jsonObjectRes = ((JsonElement) argPacks.ret).getAsJsonObject(); + if (!jsonObjectRes.has("bodyBase64Encoded") || jsonObjectRes.get("bodyBase64Encoded").getAsBoolean() == false) { + String body = jsonObjectRes.get("body").getAsString(); + jsonObjectRes.addProperty("body", ByteUtil.encodeBASE64(body.getBytes(StandardCharsets.UTF_8))); + } // validate json response ArgSchemaVisitor visitor = new ArgSchemaVisitor(jsonObjectRes); validateJsonElementRulesByArgSchemaVisitor(jsonResponseRules, visitor); diff --git a/src/main/java/org/bdware/sc/engine/hook/DOOPBeforeExecHandler.java b/src/main/java/org/bdware/sc/engine/hook/DOOPBeforeExecHandler.java index db31ea5..d1cf7d5 100644 --- a/src/main/java/org/bdware/sc/engine/hook/DOOPBeforeExecHandler.java +++ b/src/main/java/org/bdware/sc/engine/hook/DOOPBeforeExecHandler.java @@ -82,8 +82,11 @@ public class DOOPBeforeExecHandler implements AnnotationHook { } public DoipMessage convertHttpRequestToDoipMessage(ContractRequest httpReq) { - JsonObject jsonParams = JsonParser.parseString(httpReq.getArg().getAsString()).getAsJsonObject(); - JsonDoipMessage doipMessage = JsonUtil.fromJson(jsonParams, JsonDoipMessage.class); + JsonElement arg = httpReq.getArg(); + if (!arg.isJsonObject()) { + arg = JsonParser.parseString(arg.getAsString()); + } + JsonDoipMessage doipMessage = JsonUtil.fromJson(arg, JsonDoipMessage.class); return doipMessage.toRequestDoipMessage(); }