mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 01:44:08 +00:00
add auto type convert in ArgSchema
This commit is contained in:
parent
64cdfecd67
commit
9317385bd9
10
build.gradle
10
build.gradle
@ -6,7 +6,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "org.bdware.sc"
|
||||
version = "1.6.7"
|
||||
version = "1.6.91"
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
@ -42,8 +42,8 @@ dependencies {
|
||||
implementation 'org.jsoup:jsoup:1.14.2'
|
||||
implementation 'com.sun.mail:javax.mail:1.6.2'
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
|
||||
implementation 'org.bdware.bdcontract:sdk-java:1.0.0'
|
||||
implementation 'org.bdware.doip:doip-audit-tool:1.0.8'
|
||||
implementation 'org.bdware.bdcontract:sdk-java:1.0.2'
|
||||
implementation 'org.bdware.doip:doip-audit-tool:1.1.3'
|
||||
implementation fileTree(dir: 'lib', include: '*.jar')
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
}
|
||||
@ -61,8 +61,8 @@ jar {
|
||||
// uncomment this when publish,
|
||||
//while develop at local use "false"
|
||||
configurations.runtimeClasspath.filter {
|
||||
it.getAbsolutePath().contains("/lib/")
|
||||
// false
|
||||
// it.getAbsolutePath().contains("/lib/")
|
||||
false
|
||||
}.collect {
|
||||
it.isDirectory() ? it : zipTree(it)
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.bdware.sc.boundry;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import groovy.util.ScriptException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bdware.sc.ContractProcess;
|
||||
@ -19,7 +18,6 @@ import org.bdware.sc.util.HashUtil;
|
||||
import org.bdware.sc.util.JsonUtil;
|
||||
import org.zz.gmhelper.SM2KeyPair;
|
||||
import wrp.jdk.nashorn.api.scripting.NashornScriptEngine;
|
||||
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||
import wrp.jdk.nashorn.internal.objects.Global;
|
||||
import wrp.jdk.nashorn.internal.runtime.PropertyMap;
|
||||
import wrp.jdk.nashorn.internal.runtime.ScriptFunction;
|
||||
@ -391,10 +389,10 @@ public class JavaScriptEntry {
|
||||
* @author Kaidong Wu
|
||||
*/
|
||||
public static String subscribe(String topic, ScriptFunction fun) {
|
||||
subscribe(topic, fun, false);
|
||||
if (topic_handlers.containsKey(topic)) {
|
||||
ContractProcess.instance.unSubscribe(topic_handlers.get(topic).getName());
|
||||
}
|
||||
subscribe(topic, fun, false);
|
||||
topic_handlers.put(topic, fun);
|
||||
return topic;
|
||||
}
|
||||
|
@ -4,18 +4,9 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class ScriptReturnException extends IllegalStateException {
|
||||
// public String message1;
|
||||
// public int code;
|
||||
public JsonObject message;
|
||||
public ScriptReturnException(JsonElement jsonElement) {
|
||||
message=jsonElement.getAsJsonObject();
|
||||
// message=jo.get("msg").getAsString();
|
||||
// code=jo.get("code").getAsInt();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String getMessage() {
|
||||
// return this.message1;
|
||||
//
|
||||
// }
|
||||
public ScriptReturnException(JsonElement jsonElement) {
|
||||
message = jsonElement.getAsJsonObject();
|
||||
}
|
||||
}
|
||||
|
@ -271,7 +271,6 @@ public class DesktopEngine extends JSEngine {
|
||||
ScriptEngine.FILENAME,
|
||||
fun.getFileName(),
|
||||
ScriptContext.ENGINE_SCOPE);
|
||||
LOGGER.info("loadFun:" + str);
|
||||
compileFunction(fun, str, isInsnLimit);
|
||||
} catch (ScriptException e) {
|
||||
return wrapperException(e, fun);
|
||||
@ -427,7 +426,14 @@ public class DesktopEngine extends JSEngine {
|
||||
Method getGeneric = ScriptFunctionData.class.getDeclaredMethod("getGenericInvoker", ScriptObject.class);
|
||||
getGeneric.setAccessible(true);
|
||||
MethodHandle methodHandle = (MethodHandle) getGeneric.invoke(scriptFunctioNData, scope);
|
||||
if (methodHandle.getClass() != Class.forName("java.lang.invoke.DirectMethodHandle")) {
|
||||
Field argL0 = methodHandle.getClass().getDeclaredField("argL0");
|
||||
argL0.setAccessible(true);
|
||||
methodHandle = (MethodHandle) argL0.get(methodHandle);
|
||||
|
||||
}
|
||||
Field memberNameField = methodHandle.getClass().getDeclaredField("member");
|
||||
|
||||
memberNameField.setAccessible(true);
|
||||
Object memberName = memberNameField.get(methodHandle);
|
||||
Field clazz = memberName.getClass().getDeclaredField("clazz");
|
||||
@ -437,6 +443,7 @@ public class DesktopEngine extends JSEngine {
|
||||
functionNode.compiledClazz = clazz2;
|
||||
//functionNode==null --> event functions
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (globalChanged) Context.setGlobal(oldGlobal);
|
||||
|
@ -20,7 +20,6 @@ public class ArgSchemaHandler implements AnnotationHook {
|
||||
public ArgSchemaHandler(AnnotationNode annoNode) {
|
||||
a = annoNode;
|
||||
String arg = a.getArgs().get(0);
|
||||
|
||||
// if (arg.startsWith("/")){
|
||||
// ;//ContractProcess.instance.engine.getResources().loadAsString(arg);
|
||||
// }else {
|
||||
@ -39,8 +38,20 @@ public class ArgSchemaHandler implements AnnotationHook {
|
||||
ArgSchemaVisitor visitor;
|
||||
if (je.isJsonObject())
|
||||
visitor = new ArgSchemaVisitor(input.getArg().getAsJsonObject());
|
||||
else
|
||||
visitor = new ArgSchemaVisitor(JsonParser.parseString(input.getArg().getAsString()));
|
||||
else {
|
||||
try {
|
||||
JsonElement obj = JsonParser.parseString(input.getArg().getAsString());
|
||||
visitor = new ArgSchemaVisitor(obj);
|
||||
//IMPORTANT automatically convert arg type here
|
||||
input.setArg(obj);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JsonObject jo = new JsonObject();
|
||||
jo.addProperty("msg", "[Illegal Type] argument should be JSON");
|
||||
jo.addProperty("code", 1004);
|
||||
throw new ScriptReturnException(jo);
|
||||
}
|
||||
}
|
||||
if (je.toString().isEmpty() && !a.getArgs().get(0).equals("")) {
|
||||
JsonObject jo = new JsonObject();
|
||||
jo.addProperty("msg", "[Empty argument] argument should not be empty");
|
||||
|
@ -1,13 +1,9 @@
|
||||
package org.bdware.sc.engine.hook;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import org.bdware.sc.JSEngine;
|
||||
import org.bdware.sc.bean.ContractRequest;
|
||||
import org.bdware.sc.engine.JSONTool;
|
||||
import org.bdware.sc.node.AnnotationHook;
|
||||
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||
|
||||
public class ObjToJsonHandler implements AnnotationHook {
|
||||
@Override
|
||||
|
@ -5,6 +5,6 @@ appender.console.name=STDOUT
|
||||
appender.console.layout.type=PatternLayout
|
||||
appender.console.layout.pattern=%highlight{[%-5p] %d{HH:mm:ss.SSS} %m (%F:%L)[%M]%n}{FATAL=Bright Red,ERROR=Red,WARN=Yellow,INFO=Green,DEBUG=Blue,TRACE=White}
|
||||
|
||||
rootLogger.level=error
|
||||
rootLogger.level=info
|
||||
rootLogger.appenderRef.stdout.ref=STDOUT
|
||||
rootLogger.appenderRef.stdout.level=error
|
||||
rootLogger.appenderRef.stdout.level=info
|
||||
|
Loading…
Reference in New Issue
Block a user