mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 01:44:08 +00:00
add JoinInfo support, the DOOPAfterExecHandler has Todo to deal with
This commit is contained in:
parent
a117ef4a41
commit
fb8305031e
@ -570,11 +570,6 @@ public class ContractProcess {
|
|||||||
fun.appendBeforeInvokeHandler(argSchemaHandler);
|
fun.appendBeforeInvokeHandler(argSchemaHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fun.isDoipOperation()) {
|
|
||||||
fun.appendBeforeInvokeHandler(DOOPBeforeExecHandler.createDOOPHandler());
|
|
||||||
fun.appendAfterInvokeHandler(DOOPAfterExecHandler.createDOOPHandler());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fun.isExport()) {
|
if (fun.isExport()) {
|
||||||
//if(fun.annotations...)
|
//if(fun.annotations...)
|
||||||
AccessHandler accessHandler = createHandlerIfExist(fun,fun.annotations,AccessHandler.class);
|
AccessHandler accessHandler = createHandlerIfExist(fun,fun.annotations,AccessHandler.class);
|
||||||
@ -601,6 +596,10 @@ public class ContractProcess {
|
|||||||
fun.appendAfterInvokeHandler(new HomomorphicDecryptHandler(fun));
|
fun.appendAfterInvokeHandler(new HomomorphicDecryptHandler(fun));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fun.isDoipOperation()) {
|
||||||
|
fun.appendBeforeInvokeHandler(DOOPBeforeExecHandler.createDOOPHandler());
|
||||||
|
fun.appendAfterInvokeHandler(DOOPAfterExecHandler.createDOOPHandler());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
package org.bdware.sc.engine;
|
package org.bdware.sc.engine;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import jdk.nashorn.internal.runtime.Context;
|
|
||||||
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||||
import wrp.jdk.nashorn.internal.objects.NativeArray;
|
import wrp.jdk.nashorn.internal.objects.NativeArray;
|
||||||
import wrp.jdk.nashorn.internal.runtime.PropertyMap;
|
import wrp.jdk.nashorn.internal.runtime.PropertyMap;
|
||||||
import wrp.jdk.nashorn.internal.runtime.ScriptObject;
|
|
||||||
import wrp.jdk.nashorn.internal.scripts.JO;
|
import wrp.jdk.nashorn.internal.scripts.JO;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class JSONTool {
|
public class JSONTool {
|
||||||
public static JsonElement convertMirrorToJson(Object ret2) {
|
public static JsonElement convertMirrorToJson(Object ret2) {
|
||||||
|
@ -10,6 +10,7 @@ import org.bdware.doip.codec.operations.BasicOperations;
|
|||||||
import org.bdware.sc.JSEngine;
|
import org.bdware.sc.JSEngine;
|
||||||
import org.bdware.sc.bean.ContractRequest;
|
import org.bdware.sc.bean.ContractRequest;
|
||||||
import org.bdware.sc.boundry.ScriptReturnException;
|
import org.bdware.sc.boundry.ScriptReturnException;
|
||||||
|
import org.bdware.sc.engine.JSONTool;
|
||||||
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;
|
||||||
@ -53,29 +54,34 @@ public class DOOPAfterExecHandler implements AnnotationHook {
|
|||||||
Object originDoipMsgPacker = argPacks.arg;
|
Object originDoipMsgPacker = argPacks.arg;
|
||||||
DoipMessage originDoipMsg = null;
|
DoipMessage originDoipMsg = null;
|
||||||
if (originDoipMsgPacker instanceof DoipMessagePacker) {
|
if (originDoipMsgPacker instanceof DoipMessagePacker) {
|
||||||
originDoipMsg = ((DoipMessagePacker) originDoipMsgPacker).rawDoipMsg;
|
DoipMessagePacker doipMessagePacker = (DoipMessagePacker) originDoipMsgPacker;
|
||||||
}
|
originDoipMsg = doipMessagePacker.rawDoipMsg;
|
||||||
|
|
||||||
JsonElement jsonElementRes = JsonUtil.fromJson(JsonUtil.toJson(argPacks.ret), JsonElement.class);
|
// if http, directly return
|
||||||
JsonObject jsonObjectRes = JsonUtil.fromJson(JsonUtil.toJson(argPacks.ret), JsonObject.class);
|
if (doipMessagePacker.source.equals("http")) {
|
||||||
|
return argPacks;
|
||||||
|
} else {
|
||||||
|
// pack
|
||||||
|
JsonObject jsonObjectRes = JSONTool.convertMirrorToJson(argPacks.ret).getAsJsonObject();
|
||||||
|
|
||||||
// validate json response
|
// validate json response
|
||||||
JsonElement jsonResponseRules = getRulesForJsonResponse(curOp);
|
JsonElement jsonResponseRules = getRulesForJsonResponse(curOp);
|
||||||
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jsonElementRes);
|
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jsonObjectRes);
|
||||||
validateJsonElementRulesByArgSchemaVisitor(jsonResponseRules, visitor);
|
validateJsonElementRulesByArgSchemaVisitor(jsonResponseRules, visitor);
|
||||||
|
|
||||||
JsonObject header = jsonObjectRes.get("header") != null ? jsonObjectRes.get("header").getAsJsonObject() : null;
|
JsonObject header = jsonObjectRes.get("header") != null ? jsonObjectRes.get("header").getAsJsonObject() : null;
|
||||||
String body = jsonObjectRes.get("body") != null ? jsonObjectRes.get("body").getAsString() : null;
|
String body = jsonObjectRes.get("body") != null ? jsonObjectRes.get("body").getAsString() : null;
|
||||||
|
|
||||||
|
originDoipMsg.header.setIsRequest(false);
|
||||||
if(header != null) {
|
if(header != null) {
|
||||||
String headerRespCode = header.get("response") != null ? header.get("response").getAsString() : null;
|
String headerRespCode = header.get("response") != null ? header.get("response").getAsString() : null;
|
||||||
if(headerRespCode != null) {
|
if(headerRespCode != null) {
|
||||||
for (DoipResponseCode responseCode : DoipResponseCode.values()) {
|
originDoipMsg.header.parameters.response = DoipResponseCode.valueOf(headerRespCode);
|
||||||
if(responseCode.toString().equals(headerRespCode)) {
|
|
||||||
originDoipMsg.header.parameters.response = responseCode;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo 其他的规则的添加
|
||||||
|
if(header.get("parameters") != null && header.get("parameters").getAsJsonObject().get("attributes") != null) {
|
||||||
|
originDoipMsg.header.parameters.attributes = header.get("parameters").getAsJsonObject().get("attributes").getAsJsonObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,6 +92,10 @@ public class DOOPAfterExecHandler implements AnnotationHook {
|
|||||||
argPacks.ret = originDoipMsg;
|
argPacks.ret = originDoipMsg;
|
||||||
return argPacks;
|
return argPacks;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return argPacks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ public class DOOPBeforeExecHandler implements AnnotationHook {
|
|||||||
JsonObject jsonParams = JsonParser.parseString(httpReq.getArg().getAsString()).getAsJsonObject();
|
JsonObject jsonParams = JsonParser.parseString(httpReq.getArg().getAsString()).getAsJsonObject();
|
||||||
// taking Extension into consideration
|
// taking Extension into consideration
|
||||||
JsonObject header = jsonParams.get("header") != null ? jsonParams.get("header").getAsJsonObject() : null;
|
JsonObject header = jsonParams.get("header") != null ? jsonParams.get("header").getAsJsonObject() : null;
|
||||||
JsonObject body = jsonParams.get("body") != null ? jsonParams.get("body").getAsJsonObject() : null;
|
String body = jsonParams.get("body") != null ? jsonParams.get("body").getAsString() : null;
|
||||||
DoipMessage doipMessage = null;
|
DoipMessage doipMessage = null;
|
||||||
switch(httpOperation) {
|
switch(httpOperation) {
|
||||||
case Hello:
|
case Hello:
|
||||||
@ -114,7 +114,7 @@ public class DOOPBeforeExecHandler implements AnnotationHook {
|
|||||||
case Update:
|
case Update:
|
||||||
doipMessage = new DoipMessageFactory.DoipMessageBuilder()
|
doipMessage = new DoipMessageFactory.DoipMessageBuilder()
|
||||||
.createRequest(header.get("identifier").getAsString(), httpOperation.getName())
|
.createRequest(header.get("identifier").getAsString(), httpOperation.getName())
|
||||||
.setBody(body.getAsString().getBytes(StandardCharsets.UTF_8))
|
.setBody(body.getBytes(StandardCharsets.UTF_8))
|
||||||
.create();
|
.create();
|
||||||
break;
|
break;
|
||||||
case Search:
|
case Search:
|
||||||
@ -153,7 +153,7 @@ public class DOOPBeforeExecHandler implements AnnotationHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(body != null) {
|
if(body != null) {
|
||||||
extensionBuilder.setBody(body.getAsString().getBytes(StandardCharsets.UTF_8));
|
extensionBuilder.setBody(body.getBytes(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
doipMessage = extensionBuilder.create();
|
doipMessage = extensionBuilder.create();
|
||||||
|
@ -141,7 +141,7 @@ public class DOOPRequestHandler implements DoipRequestHandler, RepositoryHandler
|
|||||||
try {
|
try {
|
||||||
// 改变调用的函数 + 构造DoipMessagePacker
|
// 改变调用的函数 + 构造DoipMessagePacker
|
||||||
Object ret = ContractProcess.instance.engine.executeWithoutLock(fn, contractRequest, arg);
|
Object ret = ContractProcess.instance.engine.executeWithoutLock(fn, contractRequest, arg);
|
||||||
DoipMessage finalDoipMsg = JsonUtil.fromJson(JsonUtil.toJson(ret), DoipMessage.class);
|
DoipMessage finalDoipMsg = (DoipMessage) ret;
|
||||||
finalDoipMsg.requestID = msg.requestID;
|
finalDoipMsg.requestID = msg.requestID;
|
||||||
if(finalDoipMsg.header.parameters == null) {
|
if(finalDoipMsg.header.parameters == null) {
|
||||||
finalDoipMsg.header.parameters = new HeaderParameter("", "");
|
finalDoipMsg.header.parameters = new HeaderParameter("", "");
|
||||||
|
Loading…
Reference in New Issue
Block a user