update doop handler

This commit is contained in:
CaiHQ 2023-03-27 20:30:09 +08:00
parent 16f2d4fae1
commit 042cfae39b
7 changed files with 60 additions and 130 deletions

View File

@ -6,7 +6,7 @@ plugins {
} }
group = "org.bdware.sc" group = "org.bdware.sc"
version = "1.8.1" version = "1.8.2"
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
// options.compilerArgs << '-Xlint:none' // options.compilerArgs << '-Xlint:none'
// options.compilerArgs << '-Xlint:deprecation' << "-Werror" // options.compilerArgs << '-Xlint:deprecation' << "-Werror"
@ -67,7 +67,7 @@ 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)

View File

@ -31,6 +31,7 @@ import org.bdware.sc.engine.DesktopEngine;
import org.bdware.sc.engine.JSONTool; import org.bdware.sc.engine.JSONTool;
import org.bdware.sc.engine.hook.*; import org.bdware.sc.engine.hook.*;
import org.bdware.sc.handler.ContractHandler; import org.bdware.sc.handler.ContractHandler;
import org.bdware.sc.handler.DOOPRequestHandler;
import org.bdware.sc.index.TimeSerialIndex; import org.bdware.sc.index.TimeSerialIndex;
import org.bdware.sc.node.*; import org.bdware.sc.node.*;
import org.bdware.sc.server.DoipClusterServer; import org.bdware.sc.server.DoipClusterServer;
@ -80,6 +81,7 @@ public class ContractProcess {
private TimeSerialIndex logIndex; private TimeSerialIndex logIndex;
private RocksDBUtil edion; private RocksDBUtil edion;
private String pid; private String pid;
public DOOPRequestHandler doopRequestHandler;
public ContractProcess(int port, String cmi) { public ContractProcess(int port, String cmi) {
handler = new ContractHandler(this); handler = new ContractHandler(this);
@ -542,7 +544,7 @@ public class ContractProcess {
} }
} }
private void injectHandlers() { private void injectHandlers() throws Exception {
// 正式启动 // 正式启动
if (!this.contract.isDebug()) { if (!this.contract.isDebug()) {
// this.engine.getResources().loadAsString("/maskConfig.json"); // this.engine.getResources().loadAsString("/maskConfig.json");
@ -555,6 +557,9 @@ public class ContractProcess {
} }
} }
} }
DOOPBeforeExecHandler doopBeforeExecHandler = null;
DOOPAfterExecHandler doopAfterExecHandler = null;
doopRequestHandler = null;
for (FunctionNode fun : cn.getFunctions()) { for (FunctionNode fun : cn.getFunctions()) {
if (fun.isConfidential()) { if (fun.isConfidential()) {
fun.appendBeforeInvokeHandler(new ConfidentialHandler(fun)); fun.appendBeforeInvokeHandler(new ConfidentialHandler(fun));
@ -591,8 +596,12 @@ public class ContractProcess {
} }
if (fun.isDoipOperation()) { if (fun.isDoipOperation()) {
fun.appendBeforeInvokeHandler(DOOPBeforeExecHandler.createDOOPHandler()); if (doopRequestHandler == null) {
fun.appendAfterInvokeHandler(DOOPAfterExecHandler.createDOOPHandler()); doopRequestHandler = new DOOPRequestHandler();
}
fun.appendBeforeInvokeHandler(new DOOPBeforeExecHandler(fun.getDoipOperationInfo().operation));
fun.appendAfterInvokeHandler(new DOOPAfterExecHandler(fun.getDoipOperationInfo().operation));
doopRequestHandler.addDoipOperation(fun);
} }
} }
} }

View File

