mirror of
https://gitee.com/BDWare/front-base
synced 2025-04-29 07:12:16 +00:00
Compare commits
No commits in common. "master" and "v1.6.6" have entirely different histories.
86
build.gradle
86
build.gradle
@ -1,10 +1,7 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'java-library'
|
id 'java-library'
|
||||||
id 'maven-publish'
|
|
||||||
id 'signing'
|
|
||||||
}
|
}
|
||||||
apply from: '../spotless.gradle'
|
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
@ -26,87 +23,8 @@ sourceSets {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
api project (":common")
|
api project (":common")
|
||||||
api 'io.netty:netty-tcnative-boringssl-static:2.0.59.Final'
|
api 'io.netty:netty-tcnative-boringssl-static:2.0.46.Final'
|
||||||
api 'com.google.code.gson:gson:2.8.8'
|
api 'com.google.code.gson:gson:2.8.8'
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
}
|
}
|
||||||
version = "1.0.1"
|
|
||||||
task classJar(type: Jar, dependsOn: classes) {
|
|
||||||
classifier = "jar"
|
|
||||||
}
|
|
||||||
task sourceJar(type: Jar, dependsOn: classes) {
|
|
||||||
archiveClassifier = "sources"
|
|
||||||
classifier = "sources"
|
|
||||||
from sourceSets.main.allSource
|
|
||||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType(Javadoc) {
|
|
||||||
options.addStringOption('Xdoclint:none', '-quiet')
|
|
||||||
}
|
|
||||||
|
|
||||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
|
||||||
archiveClassifier = 'javadoc'
|
|
||||||
classifier = "javadoc"
|
|
||||||
exclude {
|
|
||||||
details -> details.file.getAbsolutePath().contains("/gm/")
|
|
||||||
}
|
|
||||||
from javadoc.destinationDir
|
|
||||||
}
|
|
||||||
publishing {
|
|
||||||
publications {
|
|
||||||
mavenJava(MavenPublication) {
|
|
||||||
groupId project.group
|
|
||||||
artifactId "front-base"
|
|
||||||
version "${version}"
|
|
||||||
from components.java
|
|
||||||
artifact sourceJar
|
|
||||||
artifact javadocJar
|
|
||||||
artifact classJar
|
|
||||||
pom {
|
|
||||||
name = "bdware-front-base"
|
|
||||||
description = "front-base"
|
|
||||||
url = "https://gitee.com/BDWare/front-base"
|
|
||||||
licenses {
|
|
||||||
license {
|
|
||||||
name = "Mulan PSL v2"
|
|
||||||
url = "http://license.coscl.org.cn/MulanPSL2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
developers {
|
|
||||||
developer {
|
|
||||||
id = "dataware"
|
|
||||||
email = "caihq@pku.edu.cn"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
scm {
|
|
||||||
connection = "scm:git:https://gitee.com/BDWare/front-base.git"
|
|
||||||
developerConnection = "scm:git:https://gitee.com/BDWare/front-base.git"
|
|
||||||
url = "https://gitee.com/BDWare/front-base"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
repositories {
|
|
||||||
maven {
|
|
||||||
name 'bdwareSnapshot'
|
|
||||||
url 'https://oss.sonatype.org/content/repositories/snapshots'
|
|
||||||
credentials {
|
|
||||||
username = "${NEXUS_USERNAME}"
|
|
||||||
password = "${NEXUS_PASSWORD}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
maven {
|
|
||||||
name 'bdware'
|
|
||||||
url 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
|
|
||||||
credentials {
|
|
||||||
username = "${NEXUS_USERNAME}"
|
|
||||||
password = "${NEXUS_PASSWORD}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
signing {
|
|
||||||
sign publishing.publications.mavenJava
|
|
||||||
}
|
|
@ -4,7 +4,8 @@ public class ByteHexUtil {
|
|||||||
protected static final char[] hexArray = "0123456789ABCDEF".toCharArray();
|
protected static final char[] hexArray = "0123456789ABCDEF".toCharArray();
|
||||||
// lower ascii only
|
// lower ascii only
|
||||||
private static final int[] HEX_TO_INT =
|
private static final int[] HEX_TO_INT =
|
||||||
new int[] {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0-15
|
new int[]{
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0-15
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 16-31
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 16-31
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 32-47
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 32-47
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, // 48-63
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, // 48-63
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package org.bdware.server;
|
package org.bdware.server;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
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.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
@ -18,15 +17,16 @@ public class CMDConf {
|
|||||||
|
|
||||||
public String cmi = "";
|
public String cmi = "";
|
||||||
public String debug = "";
|
public String debug = "";
|
||||||
public String repoDoid = "";
|
public boolean disableDoRepo = false;
|
||||||
public String lhsAddress = "";
|
public boolean disableLocalLhs = false;
|
||||||
public String repoName;
|
public String doipCertPath = "";
|
||||||
|
public String doipLhsAddress = "";
|
||||||
public int doipPort = -1;
|
public int doipPort = -1;
|
||||||
|
public String doipUserHandle = "";
|
||||||
public boolean enableEventPersistence = false;
|
public boolean enableEventPersistence = false;
|
||||||
public String enableSsl = "./ssl/chained.pem:./ssl/domain.pem";
|
public String enableSsl = "./ssl/chained.pem:./ssl/domain.pem";
|
||||||
public String ip = "127.0.0.1";
|
public String ip = "127.0.0.1";
|
||||||
|
public boolean isLAN = true;
|
||||||
public boolean overwrite = false;
|
public boolean overwrite = false;
|
||||||
public int servicePort = 18005;
|
public int servicePort = 18005;
|
||||||
public String textFileSuffixes = ".yjs,.json,.txt,.css,.js,.html,.md,.conf,.csv";
|
public String textFileSuffixes = ".yjs,.json,.txt,.css,.js,.html,.md,.conf,.csv";
|
||||||
@ -37,9 +37,6 @@ public class CMDConf {
|
|||||||
public String clientToAgentPlugins = "";
|
public String clientToAgentPlugins = "";
|
||||||
public String clientToClusterPlugins = "";
|
public String clientToClusterPlugins = "";
|
||||||
public String tcpPlugins = "";
|
public String tcpPlugins = "";
|
||||||
public String consistencyPlugins = "";
|
|
||||||
public JsonArray startContract = null;
|
|
||||||
public String datachainConf = null;
|
|
||||||
|
|
||||||
public static CMDConf parseFile(String confPath) {
|
public static CMDConf parseFile(String confPath) {
|
||||||
CMDConf ret = null;
|
CMDConf ret = null;
|
||||||
|
@ -36,10 +36,8 @@ public class Entry {
|
|||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
Process p = Runtime.getRuntime().exec("./bdledger_go");
|
Process p = Runtime.getRuntime().exec("./bdledger_go");
|
||||||
|
|
||||||
BufferedReader stdInput = new BufferedReader(
|
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||||
new InputStreamReader(p.getInputStream()));
|
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
|
||||||
BufferedReader stdError = new BufferedReader(
|
|
||||||
new InputStreamReader(p.getErrorStream()));
|
|
||||||
|
|
||||||
// read the output from the command
|
// read the output from the command
|
||||||
System.out.println("Here is the standard output of the command:\n");
|
System.out.println("Here is the standard output of the command:\n");
|
||||||
@ -48,8 +46,7 @@ public class Entry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read any errors from the attempted command
|
// read any errors from the attempted command
|
||||||
System.out.println(
|
System.out.println("Here is the standard error of the command (if any):\n");
|
||||||
"Here is the standard error of the command (if any):\n");
|
|
||||||
while ((s = stdError.readLine()) != null) {
|
while ((s = stdError.readLine()) != null) {
|
||||||
System.out.println(s);
|
System.out.println(s);
|
||||||
}
|
}
|
||||||
|
@ -84,8 +84,11 @@ public class ActionExecutor<T, U> {
|
|||||||
handlers.put(method.getName(), new Pair<>(method, obj));
|
handlers.put(method.getName(), new Pair<>(method, obj));
|
||||||
if (!method.getReturnType().equals(Void.TYPE)
|
if (!method.getReturnType().equals(Void.TYPE)
|
||||||
|| method.getParameterCount() != 2) {
|
|| method.getParameterCount() != 2) {
|
||||||
LOGGER.error("action ret is not void:"
|
LOGGER.error(
|
||||||
+ obj.getClass().getCanonicalName() + "-->" + method.getName());
|
"action ret is not void:"
|
||||||
|
+ obj.getClass().getCanonicalName()
|
||||||
|
+ "-->"
|
||||||
|
+ method.getName());
|
||||||
|
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
@ -94,8 +97,10 @@ public class ActionExecutor<T, U> {
|
|||||||
handlers.put(a, new Pair<>(method, obj));
|
handlers.put(a, new Pair<>(method, obj));
|
||||||
if (!method.getReturnType().equals(Void.TYPE)
|
if (!method.getReturnType().equals(Void.TYPE)
|
||||||
|| method.getParameterCount() != 2) {
|
|| method.getParameterCount() != 2) {
|
||||||
LOGGER.error("action ret is not void:"
|
LOGGER.error(
|
||||||
+ obj.getClass().getCanonicalName() + "-->"
|
"action ret is not void:"
|
||||||
|
+ obj.getClass().getCanonicalName()
|
||||||
|
+ "-->"
|
||||||
+ method.getName());
|
+ method.getName());
|
||||||
|
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
@ -112,7 +117,7 @@ public class ActionExecutor<T, U> {
|
|||||||
public void handle(String action, final U args, final T callback)
|
public void handle(String action, final U args, final T callback)
|
||||||
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
// LOGGER.info("handling " + action + "...");
|
// LOGGER.info("handling " + action + "...");
|
||||||
// LOGGER.info("handle : " + action + " ->" + JsonUtil.toJson(args));
|
// LOGGER.debug("handle : " + action + " ->" + JsonUtil.toJson(args));
|
||||||
|
|
||||||
if (null != action) {
|
if (null != action) {
|
||||||
if (staticData.containsKey(action)) {
|
if (staticData.containsKey(action)) {
|
||||||
@ -130,7 +135,7 @@ public class ActionExecutor<T, U> {
|
|||||||
final Pair<Method, Object> pair = handlers.get(action);
|
final Pair<Method, Object> pair = handlers.get(action);
|
||||||
Action actionAnnotations = pair.first.getAnnotation(Action.class);
|
Action actionAnnotations = pair.first.getAnnotation(Action.class);
|
||||||
if (!checkPermission(actionAnnotations, args, permission)) {
|
if (!checkPermission(actionAnnotations, args, permission)) {
|
||||||
LOGGER.info("unauthorised action " + action + " -> " + JsonUtil.toJson(args));
|
LOGGER.info("unauthorised action " + action);
|
||||||
throw new IllegalArgumentException("unauthorised action " + action);
|
throw new IllegalArgumentException("unauthorised action " + action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +144,9 @@ public class ActionExecutor<T, U> {
|
|||||||
try {
|
try {
|
||||||
pair.first.invoke(pair.second, args, callback);
|
pair.first.invoke(pair.second, args, callback);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.debug(pair.first.getDeclaringClass().getCanonicalName() + "->"
|
LOGGER.debug(
|
||||||
|
pair.first.getDeclaringClass().getCanonicalName()
|
||||||
|
+ "->"
|
||||||
+ pair.first.getName());
|
+ pair.first.getName());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,7 @@ public class HttpResultCallback extends ResultCallback implements Runnable {
|
|||||||
bytes = ret.getBytes();
|
bytes = ret.getBytes();
|
||||||
}
|
}
|
||||||
assert bytes != null;
|
assert bytes != null;
|
||||||
response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, OK,
|
response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, OK, Unpooled.wrappedBuffer(bytes));
|
||||||
Unpooled.wrappedBuffer(bytes));
|
|
||||||
|
|
||||||
for (String key : extraHeaders.keySet())
|
for (String key : extraHeaders.keySet())
|
||||||
response.headers().add(key, extraHeaders.get(key));
|
response.headers().add(key, extraHeaders.get(key));
|
||||||
@ -59,9 +58,8 @@ public class HttpResultCallback extends ResultCallback implements Runnable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpResultCallback addHeader(String key, String val) {
|
public void addHeader(String key, String val) {
|
||||||
extraHeaders.put(key, val);
|
extraHeaders.put(key, val);
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -75,3 +73,10 @@ public class HttpResultCallback extends ResultCallback implements Runnable {
|
|||||||
decodeAsB64 = true;
|
decodeAsB64 = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
scp ./libs/front-base-0.80.jar dev@023.node.internetapi.cn:./
|
||||||
|
scp ./libs/front-base-0.80.jar dev@021.node.internetapi.cn:./
|
||||||
|
scp ./libs/front-base-0.80.jar dev@024.node.internetapi.cn:./
|
||||||
|
|
||||||
|
|
||||||
|
* */
|
@ -1,89 +0,0 @@
|
|||||||
package org.bdware.server.action;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
|
||||||
import io.netty.handler.codec.http.*;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import java.io.Closeable;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class HttpServerSentEventResultCallback extends HttpResultCallback implements Closeable {
|
|
||||||
public static ScheduledExecutorService scheduledThreadPool =
|
|
||||||
Executors.newScheduledThreadPool(1);
|
|
||||||
private ScheduledFuture<?> currentScheduler;
|
|
||||||
private long lastUpdate;
|
|
||||||
|
|
||||||
public HttpServerSentEventResultCallback(ChannelHandlerContext ctx, String jsonCallback) {
|
|
||||||
super(ctx, jsonCallback);
|
|
||||||
ctxField = ctx;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeInitialHead() {
|
|
||||||
HttpResponse response =
|
|
||||||
new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
|
||||||
for (String key : extraHeaders.keySet())
|
|
||||||
response.headers().add(key, extraHeaders.get(key));
|
|
||||||
ctxField.writeAndFlush(response);
|
|
||||||
currentScheduler = scheduledThreadPool.schedule(this, 10, TimeUnit.SECONDS);
|
|
||||||
final ByteBuf buffer = Unpooled.copiedBuffer("\n", StandardCharsets.UTF_8);
|
|
||||||
ctxField.writeAndFlush(new DefaultHttpContent(buffer));
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean closed = false;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResult(String ret) {
|
|
||||||
ByteBuf event = Unpooled.copiedBuffer("event: onResult\n", StandardCharsets.UTF_8);
|
|
||||||
ctxField.writeAndFlush(new DefaultHttpContent(event));
|
|
||||||
ByteBuf buffer = Unpooled.copiedBuffer("data: " + ret + "\n\n", StandardCharsets.UTF_8);
|
|
||||||
ctxField.writeAndFlush(new DefaultHttpContent(buffer));
|
|
||||||
lastUpdate = System.currentTimeMillis();
|
|
||||||
if (ret.contains("\"onDistributeFinish\"")) {
|
|
||||||
lastUpdate = 0;
|
|
||||||
currentScheduler.cancel(true);
|
|
||||||
try {
|
|
||||||
close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static Logger LOGGER = LogManager.getLogger(HttpServerSentEventResultCallback.class);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
if (System.currentTimeMillis() - lastUpdate < 10000L) {
|
|
||||||
// reschedule
|
|
||||||
LOGGER.info("Reschedule time out");
|
|
||||||
currentScheduler = scheduledThreadPool.schedule(this, 10, TimeUnit.SECONDS);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!closed) {
|
|
||||||
final ByteBuf buffer = Unpooled.copiedBuffer(
|
|
||||||
"{\"action\":\"onDistributeFinish\",\"progress\":\"-1\",\"data\":\"timeout\"}"
|
|
||||||
+ "\n\n",
|
|
||||||
StandardCharsets.UTF_8);
|
|
||||||
ctxField.writeAndFlush(new DefaultHttpContent(buffer));
|
|
||||||
}
|
|
||||||
close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void close() throws IOException {
|
|
||||||
closed = true;
|
|
||||||
ctxField.close();
|
|
||||||
}
|
|
||||||
}
|
|
@ -15,8 +15,7 @@ public class ReplyUtil {
|
|||||||
resultCallback.onResult(ret);
|
resultCallback.onResult(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void replyWithStatus(ResultCallback resultCallback, String action, boolean status,
|
public static void replyWithStatus(ResultCallback resultCallback, String action, boolean status,Object data) {
|
||||||
Object data) {
|
|
||||||
Map<String, Object> ret = new HashMap<>();
|
Map<String, Object> ret = new HashMap<>();
|
||||||
ret.put("action", action);
|
ret.put("action", action);
|
||||||
ret.put("status",status);
|
ret.put("status",status);
|
||||||
|
@ -19,8 +19,11 @@ import java.util.concurrent.Executors;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class SyncResult {
|
public class SyncResult {
|
||||||
public static final HashedWheelTimer timer =
|
public static final HashedWheelTimer timer = new HashedWheelTimer(
|
||||||
new HashedWheelTimer(Executors.defaultThreadFactory(), 5, TimeUnit.MILLISECONDS, 2);
|
Executors.defaultThreadFactory(),
|
||||||
|
5,
|
||||||
|
TimeUnit.MILLISECONDS,
|
||||||
|
2);
|
||||||
private static final Logger LOGGER = LogManager.getLogger(SyncResult.class);
|
private static final Logger LOGGER = LogManager.getLogger(SyncResult.class);
|
||||||
public Map<String, ResultCallback> waitObj = new ConcurrentHashMap<>();
|
public Map<String, ResultCallback> waitObj = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@ -35,8 +38,10 @@ public class SyncResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void instrumentWakeUp(String requestID,
|
public void instrumentWakeUp(
|
||||||
InstrumentedResultCallback instrumentedResultCallback, JsonObject result) {
|
String requestID,
|
||||||
|
InstrumentedResultCallback instrumentedResultCallback,
|
||||||
|
JsonObject result) {
|
||||||
ResultCallback ob = waitObj.get(requestID);
|
ResultCallback ob = waitObj.get(requestID);
|
||||||
// TODO 难怪之前这是注释的。
|
// TODO 难怪之前这是注释的。
|
||||||
waitObj.remove(requestID);
|
waitObj.remove(requestID);
|
||||||
|
@ -1,100 +0,0 @@
|
|||||||
package org.bdware.server.http;
|
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import io.netty.buffer.ByteBufInputStream;
|
|
||||||
import io.netty.handler.codec.http.FullHttpRequest;
|
|
||||||
import io.netty.handler.codec.http.QueryStringDecoder;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.bdware.sc.util.ExceptionUtil;
|
|
||||||
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
|
||||||
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
|
||||||
import org.zz.gmhelper.BCECUtil;
|
|
||||||
import org.zz.gmhelper.SM2Util;
|
|
||||||
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ArgParser {
|
|
||||||
|
|
||||||
public interface VerifiedCallback {
|
|
||||||
void onResult(boolean verified, JsonObject param);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(ArgParser.class);
|
|
||||||
|
|
||||||
public static JsonObject parseGetAndVerify(FullHttpRequest msg, VerifiedCallback cb)
|
|
||||||
throws Exception {
|
|
||||||
QueryStringDecoder decoderQuery = new QueryStringDecoder(msg.uri());
|
|
||||||
Map<String, List<String>> parameters = decoderQuery.parameters();
|
|
||||||
JsonObject transformedParam = new JsonObject();
|
|
||||||
for (String key : parameters.keySet()) {
|
|
||||||
List<String> val = parameters.get(key);
|
|
||||||
if (null != val) {
|
|
||||||
transformedParam.addProperty(key, val.get(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 匿名用户权限为0
|
|
||||||
transformedParam.addProperty("permission", 0);
|
|
||||||
transformedParam.remove("verifiedPubKey");
|
|
||||||
// 验签 有pubKey就必须有sign
|
|
||||||
String uri = URLDecoder.decode(msg.uri(), "UTF-8").split("\\?")[1];
|
|
||||||
int index = uri.lastIndexOf('&');
|
|
||||||
if (index >= 0)
|
|
||||||
verifyParam(transformedParam, uri.substring(0, index), cb);
|
|
||||||
return transformedParam;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void verifyParam(JsonObject transformedParam, String toVerifyStr,
|
|
||||||
VerifiedCallback cb) {
|
|
||||||
boolean verify = false;
|
|
||||||
if (transformedParam.has("pubKey")) {
|
|
||||||
LOGGER.info("before verifying: " + toVerifyStr);
|
|
||||||
try {
|
|
||||||
ECPublicKeyParameters pubKey = BCECUtil.createECPublicKeyFromStrParameters(
|
|
||||||
transformedParam.get("pubKey").getAsString(), SM2Util.CURVE,
|
|
||||||
SM2Util.DOMAIN_PARAMS);
|
|
||||||
verify = SM2Util.verify(pubKey, toVerifyStr.getBytes(),
|
|
||||||
ByteUtils.fromHexString(transformedParam.get("sign").getAsString()));
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOGGER.error(e.getMessage());
|
|
||||||
LOGGER.debug(ExceptionUtil.exceptionToString(e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cb != null)
|
|
||||||
cb.onResult(verify, transformedParam);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JsonObject parsePostAndVerify(FullHttpRequest msg, VerifiedCallback cb)
|
|
||||||
throws Exception {
|
|
||||||
ByteBuf content = msg.content();
|
|
||||||
JsonObject map =
|
|
||||||
JsonParser.parseReader(new InputStreamReader(new ByteBufInputStream(content)))
|
|
||||||
.getAsJsonObject();
|
|
||||||
StringBuilder toSign = new StringBuilder();
|
|
||||||
boolean isFirst = true;
|
|
||||||
for (String key : map.keySet()) {
|
|
||||||
if (!key.equals("sign")) {
|
|
||||||
if (!isFirst)
|
|
||||||
toSign.append("&");
|
|
||||||
isFirst = false;
|
|
||||||
toSign.append(key).append("=");
|
|
||||||
JsonElement je = map.get(key);
|
|
||||||
if (je.isJsonPrimitive())
|
|
||||||
toSign.append(je.getAsString());
|
|
||||||
else
|
|
||||||
toSign.append(je.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
verifyParam(map, toSign.toString(), cb);
|
|
||||||
return map;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,8 +24,7 @@ public class FileDownloaderCallback extends HttpResultCallback {
|
|||||||
public void onResult(final String filePath) {
|
public void onResult(final String filePath) {
|
||||||
try {
|
try {
|
||||||
final RandomAccessFile file = new RandomAccessFile(filePath, "r");
|
final RandomAccessFile file = new RandomAccessFile(filePath, "r");
|
||||||
HttpResponse response =
|
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
||||||
new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
|
||||||
// 设置文件格式内容
|
// 设置文件格式内容
|
||||||
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/x-msdownload");
|
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/x-msdownload");
|
||||||
response.headers().set(HttpHeaderNames.CONTENT_DISPOSITION,
|
response.headers().set(HttpHeaderNames.CONTENT_DISPOSITION,
|
||||||
@ -34,14 +33,13 @@ public class FileDownloaderCallback extends HttpResultCallback {
|
|||||||
HttpUtil.setContentLength(response, file.length());
|
HttpUtil.setContentLength(response, file.length());
|
||||||
LOGGER.debug("FileLength:" + file.length());
|
LOGGER.debug("FileLength:" + file.length());
|
||||||
ctxField.write(response);
|
ctxField.write(response);
|
||||||
ChannelFuture future =
|
ChannelFuture future = ctxField.write(new DefaultFileRegion(file.getChannel(), 0, file.length()),
|
||||||
ctxField.write(new DefaultFileRegion(file.getChannel(), 0, file.length()),
|
|
||||||
ctxField.newProgressivePromise());
|
ctxField.newProgressivePromise());
|
||||||
ctxField.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
|
ctxField.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
|
||||||
future.addListener(new ChannelProgressiveFutureListener() {
|
future.addListener(new ChannelProgressiveFutureListener() {
|
||||||
@Override
|
@Override
|
||||||
public void operationProgressed(ChannelProgressiveFuture future, long progress,
|
public void operationProgressed(ChannelProgressiveFuture future, long progress, long total) {
|
||||||
long total) {}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void operationComplete(ChannelProgressiveFuture future) throws Exception {
|
public void operationComplete(ChannelProgressiveFuture future) throws Exception {
|
||||||
|
@ -24,8 +24,12 @@ public class HttpFileHandleAdapter extends SimpleChannelInboundHandler<FullHttpR
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
|
public static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
|
||||||
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, status,
|
FullHttpResponse response =
|
||||||
Unpooled.wrappedBuffer(("Failure: " + status + "\r\n").getBytes()));
|
new DefaultFullHttpResponse(
|
||||||
|
HTTP_1_1,
|
||||||
|
status,
|
||||||
|
Unpooled.wrappedBuffer(
|
||||||
|
("Failure: " + status + "\r\n").getBytes()));
|
||||||
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8");
|
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8");
|
||||||
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
|
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
|
||||||
}
|
}
|
||||||
@ -40,9 +44,7 @@ public class HttpFileHandleAdapter extends SimpleChannelInboundHandler<FullHttpR
|
|||||||
} else if (path.endsWith(".ico")) {
|
} else if (path.endsWith(".ico")) {
|
||||||
headers.set(HttpHeaderNames.CONTENT_TYPE, "image/x-icon;");
|
headers.set(HttpHeaderNames.CONTENT_TYPE, "image/x-icon;");
|
||||||
} else if (path.endsWith(".svg")) {
|
} else if (path.endsWith(".svg")) {
|
||||||
headers.set(HttpHeaderNames.CONTENT_TYPE, "image/svg+xml;charset=utf-8");
|
headers.set(HttpHeaderNames.CONTENT_TYPE, "text/xml;charset=utf-8");
|
||||||
} else if (path.endsWith(".ypk")) {
|
|
||||||
headers.set(HttpHeaderNames.CONTENT_TYPE, "application/ypk");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
package org.bdware.server.http;
|
package org.bdware.server.http;
|
||||||
|
|
||||||
public enum HttpMethod {
|
public enum HttpMethod {
|
||||||
OPTIONS, GET, HEAD, POST, PUT, PATCH, DELETE, TRACE, CONNECT;
|
OPTIONS,
|
||||||
|
GET,
|
||||||
|
HEAD,
|
||||||
|
POST,
|
||||||
|
PUT,
|
||||||
|
PATCH,
|
||||||
|
DELETE,
|
||||||
|
TRACE,
|
||||||
|
CONNECT;
|
||||||
|
|
||||||
io.netty.handler.codec.http.HttpMethod get() {
|
io.netty.handler.codec.http.HttpMethod get() {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
|
@ -17,7 +17,7 @@ import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
|||||||
|
|
||||||
public class URIHandler {
|
public class URIHandler {
|
||||||
private static final Logger LOGGER = LogManager.getLogger(URIHandler.class);
|
private static final Logger LOGGER = LogManager.getLogger(URIHandler.class);
|
||||||
private Map<io.netty.handler.codec.http.HttpMethod, List<Tuple<String, Method, Object>>> handlers;
|
Map<io.netty.handler.codec.http.HttpMethod, List<Tuple<String, Method, Object>>> handlers;
|
||||||
|
|
||||||
public URIHandler() {
|
public URIHandler() {
|
||||||
handlers = new HashMap<>();
|
handlers = new HashMap<>();
|
||||||
@ -59,26 +59,14 @@ public class URIHandler {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tuple<String, Method, Object> findHandler(FullHttpRequest msg) {
|
public void handle(ChannelHandlerContext ctx, FullHttpRequest msg) {
|
||||||
|
try {
|
||||||
List<Tuple<String, Method, Object>> handlerList = handlers.get(msg.method());
|
List<Tuple<String, Method, Object>> handlerList = handlers.get(msg.method());
|
||||||
for (Tuple<String, Method, Object> t : handlerList)
|
for (Tuple<String, Method, Object> t : handlerList)
|
||||||
if (msg.uri().startsWith(t.t)) {
|
if (msg.uri().startsWith(t.t)) {
|
||||||
return t;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handle(ChannelHandlerContext ctx, FullHttpRequest msg) {
|
|
||||||
Tuple<String, Method, Object> t = findHandler(msg);
|
|
||||||
handle(ctx, msg, t);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handle(ChannelHandlerContext ctx, FullHttpRequest msg,
|
|
||||||
Tuple<String, Method, Object> t) {
|
|
||||||
try {
|
|
||||||
if (t != null)
|
|
||||||
t.u.invoke(t.s, ctx, msg);
|
t.u.invoke(t.s, ctx, msg);
|
||||||
else
|
return;
|
||||||
|
}
|
||||||
sendUnsupported(ctx);
|
sendUnsupported(ctx);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -92,25 +80,29 @@ public class URIHandler {
|
|||||||
for (Tuple<String, Method, Object> t : handlers.get(m)) {
|
for (Tuple<String, Method, Object> t : handlers.get(m)) {
|
||||||
String className = t.u.getDeclaringClass().getSimpleName();
|
String className = t.u.getDeclaringClass().getSimpleName();
|
||||||
sbl.append("\t\t").append(t.t.isEmpty() ? "<null>" : t.t).append(" --> ")
|
sbl.append("\t\t").append(t.t.isEmpty() ? "<null>" : t.t).append(" --> ")
|
||||||
.append(className.isEmpty() ? "null" : className).append(".")
|
.append(className.isEmpty() ? "null" : className)
|
||||||
.append(t.u.getName()).append("\n");
|
.append(".").append(t.u.getName()).append("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.info(sbl.substring(0, sbl.length() - 1));
|
LOGGER.info(sbl.substring(0, sbl.length() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendUnsupported(ChannelHandlerContext ctx) {
|
private void sendUnsupported(ChannelHandlerContext ctx) {
|
||||||
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1,
|
FullHttpResponse response =
|
||||||
HttpResponseStatus.BAD_REQUEST, Unpooled.wrappedBuffer(
|
new DefaultFullHttpResponse(
|
||||||
("Failure: " + HttpResponseStatus.BAD_REQUEST + "\r\n").getBytes()));
|
HTTP_1_1,
|
||||||
|
HttpResponseStatus.BAD_REQUEST,
|
||||||
|
Unpooled.wrappedBuffer(
|
||||||
|
("Failure: " + HttpResponseStatus.BAD_REQUEST + "\r\n")
|
||||||
|
.getBytes()));
|
||||||
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8");
|
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8");
|
||||||
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
|
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Tuple<T, U, S> {
|
static class Tuple<T, U, S> {
|
||||||
public T t;
|
T t;
|
||||||
public U u;
|
U u;
|
||||||
public S s;
|
S s;
|
||||||
|
|
||||||
Tuple(T t, U u, S s) {
|
Tuple(T t, U u, S s) {
|
||||||
this.t = t;
|
this.t = t;
|
||||||
|
@ -9,6 +9,5 @@ import java.lang.annotation.Target;
|
|||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
public @interface URIPath {
|
public @interface URIPath {
|
||||||
String[] value() default {""};
|
String[] value() default {""};
|
||||||
|
|
||||||
HttpMethod method() default HttpMethod.GET;
|
HttpMethod method() default HttpMethod.GET;
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,9 @@ public class CMNodeBean {
|
|||||||
// TODO nodeMangerPubkey
|
// TODO nodeMangerPubkey
|
||||||
public void updateContract(Map<String, String> json) {
|
public void updateContract(Map<String, String> json) {
|
||||||
String jsonStr = json.get("contracts");
|
String jsonStr = json.get("contracts");
|
||||||
contracts = JsonUtil.fromJson(jsonStr, new TypeToken<List<ContractDesp>>() {}.getType());
|
contracts = JsonUtil.fromJson(jsonStr, new TypeToken<List<ContractDesp>>() {
|
||||||
// KeyValueDBUtil.instance.setValue(NCTables.NodesDB.toString(), pubKey,
|
}.getType());
|
||||||
// JsonUtil.toJson(this));
|
// KeyValueDBUtil.instance.setValue(NCTables.NodesDB.toString(), pubKey, JsonUtil.toJson(this));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,8 +33,7 @@ public class CMNodeBean {
|
|||||||
public String formatContractName(String contractIDOrName) {
|
public String formatContractName(String contractIDOrName) {
|
||||||
if (null != contracts) {
|
if (null != contracts) {
|
||||||
for (ContractDesp desp : contracts) {
|
for (ContractDesp desp : contracts) {
|
||||||
if (desp.contractID.equals(contractIDOrName)
|
if (desp.contractID.equals(contractIDOrName) || desp.contractName.equals(contractIDOrName)) {
|
||||||
|| desp.contractName.equals(contractIDOrName)) {
|
|
||||||
return desp.contractName;
|
return desp.contractName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,8 +44,7 @@ public class CMNodeBean {
|
|||||||
public boolean containsContract(String contractIDOrName) {
|
public boolean containsContract(String contractIDOrName) {
|
||||||
if (null != contracts) {
|
if (null != contracts) {
|
||||||
for (ContractDesp desp : contracts) {
|
for (ContractDesp desp : contracts) {
|
||||||
if (desp.contractID.equals(contractIDOrName)
|
if (desp.contractID.equals(contractIDOrName) || desp.contractName.equals(contractIDOrName))
|
||||||
|| desp.contractName.equals(contractIDOrName))
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,8 +54,7 @@ public class CMNodeBean {
|
|||||||
public boolean containsEvent(String contractIDOrName, String event) {
|
public boolean containsEvent(String contractIDOrName, String event) {
|
||||||
if (null != contracts) {
|
if (null != contracts) {
|
||||||
for (ContractDesp desp : contracts) {
|
for (ContractDesp desp : contracts) {
|
||||||
if (desp.contractID.equals(contractIDOrName)
|
if (desp.contractID.equals(contractIDOrName) || desp.contractName.equals(contractIDOrName)) {
|
||||||
|| desp.contractName.equals(contractIDOrName)) {
|
|
||||||
if (desp.events.containsKey(event))
|
if (desp.events.containsKey(event))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -45,10 +45,16 @@ public enum Permission {
|
|||||||
// TODO: 20205/20 需要整理权限就权限和最新的权限
|
// TODO: 20205/20 需要整理权限就权限和最新的权限
|
||||||
|
|
||||||
// CenterManager (其他部分代码中出现的,暂未合并整理)
|
// CenterManager (其他部分代码中出现的,暂未合并整理)
|
||||||
ApplyRole(1 << 0), NodeStateList(1 << 1), AuthNodeManager(1 << 2), ListAllUsers(
|
ApplyRole(1 << 0),
|
||||||
1 << 3), ListApplyUser(1 << 4), DeleteNodeManager(1 << 5), ListTrustCluster(
|
NodeStateList(1 << 1),
|
||||||
1 << 6), AssignTrustedCluster(
|
AuthNodeManager(1 << 2),
|
||||||
1 << 7), QueryActionLog(1 << 8), QueryUserStateLog(1 << 9),
|
ListAllUsers(1 << 3),
|
||||||
|
ListApplyUser(1 << 4),
|
||||||
|
DeleteNodeManager(1 << 5),
|
||||||
|
ListTrustCluster(1 << 6),
|
||||||
|
AssignTrustedCluster(1 << 7),
|
||||||
|
QueryActionLog(1 << 8),
|
||||||
|
QueryUserStateLog(1 << 9),
|
||||||
|
|
||||||
// Node
|
// Node
|
||||||
ConfigureNode(1 << 10), // 其他地方代码中的权限
|
ConfigureNode(1 << 10), // 其他地方代码中的权限
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
package org.bdware.server.permission;
|
package org.bdware.server.permission;
|
||||||
|
|
||||||
public enum Role {
|
public enum Role {
|
||||||
CenterManager(0x3ffL), NodeManager(0xe41L), Node(0x1L), ContractProvider(
|
CenterManager(0x3ffL),
|
||||||
0x3f000L), ContractInstanceManager(0x7ff10c0L), ContractUser(0x5c0000L), Anonymous(0);
|
NodeManager(0xe41L),
|
||||||
|
Node(0x1L),
|
||||||
|
ContractProvider(0x3f000L),
|
||||||
|
ContractInstanceManager(0x7ff10c0L),
|
||||||
|
ContractUser(0x5c0000L),
|
||||||
|
Anonymous(0);
|
||||||
|
|
||||||
long value;
|
long value;
|
||||||
|
|
||||||
|
@ -5,11 +5,13 @@ import io.netty.buffer.Unpooled;
|
|||||||
import io.netty.channel.CombinedChannelDuplexHandler;
|
import io.netty.channel.CombinedChannelDuplexHandler;
|
||||||
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
|
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
|
||||||
|
|
||||||
public class DelimiterCodec extends
|
public class DelimiterCodec
|
||||||
CombinedChannelDuplexHandler<DelimiterBasedFrameDecoder, DelimiterBasedFrameEncoder> {
|
extends CombinedChannelDuplexHandler<
|
||||||
|
DelimiterBasedFrameDecoder, DelimiterBasedFrameEncoder> {
|
||||||
public DelimiterCodec() {
|
public DelimiterCodec() {
|
||||||
ByteBuf buf = Unpooled.wrappedBuffer(DelimiterBasedFrameEncoder.delimiter);
|
ByteBuf buf = Unpooled.wrappedBuffer(DelimiterBasedFrameEncoder.delimiter);
|
||||||
init(new DelimiterBasedFrameDecoder(10 * 1024 * 1024, buf),
|
init(
|
||||||
|
new DelimiterBasedFrameDecoder(10 * 1024 * 1024, buf),
|
||||||
new DelimiterBasedFrameEncoder());
|
new DelimiterBasedFrameEncoder());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,26 +36,25 @@ public class WebSocketIndexPageHandler extends SimpleChannelInboundHandler<FullH
|
|||||||
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
|
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
|
||||||
// Handle a bad request.
|
// Handle a bad request.
|
||||||
if (!req.getUri().startsWith("/SCIDE/SCExecutor")) {
|
if (!req.getUri().startsWith("/SCIDE/SCExecutor")) {
|
||||||
sendHttpResponse(ctx, req, new DefaultFullHttpResponse(req.protocolVersion(), NOT_FOUND,
|
sendHttpResponse(ctx, req,
|
||||||
ctx.alloc().buffer(0)));
|
new DefaultFullHttpResponse(req.protocolVersion(), NOT_FOUND, ctx.alloc().buffer(0)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!req.decoderResult().isSuccess()) {
|
if (!req.decoderResult().isSuccess()) {
|
||||||
sendHttpResponse(ctx, req, new DefaultFullHttpResponse(req.protocolVersion(),
|
sendHttpResponse(ctx, req,
|
||||||
BAD_REQUEST, ctx.alloc().buffer(0)));
|
new DefaultFullHttpResponse(req.protocolVersion(), BAD_REQUEST, ctx.alloc().buffer(0)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow only GET methods.
|
// Allow only GET methods.
|
||||||
if (!GET.equals(req.method())) {
|
if (!GET.equals(req.method())) {
|
||||||
sendHttpResponse(ctx, req, new DefaultFullHttpResponse(req.protocolVersion(), FORBIDDEN,
|
sendHttpResponse(ctx, req,
|
||||||
ctx.alloc().buffer(0)));
|
new DefaultFullHttpResponse(req.protocolVersion(), FORBIDDEN, ctx.alloc().buffer(0)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the index page
|
// Send the index page
|
||||||
if ("/SCIDE/SCExecutor/".equals(req.uri())
|
if ("/SCIDE/SCExecutor/".equals(req.uri()) || "/SCIDE/SCExecutor/index.html".equals(req.uri())) {
|
||||||
|| "/SCIDE/SCExecutor/index.html".equals(req.uri())) {
|
|
||||||
String webSocketLocation = getWebSocketLocation(ctx.pipeline(), req, websocketPath);
|
String webSocketLocation = getWebSocketLocation(ctx.pipeline(), req, websocketPath);
|
||||||
ByteBuf content = WebSocketServerIndexPage.getContent(webSocketLocation);
|
ByteBuf content = WebSocketServerIndexPage.getContent(webSocketLocation);
|
||||||
FullHttpResponse res = new DefaultFullHttpResponse(req.protocolVersion(), OK, content);
|
FullHttpResponse res = new DefaultFullHttpResponse(req.protocolVersion(), OK, content);
|
||||||
@ -63,8 +62,8 @@ public class WebSocketIndexPageHandler extends SimpleChannelInboundHandler<FullH
|
|||||||
HttpUtil.setContentLength(res, content.readableBytes());
|
HttpUtil.setContentLength(res, content.readableBytes());
|
||||||
sendHttpResponse(ctx, req, res);
|
sendHttpResponse(ctx, req, res);
|
||||||
} else {
|
} else {
|
||||||
sendHttpResponse(ctx, req, new DefaultFullHttpResponse(req.protocolVersion(), NOT_FOUND,
|
sendHttpResponse(ctx, req,
|
||||||
ctx.alloc().buffer(0)));
|
new DefaultFullHttpResponse(req.protocolVersion(), NOT_FOUND, ctx.alloc().buffer(0)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,8 +73,7 @@ public class WebSocketIndexPageHandler extends SimpleChannelInboundHandler<FullH
|
|||||||
ctx.close();
|
ctx.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendHttpResponse(ChannelHandlerContext ctx, FullHttpRequest req,
|
private static void sendHttpResponse(ChannelHandlerContext ctx, FullHttpRequest req, FullHttpResponse res) {
|
||||||
FullHttpResponse res) {
|
|
||||||
// Generate an error page if response getStatus code is not OK (200).
|
// Generate an error page if response getStatus code is not OK (200).
|
||||||
HttpResponseStatus responseStatus = res.status();
|
HttpResponseStatus responseStatus = res.status();
|
||||||
if (responseStatus.code() != 200) {
|
if (responseStatus.code() != 200) {
|
||||||
|
@ -9,33 +9,93 @@ public final class WebSocketServerIndexPage {
|
|||||||
private static final String NEWLINE = "\r\n";
|
private static final String NEWLINE = "\r\n";
|
||||||
|
|
||||||
public static ByteBuf getContent(String webSocketLocation) {
|
public static ByteBuf getContent(String webSocketLocation) {
|
||||||
String str = "<html><head><title>Web Socket Test</title></head>" + NEWLINE + "<body>"
|
String str =
|
||||||
+ NEWLINE + "<script type=\"text/javascript\">" + NEWLINE + "var socket;" + NEWLINE
|
"<html><head><title>Web Socket Test</title></head>"
|
||||||
+ "if (!window.WebSocket) {" + NEWLINE + " window.WebSocket = window.MozWebSocket;"
|
+ NEWLINE
|
||||||
+ NEWLINE + '}' + NEWLINE + "if (window.WebSocket) {" + NEWLINE
|
+ "<body>"
|
||||||
+ " socket = new WebSocket(\"" + webSocketLocation + "\");" + NEWLINE
|
+ NEWLINE
|
||||||
+ " socket.onmessage = function(event) {" + NEWLINE
|
+ "<script type=\"text/javascript\">"
|
||||||
+ " var ta = document.getElementById('responseText');" + NEWLINE
|
+ NEWLINE
|
||||||
+ " ta.value = ta.value + '\\n' + event.data" + NEWLINE + " };" + NEWLINE
|
+ "var socket;"
|
||||||
+ " socket.onopen = function(event) {" + NEWLINE
|
+ NEWLINE
|
||||||
+ " var ta = document.getElementById('responseText');" + NEWLINE
|
+ "if (!window.WebSocket) {"
|
||||||
+ " ta.value = \"Web Socket opened!\";" + NEWLINE + " };" + NEWLINE
|
+ NEWLINE
|
||||||
+ " socket.onclose = function(event) {" + NEWLINE
|
+ " window.WebSocket = window.MozWebSocket;"
|
||||||
+ " var ta = document.getElementById('responseText');" + NEWLINE
|
+ NEWLINE
|
||||||
+ " ta.value = ta.value + \"Web Socket closed\"; " + NEWLINE + " };" + NEWLINE
|
+ '}'
|
||||||
+ "} else {" + NEWLINE + " alert(\"Your browser does not support Web Socket.\");"
|
+ NEWLINE
|
||||||
+ NEWLINE + '}' + NEWLINE + NEWLINE + "function send(message) {" + NEWLINE
|
+ "if (window.WebSocket) {"
|
||||||
+ " if (!window.WebSocket) { return; }" + NEWLINE
|
+ NEWLINE
|
||||||
+ " if (socket.readyState == WebSocket.OPEN) {" + NEWLINE
|
+ " socket = new WebSocket(\""
|
||||||
+ " socket.send(message);" + NEWLINE + " } else {" + NEWLINE
|
+ webSocketLocation
|
||||||
+ " alert(\"The socket is not open.\");" + NEWLINE + " }" + NEWLINE + '}'
|
+ "\");"
|
||||||
+ NEWLINE + "</script>" + NEWLINE + "<form onsubmit=\"return false;\">" + NEWLINE
|
+ NEWLINE
|
||||||
|
+ " socket.onmessage = function(event) {"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " var ta = document.getElementById('responseText');"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " ta.value = ta.value + '\\n' + event.data"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " };"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " socket.onopen = function(event) {"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " var ta = document.getElementById('responseText');"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " ta.value = \"Web Socket opened!\";"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " };"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " socket.onclose = function(event) {"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " var ta = document.getElementById('responseText');"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " ta.value = ta.value + \"Web Socket closed\"; "
|
||||||
|
+ NEWLINE
|
||||||
|
+ " };"
|
||||||
|
+ NEWLINE
|
||||||
|
+ "} else {"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " alert(\"Your browser does not support Web Socket.\");"
|
||||||
|
+ NEWLINE
|
||||||
|
+ '}'
|
||||||
|
+ NEWLINE
|
||||||
|
+ NEWLINE
|
||||||
|
+ "function send(message) {"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " if (!window.WebSocket) { return; }"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " if (socket.readyState == WebSocket.OPEN) {"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " socket.send(message);"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " } else {"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " alert(\"The socket is not open.\");"
|
||||||
|
+ NEWLINE
|
||||||
|
+ " }"
|
||||||
|
+ NEWLINE
|
||||||
|
+ '}'
|
||||||
|
+ NEWLINE
|
||||||
|
+ "</script>"
|
||||||
|
+ NEWLINE
|
||||||
|
+ "<form onsubmit=\"return false;\">"
|
||||||
|
+ NEWLINE
|
||||||
+ "<input type=\"text\" name=\"message\" value=\"Hello, World!\"/>"
|
+ "<input type=\"text\" name=\"message\" value=\"Hello, World!\"/>"
|
||||||
+ "<input type=\"button\" value=\"Send Web Socket Data\"" + NEWLINE
|
+ "<input type=\"button\" value=\"Send Web Socket Data\""
|
||||||
+ " onclick=\"send(this.form.message.value)\" />" + NEWLINE
|
+ NEWLINE
|
||||||
+ "<h3>Output</h3>" + NEWLINE
|
+ " onclick=\"send(this.form.message.value)\" />"
|
||||||
|
+ NEWLINE
|
||||||
|
+ "<h3>Output</h3>"
|
||||||
|
+ NEWLINE
|
||||||
+ "<textarea id=\"responseText\" style=\"width:500px;height:300px;\"></textarea>"
|
+ "<textarea id=\"responseText\" style=\"width:500px;height:300px;\"></textarea>"
|
||||||
+ NEWLINE + "</form>" + NEWLINE + "</body>" + NEWLINE + "</html>" + NEWLINE;
|
+ NEWLINE
|
||||||
|
+ "</form>"
|
||||||
|
+ NEWLINE
|
||||||
|
+ "</body>"
|
||||||
|
+ NEWLINE
|
||||||
|
+ "</html>"
|
||||||
|
+ NEWLINE;
|
||||||
return Unpooled.wrappedBuffer(str.getBytes());
|
return Unpooled.wrappedBuffer(str.getBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +44,7 @@ public class IndexServer {
|
|||||||
.childHandler(new ChannelInitializer<SocketChannel>() {
|
.childHandler(new ChannelInitializer<SocketChannel>() {
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(SocketChannel arg0) throws Exception {
|
protected void initChannel(SocketChannel arg0) throws Exception {
|
||||||
arg0.pipeline().addLast(new HttpServerCodec())
|
arg0.pipeline().addLast(new HttpServerCodec()).addLast(new HttpObjectAggregator(65536))
|
||||||
.addLast(new HttpObjectAggregator(65536))
|
|
||||||
.addLast(new ChunkedWriteHandler()).addLast(serverHandler);
|
.addLast(new ChunkedWriteHandler()).addLast(serverHandler);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -20,7 +20,8 @@ public class IndexAction {
|
|||||||
static final String MISSING_ARGUMENT = "{\"status\":\"Errorr\",\"data\":\"missing arguments\"}";
|
static final String MISSING_ARGUMENT = "{\"status\":\"Errorr\",\"data\":\"missing arguments\"}";
|
||||||
static Map<String, LenVarTimeSerialIndex2> fileMap = new HashMap<>();
|
static Map<String, LenVarTimeSerialIndex2> fileMap = new HashMap<>();
|
||||||
|
|
||||||
public IndexAction() {}
|
public IndexAction() {
|
||||||
|
}
|
||||||
|
|
||||||
@Action(async = true)
|
@Action(async = true)
|
||||||
public void createFile(JsonObject args, final ResultCallback resultCallback) {
|
public void createFile(JsonObject args, final ResultCallback resultCallback) {
|
||||||
@ -41,8 +42,8 @@ public class IndexAction {
|
|||||||
fout.write(1);
|
fout.write(1);
|
||||||
fout.close();
|
fout.close();
|
||||||
// LenVarTimeSerialIndex2 index = getIndexFile(fileName);
|
// LenVarTimeSerialIndex2 index = getIndexFile(fileName);
|
||||||
resultCallback.onResult("{\"status\":\"Success\",\"dataLength\":" + dataLength
|
resultCallback.onResult(
|
||||||
+ ",\".datasize\":" + f.length() + "}");
|
"{\"status\":\"Success\",\"dataLength\":" + dataLength + ",\".datasize\":" + f.length() + "}");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
@ -84,8 +85,7 @@ public class IndexAction {
|
|||||||
try {
|
try {
|
||||||
LenVarTimeSerialIndex2 index = getIndexFile(args.get("file").getAsString());
|
LenVarTimeSerialIndex2 index = getIndexFile(args.get("file").getAsString());
|
||||||
|
|
||||||
resultCallback.onResult(
|
resultCallback.onResult("{\"dataSize\":" + index.dataSize + ",\"fileSize\":" + index.fileSize + "}");
|
||||||
"{\"dataSize\":" + index.dataSize + ",\"fileSize\":" + index.fileSize + "}");
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
|
@ -34,10 +34,11 @@ public class IndexHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
|
|||||||
private static final String UNSUPPORTED_HTTP_METHOD = "{\"msg\":\"unsupported http method\"}";
|
private static final String UNSUPPORTED_HTTP_METHOD = "{\"msg\":\"unsupported http method\"}";
|
||||||
private static final String UNSUPPORTED_ACTION = "{\"msg\":\"unsupported action\"}";
|
private static final String UNSUPPORTED_ACTION = "{\"msg\":\"unsupported action\"}";
|
||||||
private static final Logger LOGGER = LogManager.getLogger(IndexHttpHandler.class);
|
private static final Logger LOGGER = LogManager.getLogger(IndexHttpHandler.class);
|
||||||
private static ActionExecutor<ResultCallback, JsonObject> actionExecutor =
|
private static ActionExecutor<ResultCallback, JsonObject> actionExecutor = new ActionExecutor<>(
|
||||||
new ActionExecutor<>(Executors.newFixedThreadPool(5), new IndexAction());
|
Executors.newFixedThreadPool(5), new IndexAction());
|
||||||
|
|
||||||
public IndexHttpHandler() {}
|
public IndexHttpHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelReadComplete(ChannelHandlerContext ctx) {
|
public void channelReadComplete(ChannelHandlerContext ctx) {
|
||||||
@ -57,8 +58,7 @@ public class IndexHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
|
|||||||
private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest msg) {
|
private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest msg) {
|
||||||
if (!msg.uri().startsWith("/SCIDE/Index")) {
|
if (!msg.uri().startsWith("/SCIDE/Index")) {
|
||||||
try {
|
try {
|
||||||
DefaultFullHttpResponse fullResponse =
|
DefaultFullHttpResponse fullResponse = new DefaultFullHttpResponse(msg.getProtocolVersion(), OK,
|
||||||
new DefaultFullHttpResponse(msg.getProtocolVersion(), OK,
|
|
||||||
Unpooled.wrappedBuffer(UNSUPPORTED_HTTP_METHOD.getBytes()));
|
Unpooled.wrappedBuffer(UNSUPPORTED_HTTP_METHOD.getBytes()));
|
||||||
ChannelFuture f = ctx.write(fullResponse);
|
ChannelFuture f = ctx.write(fullResponse);
|
||||||
f.addListener(ChannelFutureListener.CLOSE);
|
f.addListener(ChannelFutureListener.CLOSE);
|
||||||
@ -109,8 +109,8 @@ public class IndexHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
|
|||||||
String action = null;
|
String action = null;
|
||||||
if (!map.has("action")) {
|
if (!map.has("action")) {
|
||||||
ret = UNSUPPORTED_ACTION.getBytes();
|
ret = UNSUPPORTED_ACTION.getBytes();
|
||||||
DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
|
DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, OK,
|
||||||
OK, Unpooled.wrappedBuffer(ret));
|
Unpooled.wrappedBuffer(ret));
|
||||||
ChannelFuture f = ctx.write(response);
|
ChannelFuture f = ctx.write(response);
|
||||||
f.addListener(ChannelFutureListener.CLOSE);
|
f.addListener(ChannelFutureListener.CLOSE);
|
||||||
return;
|
return;
|
||||||
|
@ -14,22 +14,30 @@ public class URIHandlerTest {
|
|||||||
handler.register(this);
|
handler.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@URIPath(method = HttpMethod.OPTIONS, value = {"/"})
|
@URIPath(
|
||||||
|
method = HttpMethod.OPTIONS,
|
||||||
|
value = {"/"})
|
||||||
public void h1(ChannelHandlerContext ctx, FullHttpRequest request) {
|
public void h1(ChannelHandlerContext ctx, FullHttpRequest request) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@URIPath(method = HttpMethod.GET, value = {"/SCIDE/ABC/", "/SCIDE/CEEEE"})
|
@URIPath(
|
||||||
|
method = HttpMethod.GET,
|
||||||
|
value = {"/SCIDE/ABC/", "/SCIDE/CEEEE"})
|
||||||
public void h2(ChannelHandlerContext ctx, FullHttpRequest request) {
|
public void h2(ChannelHandlerContext ctx, FullHttpRequest request) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@URIPath(method = HttpMethod.GET, value = {"/"})
|
@URIPath(
|
||||||
|
method = HttpMethod.GET,
|
||||||
|
value = {"/"})
|
||||||
public void h3(ChannelHandlerContext ctx, FullHttpRequest request) {
|
public void h3(ChannelHandlerContext ctx, FullHttpRequest request) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@URIPath(method = HttpMethod.GET, value = {"/client"})
|
@URIPath(
|
||||||
|
method = HttpMethod.GET,
|
||||||
|
value = {"/client"})
|
||||||
public void h4(ChannelHandlerContext ctx, FullHttpRequest request) {
|
public void h4(ChannelHandlerContext ctx, FullHttpRequest request) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,7 @@ public class PermissionTest {
|
|||||||
for (Permission p : setNodeManager) {
|
for (Permission p : setNodeManager) {
|
||||||
NodeManager |= p.getValue();
|
NodeManager |= p.getValue();
|
||||||
}
|
}
|
||||||
System.out
|
System.out.println("[NodeManager]" + String.format("0x%xL", NodeManager) + " " + NodeManager);
|
||||||
.println("[NodeManager]" + String.format("0x%xL", NodeManager) + " " + NodeManager);
|
|
||||||
|
|
||||||
EnumSet<Permission> setContractProvider = EnumSet.noneOf(Permission.class);
|
EnumSet<Permission> setContractProvider = EnumSet.noneOf(Permission.class);
|
||||||
// 合约提供者
|
// 合约提供者
|
||||||
@ -75,8 +74,7 @@ public class PermissionTest {
|
|||||||
for (Permission p : ContractInstanceManager) {
|
for (Permission p : ContractInstanceManager) {
|
||||||
ContractInstanceManagerVAL |= p.getValue();
|
ContractInstanceManagerVAL |= p.getValue();
|
||||||
}
|
}
|
||||||
System.out.println(
|
System.out.println("[ContractInstanceManager]" + String.format("0x%xL", ContractInstanceManagerVAL));
|
||||||
"[ContractInstanceManager]" + String.format("0x%xL", ContractInstanceManagerVAL));
|
|
||||||
|
|
||||||
EnumSet<Permission> ContractUser = EnumSet.noneOf(Permission.class);
|
EnumSet<Permission> ContractUser = EnumSet.noneOf(Permission.class);
|
||||||
// 合约使用者
|
// 合约使用者
|
||||||
|
@ -42,8 +42,13 @@ public class BDLedgerClient {
|
|||||||
public void send() {
|
public void send() {
|
||||||
String mockedFrom = "0xb60e8dd61c5d32be8058bb8eb970870f07233155";
|
String mockedFrom = "0xb60e8dd61c5d32be8058bb8eb970870f07233155";
|
||||||
|
|
||||||
LedgerProto.SendTransactionResponse ret2 = client.sendTransactionSync("default",
|
LedgerProto.SendTransactionResponse ret2 =
|
||||||
CommonProto.TransactionType.MESSAGE, mockedFrom, random.nextLong(), mockedFrom,
|
client.sendTransactionSync(
|
||||||
|
"default",
|
||||||
|
CommonProto.TransactionType.MESSAGE,
|
||||||
|
mockedFrom,
|
||||||
|
random.nextLong(),
|
||||||
|
mockedFrom,
|
||||||
"Hellooooo".getBytes(StandardCharsets.UTF_8));
|
"Hellooooo".getBytes(StandardCharsets.UTF_8));
|
||||||
ByteString hash = ret2.getHash();
|
ByteString hash = ret2.getHash();
|
||||||
System.out.println("[BDLedgerClient] hash:" + byteArray2Str(hash.toByteArray(), 0));
|
System.out.println("[BDLedgerClient] hash:" + byteArray2Str(hash.toByteArray(), 0));
|
||||||
@ -55,7 +60,9 @@ public class BDLedgerClient {
|
|||||||
// "ea508a07b79afc03c94a84ff190ca29f1153ef75"
|
// "ea508a07b79afc03c94a84ff190ca29f1153ef75"
|
||||||
// cb304919522a4acd8f2b23fadf993829ac40795a
|
// cb304919522a4acd8f2b23fadf993829ac40795a
|
||||||
QueryProto.GetBlocksResponse blocks =
|
QueryProto.GetBlocksResponse blocks =
|
||||||
client.getBlocksSync("default", System.currentTimeMillis() - 23L * 3600L * 1000L,
|
client.getBlocksSync(
|
||||||
|
"default",
|
||||||
|
System.currentTimeMillis() - 23L * 3600L * 1000L,
|
||||||
QueryProto.IncludeTransactions.FULL);
|
QueryProto.IncludeTransactions.FULL);
|
||||||
System.out.println("BlockCount:" + blocks.getBlocksCount());
|
System.out.println("BlockCount:" + blocks.getBlocksCount());
|
||||||
// GetTransactionByHashResponse result = client.getTransactionByHashSync("test",
|
// GetTransactionByHashResponse result = client.getTransactionByHashSync("test",
|
||||||
@ -68,8 +75,9 @@ public class BDLedgerClient {
|
|||||||
public void queryTransaction() {
|
public void queryTransaction() {
|
||||||
// test2 31b50daa8d607c673af5ef449a4d78c70bf952d4
|
// test2 31b50daa8d607c673af5ef449a4d78c70bf952d4
|
||||||
// bdcontract cb304919522a4acd8f2b23fadf993829ac40795a
|
// bdcontract cb304919522a4acd8f2b23fadf993829ac40795a
|
||||||
QueryProto.GetTransactionByHashResponse result = client.getTransactionByHashSync("default",
|
QueryProto.GetTransactionByHashResponse result =
|
||||||
"78bf9fb27963b26bf2f8d558f20bf44559178b67");
|
client.getTransactionByHashSync(
|
||||||
|
"default", "78bf9fb27963b26bf2f8d558f20bf44559178b67");
|
||||||
ByteString bytes = result.getTransaction().getData();
|
ByteString bytes = result.getTransaction().getData();
|
||||||
System.out.println(new String(bytes.toByteArray()));
|
System.out.println(new String(bytes.toByteArray()));
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,7 @@ public class CMHttpTest {
|
|||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "killAllContract";
|
url1 = host + "killAllContract";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "startContractBatched&fileList="
|
url1 = host + "startContractBatched&fileList=" + URLEncoder.encode("[\"algorithmExample.yjs\",\"AAA.yjs\"]");
|
||||||
+ URLEncoder.encode("[\"algorithmExample.yjs\",\"AAA.yjs\"]");
|
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
// url1 = host + "startContractInTempZips";
|
// url1 = host + "startContractInTempZips";
|
||||||
// System.out.println(httpGet(url1));
|
// System.out.println(httpGet(url1));
|
||||||
@ -53,8 +52,8 @@ public class CMHttpTest {
|
|||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "downloadUUID";
|
url1 = host + "downloadUUID";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "updateConfig&key=projectDir&val=" + URLEncoder
|
url1 = host + "updateConfig&key=projectDir&val="
|
||||||
.encode("/Users/huaqiancai/java_workspace/SmartContract/contractExamples");
|
+ URLEncoder.encode("/Users/huaqiancai/java_workspace/SmartContract/contractExamples");
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "loadConfig";
|
url1 = host + "loadConfig";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
|
@ -11,11 +11,11 @@ import org.bdware.sc.bean.ContractDesp;
|
|||||||
|
|
||||||
public class GsonParseTest {
|
public class GsonParseTest {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String jsonStr =
|
String jsonStr = "{\"action\":\"updateContract\",\"contracts\":\"[{\\\"contractID\\\":\\\"-1306108766\\\",\\\"contractName\\\":\\\"EventSuberAtCHQ\\\",\\\"events\\\":[\\\"def\\\"],\\\"exportedFunctions\\\":[{\\\"annotations\\\":[{\\\"type\\\":\\\"LogType\\\",\\\"args\\\":[\\\"\\\\\\\"Arg\\\\\\\"\\\"]}],\\\"functionName\\\":\\\"init\\\"},{\\\"annotations\\\":[{\\\"type\\\":\\\"LogType\\\",\\\"args\\\":[\\\"\\\\\\\"Arg\\\\\\\"\\\"]}],\\\"functionName\\\":\\\"handler\\\"}]}]\"}\n";
|
||||||
"{\"action\":\"updateContract\",\"contracts\":\"[{\\\"contractID\\\":\\\"-1306108766\\\",\\\"contractName\\\":\\\"EventSuberAtCHQ\\\",\\\"events\\\":[\\\"def\\\"],\\\"exportedFunctions\\\":[{\\\"annotations\\\":[{\\\"type\\\":\\\"LogType\\\",\\\"args\\\":[\\\"\\\\\\\"Arg\\\\\\\"\\\"]}],\\\"functionName\\\":\\\"init\\\"},{\\\"annotations\\\":[{\\\"type\\\":\\\"LogType\\\",\\\"args\\\":[\\\"\\\\\\\"Arg\\\\\\\"\\\"]}],\\\"functionName\\\":\\\"handler\\\"}]}]\"}\n";
|
|
||||||
JsonObject jo = new JsonParser().parse(jsonStr).getAsJsonObject();
|
JsonObject jo = new JsonParser().parse(jsonStr).getAsJsonObject();
|
||||||
List<ContractDesp> contracts = new Gson().fromJson(jo.get("contracts").getAsString(),
|
List<ContractDesp> contracts = new Gson().fromJson(jo.get("contracts").getAsString(),
|
||||||
new TypeToken<List<ContractDesp>>() {}.getType());
|
new TypeToken<List<ContractDesp>>() {
|
||||||
|
}.getType());
|
||||||
System.out.println(new GsonBuilder().setPrettyPrinting().create().toJson(contracts));
|
System.out.println(new GsonBuilder().setPrettyPrinting().create().toJson(contracts));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,7 @@ public class HttpPostFormTest {
|
|||||||
String BOUNDARY = "----------" + System.currentTimeMillis();
|
String BOUNDARY = "----------" + System.currentTimeMillis();
|
||||||
// httpConnection.setRequestProperty("Content-Type", "multipart/form-data;
|
// httpConnection.setRequestProperty("Content-Type", "multipart/form-data;
|
||||||
// boundary=" + BOUNDARY);
|
// boundary=" + BOUNDARY);
|
||||||
httpConnection.setRequestProperty("Content-Type",
|
httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;boundary=" + BOUNDARY);
|
||||||
"application/x-www-form-urlencoded;boundary=" + BOUNDARY);
|
|
||||||
|
|
||||||
// 连接,从postUrl.openConnection()至此的配置必须要在connect之前完成,
|
// 连接,从postUrl.openConnection()至此的配置必须要在connect之前完成,
|
||||||
// 要注意的是connection.getOutputStream会隐含的进行connect。
|
// 要注意的是connection.getOutputStream会隐含的进行connect。
|
||||||
@ -76,8 +75,7 @@ public class HttpPostFormTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader = new BufferedReader(
|
reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream(), "UTF-8"));
|
||||||
new InputStreamReader(httpConnection.getInputStream(), "UTF-8"));
|
|
||||||
while ((responseMessage = reader.readLine()) != null) {
|
while ((responseMessage = reader.readLine()) != null) {
|
||||||
response.append(responseMessage);
|
response.append(responseMessage);
|
||||||
response.append("\n");
|
response.append("\n");
|
||||||
|
@ -27,8 +27,7 @@ public class NCHttpTest {
|
|||||||
url1 = host + "updateContract";
|
url1 = host + "updateContract";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
|
|
||||||
url1 = host
|
url1 = host + "executeContractOnOtherNodes&requestID=33333&contractRequest={\"contractID\":\"BDCoin\",\"action\":\"totalSupply\",\"arg\":\"n\"}";
|
||||||
+ "executeContractOnOtherNodes&requestID=33333&contractRequest={\"contractID\":\"BDCoin\",\"action\":\"totalSupply\",\"arg\":\"n\"}";
|
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
// url1 = host + "startContractInTempZips";
|
// url1 = host + "startContractInTempZips";
|
||||||
// System.out.println(httpGet(url1));
|
// System.out.println(httpGet(url1));
|
||||||
@ -41,8 +40,8 @@ public class NCHttpTest {
|
|||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "downloadUUID";
|
url1 = host + "downloadUUID";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "updateConfig&key=projectDir&val=" + URLEncoder
|
url1 = host + "updateConfig&key=projectDir&val="
|
||||||
.encode("/Users/huaqiancai/java_workspace/SmartContract/contractExamples");
|
+ URLEncoder.encode("/Users/huaqiancai/java_workspace/SmartContract/contractExamples");
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "loadConfig";
|
url1 = host + "loadConfig";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
|
@ -4,19 +4,16 @@ public class StringTest {
|
|||||||
public static void main(String[] arg) {
|
public static void main(String[] arg) {
|
||||||
// String str = "\\manifest.json\\dadad\\daaa";
|
// String str = "\\manifest.json\\dadad\\daaa";
|
||||||
// System.out.println(str.replaceAll("\\\\", (byte)"/"));
|
// System.out.println(str.replaceAll("\\\\", (byte)"/"));
|
||||||
byte[] arr = new byte[] {(byte) 0x1, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x2,
|
byte[] arr = new byte[] { (byte) 0x1, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x2, (byte) 0xff, (byte) 0xff,
|
||||||
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x89,
|
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x89, (byte) 0x7f, (byte) 0x51, (byte) 0x8c, (byte) 0x50,
|
||||||
(byte) 0x7f, (byte) 0x51, (byte) 0x8c, (byte) 0x50, (byte) 0xbb, (byte) 0xd0,
|
(byte) 0xbb, (byte) 0xd0, (byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xe9, (byte) 0xf4, (byte) 0xf8,
|
||||||
(byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xe9, (byte) 0xf4, (byte) 0xf8,
|
(byte) 0xfc, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x4, (byte) 0xff, (byte) 0xff, (byte) 0xff,
|
||||||
(byte) 0xfc, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x4, (byte) 0xff,
|
(byte) 0xff, (byte) 0xff, (byte) 0x89, (byte) 0x7f, (byte) 0x51, (byte) 0x8c, (byte) 0x3e, (byte) 0xf4,
|
||||||
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x89, (byte) 0x7f,
|
(byte) 0x8, (byte) 0x40, (byte) 0x9f, (byte) 0x84, (byte) 0x50, (byte) 0xbb, (byte) 0xd0, (byte) 0x7f,
|
||||||
(byte) 0x51, (byte) 0x8c, (byte) 0x3e, (byte) 0xf4, (byte) 0x8, (byte) 0x40,
|
(byte) 0xff, (byte) 0xff, (byte) 0xe9, (byte) 0xf4, (byte) 0xf8, (byte) 0xfc, (byte) 0xf8, (byte) 0xfc,
|
||||||
(byte) 0x9f, (byte) 0x84, (byte) 0x50, (byte) 0xbb, (byte) 0xd0, (byte) 0x7f,
|
(byte) 0x0 };
|
||||||
(byte) 0xff, (byte) 0xff, (byte) 0xe9, (byte) 0xf4, (byte) 0xf8, (byte) 0xfc,
|
|
||||||
(byte) 0xf8, (byte) 0xfc, (byte) 0x0};
|
|
||||||
System.out.println(new String(arr));
|
System.out.println(new String(arr));
|
||||||
String str =
|
String str = "042668227e8283cc132863cf7b83489f81056c87a19f878515d6787db7f86da7145ae05926b8e8053e59f93afdddc8705d7e17a5293b60a124a2e842d3c77cf74f";
|
||||||
"042668227e8283cc132863cf7b83489f81056c87a19f878515d6787db7f86da7145ae05926b8e8053e59f93afdddc8705d7e17a5293b60a124a2e842d3c77cf74f";
|
|
||||||
System.out.println(str.hashCode());
|
System.out.println(str.hashCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user