mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 09:54:07 +00:00
Merge remote-tracking branch 'origin/master' into lyh_dev to update AnnotationHook
This commit is contained in:
commit
37ad6c35d7
@ -6,7 +6,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "org.bdware.sc"
|
group = "org.bdware.sc"
|
||||||
version = "1.6.91"
|
version = "1.7.1"
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
@ -61,8 +61,8 @@ jar {
|
|||||||
// uncomment this when publish,
|
// uncomment this when publish,
|
||||||
//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)
|
||||||
}
|
}
|
||||||
|
BIN
lib/bdledger-java-sdk-dev-221113-all.jar
Normal file
BIN
lib/bdledger-java-sdk-dev-221113-all.jar
Normal file
Binary file not shown.
@ -510,12 +510,14 @@ public class ContractProcess {
|
|||||||
engine = new DesktopEngine(zipBundle.getManifest(), zipPath, contract);
|
engine = new DesktopEngine(zipBundle.getManifest(), zipPath, contract);
|
||||||
engine.loadJar(zf);
|
engine.loadJar(zf);
|
||||||
engine.registerResource(new Resources(zf, engine.getClassLoad()));
|
engine.registerResource(new Resources(zf, engine.getClassLoad()));
|
||||||
String retStr =
|
ContractResult result = engine.loadContract(contract, cn, cn.getInstrumentBranch());
|
||||||
JsonUtil.toJson(
|
JsonObject jo = new JsonObject();
|
||||||
engine.loadContract(contract, cn, cn.getInstrumentBranch()));
|
ContractResult onCreate = invokeOnCreate(contract.getCreateParam());
|
||||||
invokeOnCreate(contract.getCreateParam());
|
jo.add("onCreate", JsonUtil.parseObject(onCreate));
|
||||||
LOGGER.debug("result: " + retStr);
|
jo.add("loadContract", JsonUtil.parseObject(result));
|
||||||
return retStr;
|
jo.addProperty("status", result.status.merge(onCreate.status).toString());
|
||||||
|
LOGGER.debug("result: " + jo.toString());
|
||||||
|
return jo.toString();
|
||||||
} else {
|
} else {
|
||||||
contract.setScript(FileUtil.getFileContent(zipPath));
|
contract.setScript(FileUtil.getFileContent(zipPath));
|
||||||
return setContract(contract);
|
return setContract(contract);
|
||||||
@ -633,10 +635,15 @@ public class ContractProcess {
|
|||||||
handleLog();
|
handleLog();
|
||||||
LOGGER.info("load script, contract:" + JsonUtil.toJson(contract.getScriptStr()));
|
LOGGER.info("load script, contract:" + JsonUtil.toJson(contract.getScriptStr()));
|
||||||
LOGGER.info("load cn:" + JsonUtil.toJson(cn));
|
LOGGER.info("load cn:" + JsonUtil.toJson(cn));
|
||||||
String ret =
|
ContractResult ret =
|
||||||
JsonUtil.toJson(engine.loadContract(contract, cn, cn.getInstrumentBranch()));
|
engine.loadContract(contract, cn, cn.getInstrumentBranch());
|
||||||
invokeOnCreate(contract.getCreateParam());
|
ContractResult onCreate = invokeOnCreate(contract.getCreateParam());
|
||||||
return ret;
|
JsonObject jo = new JsonObject();
|
||||||
|
jo.add("onCreate", JsonUtil.parseObject(onCreate));
|
||||||
|
jo.add("loadContract", JsonUtil.parseObject(ret));
|
||||||
|
jo.addProperty("status", ret.status.merge(onCreate.status).toString());
|
||||||
|
LOGGER.debug("result: " + jo.toString());
|
||||||
|
return jo.toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
e.printStackTrace(new PrintStream(bo));
|
e.printStackTrace(new PrintStream(bo));
|
||||||
@ -688,7 +695,7 @@ public class ContractProcess {
|
|||||||
return r.totalMemory() - r.freeMemory();
|
return r.totalMemory() - r.freeMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void invokeOnCreate(JsonElement arg) {
|
private ContractResult invokeOnCreate(JsonElement arg) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
logIndex = new TimeSerialIndex("./ContractDB/" + cn.getContractName() + ".index");
|
logIndex = new TimeSerialIndex("./ContractDB/" + cn.getContractName() + ".index");
|
||||||
LOGGER.debug("timeSerialIndex: " + (System.currentTimeMillis() - start));
|
LOGGER.debug("timeSerialIndex: " + (System.currentTimeMillis() - start));
|
||||||
@ -728,7 +735,7 @@ public class ContractProcess {
|
|||||||
onCreate.setRequesterDOI("empty");
|
onCreate.setRequesterDOI("empty");
|
||||||
}
|
}
|
||||||
FunctionNode funNode = cn.getFunction("onCreate");
|
FunctionNode funNode = cn.getFunction("onCreate");
|
||||||
invoke(start, onCreate, funNode);
|
return invoke(onCreate, funNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetContractName(String name) {
|
public void resetContractName(String name) {
|
||||||
@ -736,8 +743,7 @@ public class ContractProcess {
|
|||||||
cn.resetContractName(name);
|
cn.resetContractName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void invokeOnRecover(JsonElement arg) {
|
private ContractResult invokeOnRecover(JsonElement arg) {
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
ContractRequest onRecover = new ContractRequest();
|
ContractRequest onRecover = new ContractRequest();
|
||||||
onRecover.setAction("onRecover");
|
onRecover.setAction("onRecover");
|
||||||
if (arg == null)
|
if (arg == null)
|
||||||
@ -753,26 +759,18 @@ public class ContractProcess {
|
|||||||
onRecover.setRequesterDOI("empty");
|
onRecover.setRequesterDOI("empty");
|
||||||
}
|
}
|
||||||
FunctionNode funNode = cn.getFunction("onRecover");
|
FunctionNode funNode = cn.getFunction("onRecover");
|
||||||
invoke(start, onRecover, funNode);
|
return invoke(onRecover, funNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void invoke(long start, ContractRequest onRecover, FunctionNode funNode) {
|
private ContractResult invoke(ContractRequest onRecover, FunctionNode funNode) {
|
||||||
// start = System.currentTimeMillis();
|
|
||||||
if (funNode != null) {
|
if (funNode != null) {
|
||||||
LOGGER.debug(
|
|
||||||
"getFunction:" + (System.currentTimeMillis() - start) + " " + funNode.functionName);
|
|
||||||
long start1 = System.currentTimeMillis();
|
|
||||||
funNode.setIsExport(true);
|
funNode.setIsExport(true);
|
||||||
ContractResult result = engine.executeContract(onRecover);
|
ContractResult result = engine.executeContract(onRecover);
|
||||||
LOGGER.info("invoke onCreate, result:" + new Gson().toJson(result));
|
|
||||||
LOGGER.debug("executeOnCreate:" + (System.currentTimeMillis() - start1));
|
|
||||||
start1 = System.currentTimeMillis();
|
|
||||||
funNode.setIsExport(false);
|
funNode.setIsExport(false);
|
||||||
engine.getTracePS().clean();
|
engine.getTracePS().clean();
|
||||||
LOGGER.debug("clearTrace:" + (System.currentTimeMillis() - start1));
|
return result;
|
||||||
// start1 = System.currentTimeMillis();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return new ContractResult(Status.Success, new JsonPrimitive("no funNode found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// public String executeBundle(ContractZipBundle czb, String arg) {
|
// public String executeBundle(ContractZipBundle czb, String arg) {
|
||||||
|
@ -611,7 +611,7 @@ public class DesktopEngine extends JSEngine {
|
|||||||
// long start = System.currentTimeMillis();
|
// long start = System.currentTimeMillis();
|
||||||
|
|
||||||
for (AnnotationHook handler : fun.beforeExecutionAnnotations()) {
|
for (AnnotationHook handler : fun.beforeExecutionAnnotations()) {
|
||||||
ret = handler.handle(input, this, ret);
|
ret = handler.handle(this, new ArgPacks(input, input.getArg(), ret));
|
||||||
}
|
}
|
||||||
// actually invoke!
|
// actually invoke!
|
||||||
if (ret == null) {
|
if (ret == null) {
|
||||||
@ -628,7 +628,7 @@ public class DesktopEngine extends JSEngine {
|
|||||||
//Mask在after裏面
|
//Mask在after裏面
|
||||||
//System.out.println("afterHook"+contract.Mask);
|
//System.out.println("afterHook"+contract.Mask);
|
||||||
|
|
||||||
ret = handler.handle(input, this, ret);
|
ret = handler.handle(this, new ArgPacks(input, input.getArg(), ret));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import org.bdware.sc.bean.ContractRequest;
|
|||||||
import org.bdware.sc.boundry.ScriptReturnException;
|
import org.bdware.sc.boundry.ScriptReturnException;
|
||||||
import org.bdware.sc.node.AnnotationHook;
|
import org.bdware.sc.node.AnnotationHook;
|
||||||
import org.bdware.sc.node.AnnotationNode;
|
import org.bdware.sc.node.AnnotationNode;
|
||||||
|
import org.bdware.sc.node.ArgPacks;
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.node.FunctionNode;
|
||||||
|
|
||||||
@YJSAnnotation(name = "ArgSchema")
|
@YJSAnnotation(name = "ArgSchema")
|
||||||
@ -33,7 +34,8 @@ public class ArgSchemaHandler implements AnnotationHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object handle(ContractRequest input, JSEngine Engine, Object ret) throws ScriptReturnException {
|
public ArgPacks handle(JSEngine Engine, ArgPacks argPacks) throws ScriptReturnException {
|
||||||
|
ContractRequest input = argPacks.request;
|
||||||
JsonElement je = input.getArg();
|
JsonElement je = input.getArg();
|
||||||
ArgSchemaVisitor visitor;
|
ArgSchemaVisitor visitor;
|
||||||
if (je.isJsonObject())
|
if (je.isJsonObject())
|
||||||
@ -44,6 +46,7 @@ public class ArgSchemaHandler implements AnnotationHook {
|
|||||||
visitor = new ArgSchemaVisitor(obj);
|
visitor = new ArgSchemaVisitor(obj);
|
||||||
//IMPORTANT automatically convert arg type here
|
//IMPORTANT automatically convert arg type here
|
||||||
input.setArg(obj);
|
input.setArg(obj);
|
||||||
|
argPacks.arg = obj;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
JsonObject jo = new JsonObject();
|
JsonObject jo = new JsonObject();
|
||||||
@ -65,6 +68,6 @@ public class ArgSchemaHandler implements AnnotationHook {
|
|||||||
jo.addProperty("code", visitor.errorCode);
|
jo.addProperty("code", visitor.errorCode);
|
||||||
throw new ScriptReturnException(jo);
|
throw new ScriptReturnException(jo);
|
||||||
}
|
}
|
||||||
return ret;
|
return argPacks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ public class ArgSchemaVisitor extends JsonVisitor {
|
|||||||
if (jo.has(key.substring(1))) {
|
if (jo.has(key.substring(1))) {
|
||||||
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jo.get(key.substring(1)));
|
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jo.get(key.substring(1)));
|
||||||
visitor.visit(schema.get(key));
|
visitor.visit(schema.get(key));
|
||||||
jo.add(key, visitor.get());
|
|
||||||
if (!visitor.status) {
|
if (!visitor.status) {
|
||||||
errorCode += visitor.errorCode;
|
errorCode += visitor.errorCode;
|
||||||
message += visitor.message;
|
message += visitor.message;
|
||||||
@ -46,13 +45,11 @@ public class ArgSchemaVisitor extends JsonVisitor {
|
|||||||
if (jo.has(key)) {
|
if (jo.has(key)) {
|
||||||
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jo.get(key));
|
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jo.get(key));
|
||||||
visitor.visit(schema.get(key));
|
visitor.visit(schema.get(key));
|
||||||
jo.add(key, visitor.get());
|
|
||||||
if (!visitor.status) {
|
if (!visitor.status) {
|
||||||
message += visitor.message;
|
message += visitor.message;
|
||||||
errorCode += visitor.errorCode;
|
errorCode += visitor.errorCode;
|
||||||
}
|
}
|
||||||
status &= visitor.status;
|
status &= visitor.status;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,11 +65,11 @@ public class ArgSchemaVisitor extends JsonVisitor {
|
|||||||
public JsonVisitor visitJsonArray(JsonArray ele) {
|
public JsonVisitor visitJsonArray(JsonArray ele) {
|
||||||
if (root.isJsonArray()) {
|
if (root.isJsonArray()) {
|
||||||
JsonArray array = root.getAsJsonArray();
|
JsonArray array = root.getAsJsonArray();
|
||||||
//message = new JsonArray();
|
|
||||||
for (int i = 0; i < array.size(); i++) {
|
for (int i = 0; i < array.size(); i++) {
|
||||||
ArgSchemaVisitor visitor = new ArgSchemaVisitor(array.get(i));
|
ArgSchemaVisitor visitor = new ArgSchemaVisitor(array.get(i));
|
||||||
visitor.visit(ele.get(0));
|
visitor.visit(ele.get(0));
|
||||||
message += visitor.message;
|
message += visitor.message;
|
||||||
|
status &= visitor.status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@ -95,9 +92,6 @@ public class ArgSchemaVisitor extends JsonVisitor {
|
|||||||
if (root.isJsonPrimitive() && root.getAsJsonPrimitive().isString()) {
|
if (root.isJsonPrimitive() && root.getAsJsonPrimitive().isString()) {
|
||||||
return this;
|
return this;
|
||||||
} else {
|
} else {
|
||||||
// message=new JsonObject();
|
|
||||||
// message.getAsJsonObject().addProperty("msg","xxx");
|
|
||||||
// message.getAsJsonObject().addProperty("code","1000");
|
|
||||||
message = "[Type error] The value (" + root.getAsJsonPrimitive().getAsString() + ") should be string";
|
message = "[Type error] The value (" + root.getAsJsonPrimitive().getAsString() + ") should be string";
|
||||||
status = false;
|
status = false;
|
||||||
errorCode = 1001;
|
errorCode = 1001;
|
||||||
@ -145,12 +139,6 @@ public class ArgSchemaVisitor extends JsonVisitor {
|
|||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//String result = masker.execute(primitive.toString());
|
|
||||||
//System.out.println(result);
|
|
||||||
|
|
||||||
//root = new JsonPrimitive(root.getAsString().substring(0, 2));
|
|
||||||
//https://github.com/guohf/DataX-Masking
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import org.bdware.sc.bean.ContractRequest;
|
|||||||
import org.bdware.sc.engine.ConfidentialContractUtil;
|
import org.bdware.sc.engine.ConfidentialContractUtil;
|
||||||
import org.bdware.sc.engine.DesktopEngine;
|
import org.bdware.sc.engine.DesktopEngine;
|
||||||
import org.bdware.sc.node.AnnotationHook;
|
import org.bdware.sc.node.AnnotationHook;
|
||||||
|
import org.bdware.sc.node.ArgPacks;
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.node.FunctionNode;
|
||||||
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||||
|
|
||||||
@ -16,19 +17,20 @@ public class ConfidentialHandler implements AnnotationHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object handle(ContractRequest input, JSEngine engine, Object ret) {
|
public ArgPacks handle(JSEngine engine, ArgPacks argPacks) {
|
||||||
try {
|
try {
|
||||||
|
ContractRequest input = argPacks.request;
|
||||||
DesktopEngine desktopEngine = (DesktopEngine) engine;
|
DesktopEngine desktopEngine = (DesktopEngine) engine;
|
||||||
ConfidentialContractUtil.copyTemplateToDestination(input);
|
ConfidentialContractUtil.copyTemplateToDestination(input);
|
||||||
ScriptObjectMirror globalVars = (ScriptObjectMirror) desktopEngine.get("Global");
|
ScriptObjectMirror globalVars = (ScriptObjectMirror) desktopEngine.get("Global");
|
||||||
ConfidentialContractUtil.dumpScriptAndStates(
|
ConfidentialContractUtil.dumpScriptAndStates(
|
||||||
desktopEngine.engine, fun, input, globalVars);
|
desktopEngine.engine, fun, input, globalVars);
|
||||||
// run in SGX instead of Nashorn if function has @Confidential annotation
|
// run in SGX instead of Nashorn if function has @Confidential annotation
|
||||||
ret = ConfidentialContractUtil.executeConfidentialContract(input);
|
argPacks.ret = ConfidentialContractUtil.executeConfidentialContract(input);
|
||||||
return ret;
|
return argPacks;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return ret;
|
return argPacks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,9 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bdware.sc.ContractResult;
|
import org.bdware.sc.ContractResult;
|
||||||
import org.bdware.sc.JSEngine;
|
import org.bdware.sc.JSEngine;
|
||||||
import org.bdware.sc.bean.ContractRequest;
|
|
||||||
import org.bdware.sc.boundry.JavaScriptEntry;
|
import org.bdware.sc.boundry.JavaScriptEntry;
|
||||||
import org.bdware.sc.node.AnnotationHook;
|
import org.bdware.sc.node.AnnotationHook;
|
||||||
|
import org.bdware.sc.node.ArgPacks;
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.node.FunctionNode;
|
||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
import org.paillier.PaillierKeyPair;
|
import org.paillier.PaillierKeyPair;
|
||||||
@ -25,7 +25,7 @@ public class HomomorphicDecryptHandler implements AnnotationHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object handle(ContractRequest input, JSEngine engine, Object ret) {
|
public ArgPacks handle(JSEngine engine, ArgPacks argPacks) {
|
||||||
try {
|
try {
|
||||||
// GetHomArgs args =
|
// GetHomArgs args =
|
||||||
// new GetHomArgs(
|
// new GetHomArgs(
|
||||||
@ -45,18 +45,18 @@ public class HomomorphicDecryptHandler implements AnnotationHook {
|
|||||||
RSAPrivateKey privkey = (RSAPrivateKey) PaillierKeyPair.pemToPrivateKey(privKeyStr);
|
RSAPrivateKey privkey = (RSAPrivateKey) PaillierKeyPair.pemToPrivateKey(privKeyStr);
|
||||||
LOGGER.info("HomomorphicEncryptHandler--------------------------------3: " + privkey);
|
LOGGER.info("HomomorphicEncryptHandler--------------------------------3: " + privkey);
|
||||||
HomoVisitor.privateKey = privkey;
|
HomoVisitor.privateKey = privkey;
|
||||||
ret = getDecryptResult(homoDecryptConf, JsonUtil.parseObject(ret));
|
argPacks.ret = getDecryptResult(homoDecryptConf, JsonUtil.parseObject(argPacks.ret));
|
||||||
if (null != ret) {
|
if (null != argPacks.ret) {
|
||||||
return ret;
|
return argPacks;
|
||||||
}
|
}
|
||||||
ret = new JsonObject();
|
argPacks.ret = new JsonObject();
|
||||||
}
|
}
|
||||||
return ret;
|
return argPacks;
|
||||||
// return ret;
|
// return ret;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return ret;
|
return argPacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getDecryptResult(JsonElement homoDecryptConf, JsonElement data) {
|
private Object getDecryptResult(JsonElement homoDecryptConf, JsonElement data) {
|
||||||
|
@ -9,6 +9,7 @@ import org.bdware.sc.JSEngine;
|
|||||||
import org.bdware.sc.bean.ContractRequest;
|
import org.bdware.sc.bean.ContractRequest;
|
||||||
import org.bdware.sc.boundry.JavaScriptEntry;
|
import org.bdware.sc.boundry.JavaScriptEntry;
|
||||||
import org.bdware.sc.node.AnnotationHook;
|
import org.bdware.sc.node.AnnotationHook;
|
||||||
|
import org.bdware.sc.node.ArgPacks;
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.node.FunctionNode;
|
||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
import org.paillier.PaillierKeyPair;
|
import org.paillier.PaillierKeyPair;
|
||||||
@ -25,15 +26,16 @@ public class HomomorphicEncryptHandler implements AnnotationHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object handle(ContractRequest input, JSEngine engine, Object ret) {
|
public ArgPacks handle(JSEngine engine, ArgPacks argPacks) {
|
||||||
try {
|
try {
|
||||||
|
ContractRequest input = argPacks.request;
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
"HomomorphicEncryptHandler--------------------------------1: "
|
"HomomorphicEncryptHandler--------------------------------1: "
|
||||||
+ input.getRequester());
|
+ input.getRequester());
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
"HomomorphicEncryptHandler--------------------------------2: "
|
"HomomorphicEncryptHandler--------------------------------2: "
|
||||||
+ this.fun.getSecretID());
|
+ this.fun.getSecretID());
|
||||||
JsonElement response = (JsonElement) ret;
|
JsonElement response = (JsonElement) argPacks.ret;
|
||||||
JsonElement homoEncryptConf = this.fun.getHomoEncryptConf();
|
JsonElement homoEncryptConf = this.fun.getHomoEncryptConf();
|
||||||
if (homoEncryptConf != null && !homoEncryptConf.isJsonNull()) {
|
if (homoEncryptConf != null && !homoEncryptConf.isJsonNull()) {
|
||||||
String res =
|
String res =
|
||||||
@ -54,20 +56,20 @@ public class HomomorphicEncryptHandler implements AnnotationHook {
|
|||||||
// if (homoEncryptConf.getAsJsonPrimitive().isString())
|
// if (homoEncryptConf.getAsJsonPrimitive().isString())
|
||||||
// homoEncryptConf = JsonParser.parseString(homoEncryptConf.getAsString());
|
// homoEncryptConf = JsonParser.parseString(homoEncryptConf.getAsString());
|
||||||
LOGGER.info("HomomorphicEncryptHandler--------------------------------6: " + homoEncryptConf);
|
LOGGER.info("HomomorphicEncryptHandler--------------------------------6: " + homoEncryptConf);
|
||||||
LOGGER.info("HomomorphicEncryptHandler--------------------------------7: " + ret);
|
LOGGER.info("HomomorphicEncryptHandler--------------------------------7: " + argPacks.ret);
|
||||||
LOGGER.info("HomomorphicEncryptHandler--------------------------------8: " + ret.toString());
|
LOGGER.info("HomomorphicEncryptHandler--------------------------------8: " + argPacks.ret.toString());
|
||||||
// LOGGER.info("HomomorphicEncryptHandler--------------------------------9: " + JsonUtil.toJson(ret));
|
// LOGGER.info("HomomorphicEncryptHandler--------------------------------9: " + JsonUtil.toJson(ret));
|
||||||
ret = getEncryptResult(homoEncryptConf, response);
|
argPacks.ret = getEncryptResult(homoEncryptConf, response);
|
||||||
if (ret != null) {
|
if (argPacks.ret != null) {
|
||||||
return ret;
|
return argPacks;
|
||||||
}
|
}
|
||||||
ret = new JsonObject();
|
argPacks.ret = new JsonObject();
|
||||||
}
|
}
|
||||||
return ret;
|
return argPacks;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return ret;
|
return argPacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getEncryptResult(JsonElement homoEncryptConf, JsonElement data) {
|
private Object getEncryptResult(JsonElement homoEncryptConf, JsonElement data) {
|
||||||
|
@ -9,13 +9,16 @@ import org.bdware.sc.bean.ContractRequest;
|
|||||||
import org.bdware.sc.bean.ProjectConfig;
|
import org.bdware.sc.bean.ProjectConfig;
|
||||||
import org.bdware.sc.engine.DesktopEngine;
|
import org.bdware.sc.engine.DesktopEngine;
|
||||||
import org.bdware.sc.node.AnnotationHook;
|
import org.bdware.sc.node.AnnotationHook;
|
||||||
|
import org.bdware.sc.node.ArgPacks;
|
||||||
|
|
||||||
public class MaskHandler implements AnnotationHook {
|
public class MaskHandler implements AnnotationHook {
|
||||||
private static final Logger LOGGER = LogManager.getLogger(MaskHandler.class);
|
private static final Logger LOGGER = LogManager.getLogger(MaskHandler.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object handle(ContractRequest input, JSEngine Engine, Object ret) {
|
public ArgPacks handle(JSEngine Engine, ArgPacks argPacks) {
|
||||||
try {
|
try {
|
||||||
|
ContractRequest input = argPacks.request;
|
||||||
|
Object ret = argPacks.ret;
|
||||||
DesktopEngine desktopEngine = (DesktopEngine) Engine;
|
DesktopEngine desktopEngine = (DesktopEngine) Engine;
|
||||||
ProjectConfig projectConfig = desktopEngine.getProjectConfig();
|
ProjectConfig projectConfig = desktopEngine.getProjectConfig();
|
||||||
JsonElement maskConf = projectConfig.getMask(input.getAction());
|
JsonElement maskConf = projectConfig.getMask(input.getAction());
|
||||||
@ -35,14 +38,17 @@ public class MaskHandler implements AnnotationHook {
|
|||||||
ret = visitor.get();
|
ret = visitor.get();
|
||||||
LOGGER.debug(maskConf);
|
LOGGER.debug(maskConf);
|
||||||
if (null != ret) {
|
if (null != ret) {
|
||||||
return ret;
|
argPacks.ret = ret;
|
||||||
|
|
||||||
|
return argPacks;
|
||||||
}
|
}
|
||||||
ret = JsonParser.parseString("");
|
ret = JsonParser.parseString("");
|
||||||
}
|
}
|
||||||
return ret;
|
argPacks.ret = ret;
|
||||||
|
return argPacks;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// e.printStackTrace();
|
// e.printStackTrace();
|
||||||
return ret;
|
return argPacks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,11 +6,13 @@ import org.bdware.sc.bean.ContractRequest;
|
|||||||
import org.bdware.sc.bean.ProjectConfig;
|
import org.bdware.sc.bean.ProjectConfig;
|
||||||
import org.bdware.sc.engine.DesktopEngine;
|
import org.bdware.sc.engine.DesktopEngine;
|
||||||
import org.bdware.sc.node.AnnotationHook;
|
import org.bdware.sc.node.AnnotationHook;
|
||||||
|
import org.bdware.sc.node.ArgPacks;
|
||||||
|
|
||||||
public class MockTemplateHandler implements AnnotationHook {
|
public class MockTemplateHandler implements AnnotationHook {
|
||||||
@Override
|
@Override
|
||||||
public Object handle(ContractRequest request, JSEngine engine, Object ret) {
|
public ArgPacks handle(JSEngine engine, ArgPacks argPacks) {
|
||||||
try {
|
try {
|
||||||
|
ContractRequest request = argPacks.request;
|
||||||
if (request.fromDebug()) {
|
if (request.fromDebug()) {
|
||||||
System.out.println(request.getAction());
|
System.out.println(request.getAction());
|
||||||
DesktopEngine desktopEngine = (DesktopEngine) engine;
|
DesktopEngine desktopEngine = (DesktopEngine) engine;
|
||||||
@ -19,13 +21,14 @@ public class MockTemplateHandler implements AnnotationHook {
|
|||||||
if (template != null && template.length() > 0) {
|
if (template != null && template.length() > 0) {
|
||||||
System.out.println(template);
|
System.out.println(template);
|
||||||
MockUtil Mock = new MockUtil();
|
MockUtil Mock = new MockUtil();
|
||||||
return Mock.mock(template).toString();
|
argPacks.ret = Mock.mock(template).toString();
|
||||||
} else return ret; //When mock config is null defined just ignore.
|
return argPacks;
|
||||||
|
} else return argPacks; //When mock config is null defined just ignore.
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
return ret;
|
return argPacks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package org.bdware.sc.engine.hook;
|
package org.bdware.sc.engine.hook;
|
||||||
|
|
||||||
import org.bdware.sc.JSEngine;
|
import org.bdware.sc.JSEngine;
|
||||||
import org.bdware.sc.bean.ContractRequest;
|
|
||||||
import org.bdware.sc.engine.JSONTool;
|
import org.bdware.sc.engine.JSONTool;
|
||||||
import org.bdware.sc.node.AnnotationHook;
|
import org.bdware.sc.node.AnnotationHook;
|
||||||
|
import org.bdware.sc.node.ArgPacks;
|
||||||
|
|
||||||
public class ObjToJsonHandler implements AnnotationHook {
|
public class ObjToJsonHandler implements AnnotationHook {
|
||||||
@Override
|
@Override
|
||||||
public Object handle(ContractRequest input, JSEngine desktopEngine, Object ret) {
|
public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) {
|
||||||
return JSONTool.convertMirrorToJson(ret);
|
argPacks.ret = JSONTool.convertMirrorToJson(argPacks.ret);
|
||||||
|
return argPacks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import org.bdware.sc.JSEngine;
|
|||||||
import org.bdware.sc.bean.ContractRequest;
|
import org.bdware.sc.bean.ContractRequest;
|
||||||
import org.bdware.sc.engine.DesktopEngine;
|
import org.bdware.sc.engine.DesktopEngine;
|
||||||
import org.bdware.sc.node.AnnotationHook;
|
import org.bdware.sc.node.AnnotationHook;
|
||||||
|
import org.bdware.sc.node.ArgPacks;
|
||||||
import org.commonmark.node.FencedCodeBlock;
|
import org.commonmark.node.FencedCodeBlock;
|
||||||
import org.commonmark.node.Heading;
|
import org.commonmark.node.Heading;
|
||||||
import org.commonmark.node.Node;
|
import org.commonmark.node.Node;
|
||||||
@ -56,12 +57,14 @@ public class ReadMeHandler implements AnnotationHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object handle(ContractRequest input, JSEngine engine, Object ret) {
|
public ArgPacks handle(JSEngine engine, ArgPacks argPacks) {
|
||||||
DesktopEngine desktopEngine = (DesktopEngine) engine;
|
DesktopEngine desktopEngine = (DesktopEngine) engine;
|
||||||
if (input.fromDebug() && (ret == null || ret.equals("emptyMock"))) {
|
ContractRequest input = argPacks.request;
|
||||||
ret = getReadMeData(desktopEngine, input);
|
|
||||||
System.out.println(ret);
|
if (input.fromDebug() && (argPacks.ret == null || argPacks.ret.equals("emptyMock"))) {
|
||||||
|
argPacks.ret = getReadMeData(desktopEngine, input);
|
||||||
|
System.out.println(argPacks.ret);
|
||||||
}
|
}
|
||||||
return ret;
|
return argPacks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user