@ -2,9 +2,6 @@ package org.bdware.sc.compiler.ap;
import org.bdware.sc.bean.DoipOperationInfo; import org.bdware.sc.bean.DoipOperationInfo;
import org.bdware.sc.compiler.AnnotationProcessor; import org.bdware.sc.compiler.AnnotationProcessor;
import org.bdware.sc.engine.hook.DOOPAfterExecHandler;
import org.bdware.sc.engine.hook.DOOPBeforeExecHandler;
import org.bdware.sc.handler.DOOPRequestHandler;
import org.bdware.sc.node.AnnotationNode; import org.bdware.sc.node.AnnotationNode;
import org.bdware.sc.node.ContractNode; import org.bdware.sc.node.ContractNode;
import org.bdware.sc.node.FunctionNode; import org.bdware.sc.node.FunctionNode;
@ -15,23 +12,8 @@ public class DOOP extends AnnotationProcessor {
@Override @Override
public void processFunction(AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) throws Exception { public void processFunction(AnnotationNode anno, ContractNode contractNode, FunctionNode functionNode) throws Exception {
// 通过DOOP注解解析对应的值并放进对应的FunctionNode中 // 通过DOOP注解解析对应的值并放进对应的FunctionNode中
// 注解必须暴露出来昂
functionNode.setIsExport(true); functionNode.setIsExport(true);
functionNode.setIsDoipOperation(true); functionNode.setIsDoipOperation(true);
functionNode.setDoipOperationInfo(DoipOperationInfo.create(anno, contractNode)); functionNode.setDoipOperationInfo(DoipOperationInfo.create(anno, contractNode));
// functionNode.setFunctionName(functionNode.getDoipOperationInfo().operationName);
// 维护DOOPRequestHandler
DOOPRequestHandler.createHandler();
DOOPRequestHandler.instance.addDoipOperation(functionNode);
// 维护DOOPHandler
DOOPBeforeExecHandler.createDOOPHandler();
DOOPBeforeExecHandler.instance.putFuncNameAndDoipOperationsMapping(functionNode);
DOOPAfterExecHandler.createDOOPHandler();
DOOPAfterExecHandler.instance.putFuncNameAndDoipOperationsMapping(functionNode);
// 维护ContractNodefunctionName is useless, use BasicOperation to map the corresponding functionNode
// contractNode.updateFunctionMap(functionNode.functionName, functionNode.getDoipOperationInfo().operationName);
} }
} }

View File

