fix doop before handler

This commit is contained in:
CaiHQ 2023-05-20 10:03:42 +08:00
parent fd1690c97b
commit 76f564c777
3 changed files with 13 additions and 6 deletions

View File

@ -6,7 +6,7 @@ plugins {
} }
group = "org.bdware.sc" group = "org.bdware.sc"
version = "1.8.7" version = "1.8.9"
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
// options.compilerArgs << '-Xlint:none' // options.compilerArgs << '-Xlint:none'
// options.compilerArgs << '-Xlint:deprecation' << "-Werror" // options.compilerArgs << '-Xlint:deprecation' << "-Werror"
@ -68,7 +68,7 @@ jar {
// while develop at local use "false" // while develop at local use "false"
configurations.runtimeClasspath.filter { configurations.runtimeClasspath.filter {
it.getAbsolutePath().contains("/lib/") it.getAbsolutePath().contains("/lib/")
// false // false
}.collect { }.collect {
it.isDirectory() ? it : zipTree(it) it.isDirectory() ? it : zipTree(it)
} }

View File

@ -9,7 +9,7 @@ import org.bdware.doip.codec.doipMessage.DoipResponseCode;
import org.bdware.doip.codec.operations.BasicOperations; import org.bdware.doip.codec.operations.BasicOperations;
import org.bdware.sc.JSEngine; import org.bdware.sc.JSEngine;
import org.bdware.sc.boundry.ScriptReturnException; 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.entity.DoipMessagePacker;
import org.bdware.sc.node.AnnotationHook; import org.bdware.sc.node.AnnotationHook;
import org.bdware.sc.node.ArgPacks; import org.bdware.sc.node.ArgPacks;
@ -41,7 +41,11 @@ public class DOOPAfterExecHandler implements AnnotationHook {
} else { } else {
// pack // pack
if (!(argPacks.ret instanceof DoipMessage)) { 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 // validate json response
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jsonObjectRes); ArgSchemaVisitor visitor = new ArgSchemaVisitor(jsonObjectRes);
validateJsonElementRulesByArgSchemaVisitor(jsonResponseRules, visitor); validateJsonElementRulesByArgSchemaVisitor(jsonResponseRules, visitor);

View File

@ -82,8 +82,11 @@ public class DOOPBeforeExecHandler implements AnnotationHook {
} }
public DoipMessage convertHttpRequestToDoipMessage(ContractRequest httpReq) { public DoipMessage convertHttpRequestToDoipMessage(ContractRequest httpReq) {
JsonObject jsonParams = JsonParser.parseString(httpReq.getArg().getAsString()).getAsJsonObject(); JsonElement arg = httpReq.getArg();
JsonDoipMessage doipMessage = JsonUtil.fromJson(jsonParams, JsonDoipMessage.class); if (!arg.isJsonObject()) {
arg = JsonParser.parseString(arg.getAsString());
}
JsonDoipMessage doipMessage = JsonUtil.fromJson(arg, JsonDoipMessage.class);
return doipMessage.toRequestDoipMessage(); return doipMessage.toRequestDoipMessage();
} }