mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 01:44:08 +00:00
update 1.8.5
support doip cluster
This commit is contained in:
parent
dc0671cfbd
commit
723c9c7a06
@ -6,7 +6,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "org.bdware.sc"
|
group = "org.bdware.sc"
|
||||||
version = "1.8.3"
|
version = "1.8.5"
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
// options.compilerArgs << '-Xlint:none'
|
// options.compilerArgs << '-Xlint:none'
|
||||||
// options.compilerArgs << '-Xlint:deprecation' << "-Werror"
|
// options.compilerArgs << '-Xlint:deprecation' << "-Werror"
|
||||||
@ -48,7 +48,7 @@ dependencies {
|
|||||||
implementation 'com.sun.mail:javax.mail:1.6.2'
|
implementation 'com.sun.mail:javax.mail:1.6.2'
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
|
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
|
||||||
implementation 'org.bdware.bdcontract:sdk-java:1.0.2'
|
implementation 'org.bdware.bdcontract:sdk-java:1.0.2'
|
||||||
implementation 'org.bdware.doip:doip-audit-tool:1.2.2'
|
implementation 'org.bdware.doip:doip-audit-tool:1.2.4'
|
||||||
implementation 'org.bdware.doip:doip-sdk:1.4.0'
|
implementation 'org.bdware.doip:doip-sdk:1.4.0'
|
||||||
implementation fileTree(dir: 'lib', include: '*.jar')
|
implementation fileTree(dir: 'lib', include: '*.jar')
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
|
@ -3,10 +3,9 @@ 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.JsonDoipMessage;
|
||||||
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
||||||
import org.bdware.doip.codec.doipMessage.DoipResponseCode;
|
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.boundry.ScriptReturnException;
|
import org.bdware.sc.boundry.ScriptReturnException;
|
||||||
@ -25,6 +24,7 @@ public class DOOPAfterExecHandler implements AnnotationHook {
|
|||||||
public DOOPAfterExecHandler(BasicOperations operations) {
|
public DOOPAfterExecHandler(BasicOperations operations) {
|
||||||
jsonResponseRules = getRulesForJsonResponse(operations);
|
jsonResponseRules = getRulesForJsonResponse(operations);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) {
|
public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) {
|
||||||
Object originDoipMsgPacker = argPacks.arg;
|
Object originDoipMsgPacker = argPacks.arg;
|
||||||
@ -32,7 +32,6 @@ public class DOOPAfterExecHandler implements AnnotationHook {
|
|||||||
if (originDoipMsgPacker instanceof DoipMessagePacker) {
|
if (originDoipMsgPacker instanceof DoipMessagePacker) {
|
||||||
DoipMessagePacker doipMessagePacker = (DoipMessagePacker) originDoipMsgPacker;
|
DoipMessagePacker doipMessagePacker = (DoipMessagePacker) originDoipMsgPacker;
|
||||||
originDoipMsg = doipMessagePacker.rawDoipMsg;
|
originDoipMsg = doipMessagePacker.rawDoipMsg;
|
||||||
|
|
||||||
// if http, directly return
|
// if http, directly return
|
||||||
if (doipMessagePacker.source.equals("http")) {
|
if (doipMessagePacker.source.equals("http")) {
|
||||||
return argPacks;
|
return argPacks;
|
||||||
@ -42,26 +41,8 @@ public class DOOPAfterExecHandler implements AnnotationHook {
|
|||||||
// validate json response
|
// validate json response
|
||||||
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;
|
JsonDoipMessage returnedMessage = JsonUtil.fromJson(jsonObjectRes, JsonDoipMessage.class);
|
||||||
String body = jsonObjectRes.get("body") != null ? jsonObjectRes.get("body").getAsString() : null;
|
argPacks.ret = returnedMessage.toResponseDoipMessage(originDoipMsg);
|
||||||
|
|
||||||
// 和HTTP一样,所有需要的字段自己封装,校验规则也比较简单,这里只做简单的包装返回即可!!!
|
|
||||||
if (header != null) {
|
|
||||||
originDoipMsg.header = JsonUtil.fromJson(header, MessageHeader.class);
|
|
||||||
// response字段根据白皮书上的规定,处于header下,人为包装到parameters的response中
|
|
||||||
String headerRespCode = header.get("response") != null ? header.get("response").getAsString() : null;
|
|
||||||
if (headerRespCode != null) {
|
|
||||||
if (originDoipMsg.header.parameters == null)
|
|
||||||
originDoipMsg.header.parameters = new HeaderParameter(null, null);
|
|
||||||
originDoipMsg.header.parameters.response = DoipResponseCode.valueOf(headerRespCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (body != null) {
|
|
||||||
originDoipMsg.body.encodedData = body.getBytes(StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
|
|
||||||
argPacks.ret = originDoipMsg;
|
|
||||||
return argPacks;
|
return argPacks;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -78,9 +59,8 @@ public class DOOPAfterExecHandler implements AnnotationHook {
|
|||||||
case Update:
|
case Update:
|
||||||
case Search:
|
case Search:
|
||||||
case ListOps:
|
case ListOps:
|
||||||
return JsonParser.parseString("{\"!header\":{\"!response\":\"string\"}, \"!body\":\"string\"}");
|
|
||||||
case Delete:
|
case Delete:
|
||||||
return JsonParser.parseString("{\"!header\":{\"!response\":\"string\"}, \"body\":\"string\"}");
|
return JsonParser.parseString("{\"!header\":{\"!response\":\"string\",\"attributes\":{}},\"body\":\"string\"}");
|
||||||
case Extension:
|
case Extension:
|
||||||
case Unknown:
|
case Unknown:
|
||||||
default:
|
default:
|
||||||
|
@ -50,7 +50,11 @@ public class DOOPBeforeExecHandler implements AnnotationHook {
|
|||||||
|
|
||||||
public 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 = null;
|
||||||
|
if (originArgs.isJsonObject())
|
||||||
|
httpArgs = originArgs;
|
||||||
|
else
|
||||||
|
httpArgs = JsonParser.parseString(originArgs.getAsString());
|
||||||
// get args rules and validate http args
|
// get args rules and validate http args
|
||||||
ArgSchemaVisitor visitor = new ArgSchemaVisitor(httpArgs);
|
ArgSchemaVisitor visitor = new ArgSchemaVisitor(httpArgs);
|
||||||
validateJsonElementRulesByArgSchemaVisitor(httpArgsRules, visitor);
|
validateJsonElementRulesByArgSchemaVisitor(httpArgsRules, visitor);
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package org.bdware.sc.entity;
|
package org.bdware.sc.entity;
|
||||||
|
|
||||||
|
import org.bdware.doip.codec.JsonDoipMessage;
|
||||||
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
||||||
|
import org.bdware.sc.engine.JSONTool;
|
||||||
|
import org.bdware.sc.util.JsonUtil;
|
||||||
|
|
||||||
public class DoipMessagePacker {
|
public class DoipMessagePacker {
|
||||||
// the DoipMessagePacker is raised by http/doip
|
// the DoipMessagePacker is raised by http/doip
|
||||||
@ -8,7 +11,8 @@ public class DoipMessagePacker {
|
|||||||
// the well-composed DoipMessage
|
// the well-composed DoipMessage
|
||||||
public DoipMessage rawDoipMsg;
|
public DoipMessage rawDoipMsg;
|
||||||
|
|
||||||
public DoipMessagePacker() {}
|
public DoipMessagePacker() {
|
||||||
|
}
|
||||||
|
|
||||||
public DoipMessagePacker(String source, DoipMessage rawMsg) {
|
public DoipMessagePacker(String source, DoipMessage rawMsg) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
@ -22,4 +26,8 @@ public class DoipMessagePacker {
|
|||||||
public void setSource(String source) {
|
public void setSource(String source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object toJSObject() {
|
||||||
|
return JSONTool.convertJsonElementToMirror(JsonUtil.parseObject(JsonDoipMessage.fromDoipMessage(rawDoipMsg)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
||||||
|
import org.bdware.doip.codec.doipMessage.DoipMessageFactory;
|
||||||
|
import org.bdware.doip.codec.doipMessage.DoipResponseCode;
|
||||||
import org.bdware.doip.codec.doipMessage.HeaderParameter;
|
import org.bdware.doip.codec.doipMessage.HeaderParameter;
|
||||||
import org.bdware.doip.codec.operations.BasicOperations;
|
import org.bdware.doip.codec.operations.BasicOperations;
|
||||||
import org.bdware.doip.endpoint.server.DoipRequestHandler;
|
import org.bdware.doip.endpoint.server.DoipRequestHandler;
|
||||||
@ -16,6 +18,9 @@ import org.bdware.sc.boundry.JavaScriptEntry;
|
|||||||
import org.bdware.sc.entity.DoipMessagePacker;
|
import org.bdware.sc.entity.DoipMessagePacker;
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.node.FunctionNode;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.io.PrintStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -38,6 +43,22 @@ public class DOOPRequestHandler implements DoipRequestHandler, RepositoryHandler
|
|||||||
@Override
|
@Override
|
||||||
public DoipMessage onRequest(ChannelHandlerContext ctx, DoipMessage msg) {
|
public DoipMessage onRequest(ChannelHandlerContext ctx, DoipMessage msg) {
|
||||||
String str = msg.header.parameters.operation;
|
String str = msg.header.parameters.operation;
|
||||||
|
if (msg.header != null && msg.header.parameters.attributes != null && msg.header.parameters.attributes.has("readGlobalVar")) {
|
||||||
|
try {
|
||||||
|
//TODO @wangxuxing
|
||||||
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
|
ObjectOutputStream out = new ObjectOutputStream(bo);
|
||||||
|
String var = msg.header.parameters.attributes.get("readGlobalVar").getAsString();
|
||||||
|
Object result = null;
|
||||||
|
out.writeObject(result);
|
||||||
|
DoipMessageFactory.DoipMessageBuilder builder = new DoipMessageFactory.DoipMessageBuilder();
|
||||||
|
builder.createResponse(DoipResponseCode.Success, msg);
|
||||||
|
builder.setBody(bo.toByteArray());
|
||||||
|
return builder.create();
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
//return ....
|
||||||
|
}
|
||||||
logger.debug("[Call operation] name: " + str);
|
logger.debug("[Call operation] name: " + str);
|
||||||
if (str != null) {
|
if (str != null) {
|
||||||
FunctionNode fn;
|
FunctionNode fn;
|
||||||
@ -142,11 +163,15 @@ public class DOOPRequestHandler implements DoipRequestHandler, RepositoryHandler
|
|||||||
finalDoipMsg.header.parameters.attributes.addProperty("nodeID", String.valueOf(JavaScriptEntry.shardingID));
|
finalDoipMsg.header.parameters.attributes.addProperty("nodeID", String.valueOf(JavaScriptEntry.shardingID));
|
||||||
return finalDoipMsg;
|
return finalDoipMsg;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
|
e.printStackTrace(new PrintStream(bo));
|
||||||
|
DoipMessageFactory.DoipMessageBuilder builder = new DoipMessageFactory.DoipMessageBuilder();
|
||||||
|
builder.createResponse(DoipResponseCode.Declined, msg);
|
||||||
|
builder.setBody(bo.toByteArray());
|
||||||
|
DoipMessage message = builder.create();
|
||||||
logger.error("buildRequestAndInvokeEngine has something wrong, executeWithoutLock err or validateJsonElementRulesByArgSchemaVisitor err");
|
logger.error("buildRequestAndInvokeEngine has something wrong, executeWithoutLock err or validateJsonElementRulesByArgSchemaVisitor err");
|
||||||
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContractRequest constructContractRequest(FunctionNode fn, DoipMessage request) {
|
public ContractRequest constructContractRequest(FunctionNode fn, DoipMessage request) {
|
||||||
|
Loading…
Reference in New Issue
Block a user