@ -3,10 +3,12 @@ package org.bdware.sc.engine.hook;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import org.bdware.doip.codec.doipMessage.*; import org.bdware.doip.codec.doipMessage.DoipMessage;
import org.bdware.doip.codec.doipMessage.DoipResponseCode;
import org.bdware.doip.codec.doipMessage.HeaderParameter;
import org.bdware.doip.codec.doipMessage.MessageHeader;
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.bean.ContractRequest;
import org.bdware.sc.boundry.ScriptReturnException; import org.bdware.sc.boundry.ScriptReturnException;
import org.bdware.sc.engine.JSONTool; import org.bdware.sc.engine.JSONTool;
import org.bdware.sc.entity.DoipMessagePacker; import org.bdware.sc.entity.DoipMessagePacker;
@ -16,39 +18,15 @@ import org.bdware.sc.node.FunctionNode;
import org.bdware.sc.util.JsonUtil; import org.bdware.sc.util.JsonUtil;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class DOOPAfterExecHandler implements AnnotationHook { public class DOOPAfterExecHandler implements AnnotationHook {
public static Map<String, BasicOperations> funcNameToDoipOperations; private JsonElement jsonResponseRules;
public static DOOPAfterExecHandler instance;
public DOOPAfterExecHandler() { public DOOPAfterExecHandler(BasicOperations operations) {
funcNameToDoipOperations = new HashMap<>(); jsonResponseRules = getRulesForJsonResponse(operations);
} }
public static DOOPAfterExecHandler createDOOPHandler() {
if(instance == null) {
instance = new DOOPAfterExecHandler();
}
return instance;
}
public void putFuncNameAndDoipOperationsMapping(FunctionNode fn) {
String basicOperationsString = fn.getDoipOperationInfo().operationType;
BasicOperations operation = BasicOperations.Unknown;
for(BasicOperations basicOperation : BasicOperations.values()) {
if(basicOperation.toString().equals(basicOperationsString)) {
operation = basicOperation;
}
}
funcNameToDoipOperations.put(fn.getFunctionName(), operation);
}
@Override @Override
public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) { public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) {
BasicOperations curOp = funcNameToDoipOperations.get(argPacks.request.getAction());
Object originDoipMsgPacker = argPacks.arg; Object originDoipMsgPacker = argPacks.arg;
DoipMessage originDoipMsg = null; DoipMessage originDoipMsg = null;
if (originDoipMsgPacker instanceof DoipMessagePacker) { if (originDoipMsgPacker instanceof DoipMessagePacker) {
@ -61,27 +39,25 @@ public class DOOPAfterExecHandler implements AnnotationHook {
} else { } else {
// pack // pack
JsonObject jsonObjectRes = JSONTool.convertMirrorToJson(argPacks.ret).getAsJsonObject(); JsonObject jsonObjectRes = JSONTool.convertMirrorToJson(argPacks.ret).getAsJsonObject();
// validate json response // validate json response
JsonElement jsonResponseRules = getRulesForJsonResponse(curOp);
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jsonObjectRes); 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;
// 和HTTP一样所有需要的字段自己封装校验规则也比较简单这里只做简单的包装返回即可 // 和HTTP一样所有需要的字段自己封装校验规则也比较简单这里只做简单的包装返回即可
if(header != null) { if (header != null) {
originDoipMsg.header = JsonUtil.fromJson(header, MessageHeader.class); originDoipMsg.header = JsonUtil.fromJson(header, MessageHeader.class);
// response字段根据白皮书上的规定处于header下人为包装到parameters的response中 // response字段根据白皮书上的规定处于header下人为包装到parameters的response中
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) {
if (originDoipMsg.header.parameters == null) originDoipMsg.header.parameters = new HeaderParameter(null, null); if (originDoipMsg.header.parameters == null)
originDoipMsg.header.parameters = new HeaderParameter(null, null);
originDoipMsg.header.parameters.response = DoipResponseCode.valueOf(headerRespCode); originDoipMsg.header.parameters.response = DoipResponseCode.valueOf(headerRespCode);
} }
} }
if(body != null) { if (body != null) {
originDoipMsg.body.encodedData = body.getBytes(StandardCharsets.UTF_8); originDoipMsg.body.encodedData = body.getBytes(StandardCharsets.UTF_8);
} }
@ -94,7 +70,6 @@ public class DOOPAfterExecHandler implements AnnotationHook {
} }
public static JsonElement getRulesForJsonResponse(BasicOperations basicOperations) { public static JsonElement getRulesForJsonResponse(BasicOperations basicOperations) {
switch (basicOperations) { switch (basicOperations) {
case Hello: case Hello:
@ -114,31 +89,27 @@ public class DOOPAfterExecHandler implements AnnotationHook {
} }
// old convert jsonResponse from argPack's ret to Doip response in doip chain logic // old convert jsonResponse from argPack's ret to Doip response in doip chain logic
public static DoipMessage convertJsonResponseToDoipMessage(FunctionNode fn, JsonElement jsonResponse, DoipMessage msg) { public DoipMessage convertJsonResponseToDoipMessage(FunctionNode fn, JsonElement jsonResponse, DoipMessage msg) {
BasicOperations curOp = funcNameToDoipOperations.get(fn.getFunctionName());
JsonObject jsonParams = jsonResponse.getAsJsonObject(); JsonObject jsonParams = jsonResponse.getAsJsonObject();
// validate json response // validate json response
JsonElement jsonResponseRules = getRulesForJsonResponse(curOp);
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jsonResponse); ArgSchemaVisitor visitor = new ArgSchemaVisitor(jsonResponse);
validateJsonElementRulesByArgSchemaVisitor(jsonResponseRules, visitor); validateJsonElementRulesByArgSchemaVisitor(jsonResponseRules, visitor);
JsonObject header = jsonParams.get("header") != null ? jsonParams.get("header").getAsJsonObject() : null; JsonObject header = jsonParams.get("header") != null ? jsonParams.get("header").getAsJsonObject() : null;
String body = jsonParams.get("body") != null ? jsonParams.get("body").getAsString() : null; String body = jsonParams.get("body") != null ? jsonParams.get("body").getAsString() : null;
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()) { for (DoipResponseCode responseCode : DoipResponseCode.values()) {
if(responseCode.toString().equals(headerRespCode)) { if (responseCode.toString().equals(headerRespCode)) {
msg.header.parameters.response = responseCode; msg.header.parameters.response = responseCode;
break; break;
} }
} }
} }
} }
if (body != null) {
if(body != null) {
msg.body.encodedData = body.getBytes(StandardCharsets.UTF_8); msg.body.encodedData = body.getBytes(StandardCharsets.UTF_8);
} }

View File

@ -12,37 +12,19 @@ import org.bdware.sc.boundry.ScriptReturnException;
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;
import org.bdware.sc.node.FunctionNode;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
public class DOOPBeforeExecHandler implements AnnotationHook { public class DOOPBeforeExecHandler implements AnnotationHook {
public static Map<String, BasicOperations> funcNameToDoipOperations;
public static DOOPBeforeExecHandler instance;
public DOOPBeforeExecHandler() {
funcNameToDoipOperations = new HashMap<>();
}
public static DOOPBeforeExecHandler createDOOPHandler() { private final BasicOperations httpOperation;
if(instance == null) { private JsonElement httpArgsRules;
instance = new DOOPBeforeExecHandler();
}
return instance; public DOOPBeforeExecHandler(BasicOperations operations) {
} httpOperation = operations;
httpArgsRules = getRulesForHTTPRequest(operations);
public void putFuncNameAndDoipOperationsMapping(FunctionNode fn) {
String basicOperationsString = fn.getDoipOperationInfo().operationType;
BasicOperations operation = BasicOperations.Unknown;
for(BasicOperations basicOperation : BasicOperations.values()) {
if(basicOperation.toString().equals(basicOperationsString)) {
operation = basicOperation;
}
}
funcNameToDoipOperations.put(fn.getFunctionName(), operation);
} }
@Override @Override
@ -50,8 +32,8 @@ public class DOOPBeforeExecHandler implements AnnotationHook {
Object arg = argPacks.arg; Object arg = argPacks.arg;
DoipMessagePacker doipMsgPackerArg = new DoipMessagePacker(); DoipMessagePacker doipMsgPackerArg = new DoipMessagePacker();
if (arg instanceof DoipMessagePacker){ if (arg instanceof DoipMessagePacker) {
doipMsgPackerArg = (DoipMessagePacker)arg; doipMsgPackerArg = (DoipMessagePacker) arg;
} else { } else {
// validate http request's params // validate http request's params
ContractRequest httpReq = argPacks.request; ContractRequest httpReq = argPacks.request;
@ -66,19 +48,16 @@ public class DOOPBeforeExecHandler implements AnnotationHook {
return argPacks; return argPacks;
} }
public static void validateHTTPRequestArgs(ContractRequest httpReq) { public void validateHTTPRequestArgs(ContractRequest httpReq) {
JsonElement originArgs = httpReq.getArg(); JsonElement originArgs = httpReq.getArg();
JsonElement httpArgs = JsonParser.parseString(originArgs.getAsString()); JsonElement httpArgs = JsonParser.parseString(originArgs.getAsString());
BasicOperations curOp = funcNameToDoipOperations.get(httpReq.getAction());
// get args rules and validate http args // get args rules and validate http args
JsonElement httpArgsRules = getRulesForHTTPRequest(curOp);
ArgSchemaVisitor visitor = new ArgSchemaVisitor(httpArgs); ArgSchemaVisitor visitor = new ArgSchemaVisitor(httpArgs);
validateJsonElementRulesByArgSchemaVisitor(httpArgsRules, visitor); validateJsonElementRulesByArgSchemaVisitor(httpArgsRules, visitor);
} }
public static JsonElement getRulesForHTTPRequest(BasicOperations basicOperation) { public static JsonElement getRulesForHTTPRequest(BasicOperations basicOperation) {
switch(basicOperation) { switch (basicOperation) {
case Hello: case Hello:
case Delete: case Delete:
case ListOps: case ListOps:
@ -97,14 +76,13 @@ public class DOOPBeforeExecHandler implements AnnotationHook {
} }
} }
public static DoipMessage convertHttpRequestToDoipMessage(ContractRequest httpReq) { public DoipMessage convertHttpRequestToDoipMessage(ContractRequest httpReq) {
BasicOperations httpOperation = funcNameToDoipOperations.get(httpReq.getAction());
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;
String body = jsonParams.get("body") != null ? jsonParams.get("body").getAsString() : 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:
case Delete: case Delete:
case ListOps: case ListOps:
@ -121,13 +99,13 @@ public class DOOPBeforeExecHandler implements AnnotationHook {
DoipMessageFactory.DoipMessageBuilder searchBuilder = new DoipMessageFactory.DoipMessageBuilder() DoipMessageFactory.DoipMessageBuilder searchBuilder = new DoipMessageFactory.DoipMessageBuilder()
.createRequest(header.get("identifier").getAsString(), httpOperation.getName()); .createRequest(header.get("identifier").getAsString(), httpOperation.getName());
JsonElement query = header.get("query"); JsonElement query = header.get("query");
if(query != null) searchBuilder.addAttributes("query", query.getAsString()); if (query != null) searchBuilder.addAttributes("query", query.getAsString());
JsonElement pageNum = header.get("pageNum"); JsonElement pageNum = header.get("pageNum");
if(pageNum != null) searchBuilder.addAttributes("pageNum", pageNum.getAsInt()); if (pageNum != null) searchBuilder.addAttributes("pageNum", pageNum.getAsInt());
JsonElement pageSize = header.get("pageSize"); JsonElement pageSize = header.get("pageSize");
if(pageSize != null) searchBuilder.addAttributes("pageSize", pageSize.getAsInt()); if (pageSize != null) searchBuilder.addAttributes("pageSize", pageSize.getAsInt());
JsonElement type = header.get("type"); JsonElement type = header.get("type");
if(type != null) searchBuilder.addAttributes("type", type.getAsString()); if (type != null) searchBuilder.addAttributes("type", type.getAsString());
doipMessage = searchBuilder.create(); doipMessage = searchBuilder.create();
break; break;
@ -135,13 +113,14 @@ public class DOOPBeforeExecHandler implements AnnotationHook {
doipMessage = new DoipMessageFactory.DoipMessageBuilder().createRequest(header.get("identifier").getAsString(), httpOperation.getName()).create(); doipMessage = new DoipMessageFactory.DoipMessageBuilder().createRequest(header.get("identifier").getAsString(), httpOperation.getName()).create();
JsonElement element = header.get("element"); JsonElement element = header.get("element");
JsonElement includeElementData = header.get("includeElementData"); JsonElement includeElementData = header.get("includeElementData");
if(element != null) doipMessage.header.parameters.addAttribute("element", element.getAsString()); if (element != null) doipMessage.header.parameters.addAttribute("element", element.getAsString());
if(includeElementData != null && includeElementData.getAsBoolean()) doipMessage.header.parameters.addAttribute("includeElementData", "true"); if (includeElementData != null && includeElementData.getAsBoolean())
doipMessage.header.parameters.addAttribute("includeElementData", "true");
break; break;
case Extension: case Extension:
DoipMessageFactory.DoipMessageBuilder extensionBuilder = new DoipMessageFactory.DoipMessageBuilder(); DoipMessageFactory.DoipMessageBuilder extensionBuilder = new DoipMessageFactory.DoipMessageBuilder();
if(header != null) { if (header != null) {
if(header.get("identifier") != null) { if (header.get("identifier") != null) {
extensionBuilder = extensionBuilder extensionBuilder = extensionBuilder
.createRequest(header.get("identifier").getAsString(), httpOperation.getName()); .createRequest(header.get("identifier").getAsString(), httpOperation.getName());
} }
@ -152,7 +131,7 @@ public class DOOPBeforeExecHandler implements AnnotationHook {
} }
} }
if(body != null) { if (body != null) {
extensionBuilder.setBody(body.getBytes(StandardCharsets.UTF_8)); extensionBuilder.setBody(body.getBytes(StandardCharsets.UTF_8));
} }

View File

@ -1,6 +1,5 @@
package org.bdware.sc.handler; package org.bdware.sc.handler;
import com.google.gson.Gson;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -21,22 +20,11 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class DOOPRequestHandler implements DoipRequestHandler, RepositoryHandler { public class DOOPRequestHandler implements DoipRequestHandler, RepositoryHandler {
public Map<String, FunctionNode> doipFunctionNodeMap;
static Logger logger = LogManager.getLogger(NettyServerHandler.class); static Logger logger = LogManager.getLogger(NettyServerHandler.class);
static Gson gson; public Map<String, FunctionNode> doipFunctionNodeMap;
public static DOOPRequestHandler instance;
public DOOPRequestHandler() { public DOOPRequestHandler() {
doipFunctionNodeMap = new HashMap<>(); doipFunctionNodeMap = new HashMap<>();
gson = new Gson();
}
public static DOOPRequestHandler createHandler() {
if(instance == null) {
instance = new DOOPRequestHandler();
}
return instance;
} }
public void addDoipOperation(FunctionNode function) throws Exception { public void addDoipOperation(FunctionNode function) throws Exception {
@ -145,10 +133,10 @@ public class DOOPRequestHandler implements DoipRequestHandler, RepositoryHandler
Object ret = ContractProcess.instance.engine.executeWithoutLock(fn, contractRequest, arg); Object ret = ContractProcess.instance.engine.executeWithoutLock(fn, contractRequest, arg);
DoipMessage finalDoipMsg = (DoipMessage) ret; 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("", "");
} }
if(finalDoipMsg.header.parameters.attributes == null) { if (finalDoipMsg.header.parameters.attributes == null) {
finalDoipMsg.header.parameters.attributes = new JsonObject(); finalDoipMsg.header.parameters.attributes = new JsonObject();
} }
finalDoipMsg.header.parameters.attributes.addProperty("nodeID", String.valueOf(JavaScriptEntry.shardingID)); finalDoipMsg.header.parameters.attributes.addProperty("nodeID", String.valueOf(JavaScriptEntry.shardingID));
@ -162,9 +150,9 @@ public class DOOPRequestHandler implements DoipRequestHandler, RepositoryHandler
} }
public ContractRequest constructContractRequest(FunctionNode fn, DoipMessage request) { public ContractRequest constructContractRequest(FunctionNode fn, DoipMessage request) {
ContractRequest cr = new ContractRequest(); ContractRequest cr = new ContractRequest();
cr.setContractID(""); cr.setContractID("");
if(request.credential == null) { if (request.credential == null) {
cr.setRequester(null); cr.setRequester(null);
} else { } else {
cr.setRequester(request.credential.getSigner()); cr.setRequester(request.credential.getSigner());

View File

@ -6,6 +6,7 @@ import org.bdware.doip.endpoint.server.DoipListenerConfig;
import org.bdware.doip.endpoint.server.DoipServerImpl; import org.bdware.doip.endpoint.server.DoipServerImpl;
import org.bdware.doip.endpoint.server.DoipServiceInfo; import org.bdware.doip.endpoint.server.DoipServiceInfo;
import org.bdware.doip.endpoint.server.StartServerCallback; import org.bdware.doip.endpoint.server.StartServerCallback;
import org.bdware.sc.ContractProcess;
import org.bdware.sc.handler.DOOPRequestHandler; import org.bdware.sc.handler.DOOPRequestHandler;
import java.net.URI; import java.net.URI;
@ -54,7 +55,7 @@ public class DoipLocalSingleton {
} }
DoipServiceInfo info = new DoipServiceInfo("aibd.govdata.tj/do.3f9c41e6-9f8e-48a0-9220-53f438d40e43", "ownerDEF", "gateRepo", infos); DoipServiceInfo info = new DoipServiceInfo("aibd.govdata.tj/do.3f9c41e6-9f8e-48a0-9220-53f438d40e43", "ownerDEF", "gateRepo", infos);
server = new DoipServerImpl(info); server = new DoipServerImpl(info);
DOOPRequestHandler handler = DOOPRequestHandler.createHandler(); DOOPRequestHandler handler = ContractProcess.instance.doopRequestHandler;
server.setRepositoryHandler(handler); server.setRepositoryHandler(handler);
ResultChecker checker = new ResultChecker(); ResultChecker checker = new ResultChecker();
server.start(checker); server.start(checker);