mirror of
https://gitee.com/BDWare/front-base
synced 2025-04-27 14:22:15 +00:00
build: config spotless plugin and reformat code
This commit is contained in:
parent
912ecc21fc
commit
6dfe551a1d
@ -5,6 +5,8 @@ plugins {
|
|||||||
id 'signing'
|
id 'signing'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apply from: '../spotless.gradle'
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
java {
|
java {
|
||||||
|
@ -4,8 +4,7 @@ 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[]{
|
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, // 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
|
||||||
|
@ -5,7 +5,7 @@ import java.io.InputStreamReader;
|
|||||||
|
|
||||||
|
|
||||||
public class Entry {
|
public class Entry {
|
||||||
//release 地址:47.93.86.250 root:i1235813
|
// release 地址:47.93.86.250 root:i1235813
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
if (args == null || args.length < 2) {
|
if (args == null || args.length < 2) {
|
||||||
@ -19,7 +19,7 @@ public class Entry {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
// JavaContractServiceGrpcServer.init();
|
// JavaContractServiceGrpcServer.init();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -36,8 +36,10 @@ 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(new InputStreamReader(p.getInputStream()));
|
BufferedReader stdInput = new BufferedReader(
|
||||||
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
|
new InputStreamReader(p.getInputStream()));
|
||||||
|
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");
|
||||||
@ -46,7 +48,8 @@ public class Entry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read any errors from the attempted command
|
// read any errors from the attempted command
|
||||||
System.out.println("Here is the standard error of the command (if any):\n");
|
System.out.println(
|
||||||
|
"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);
|
||||||
}
|
}
|
||||||
@ -57,14 +60,14 @@ public class Entry {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
t2.start();
|
t2.start();
|
||||||
//CMHttpServer.start(getPort(args));
|
// CMHttpServer.start(getPort(args));
|
||||||
break;
|
break;
|
||||||
case "NC":
|
case "NC":
|
||||||
case "NodeCenter":
|
case "NodeCenter":
|
||||||
//NodeCenterServer.start(getPort(args));
|
// NodeCenterServer.start(getPort(args));
|
||||||
break;
|
break;
|
||||||
case "Index":
|
case "Index":
|
||||||
// IndexServer.start(getPort(args));
|
// IndexServer.start(getPort(args));
|
||||||
default:
|
default:
|
||||||
printUsage();
|
printUsage();
|
||||||
}
|
}
|
||||||
@ -96,4 +99,4 @@ public class Entry {
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class ActionExecutor<T, U> {
|
|||||||
// ---------- use for profiling
|
// ---------- use for profiling
|
||||||
static Map<String, Map<String, AtomicInteger>> allData = new ConcurrentHashMap<>();
|
static Map<String, Map<String, AtomicInteger>> allData = new ConcurrentHashMap<>();
|
||||||
public ExecutorService executor;
|
public ExecutorService executor;
|
||||||
// private Profiler profiler = new Profiler();
|
// private Profiler profiler = new Profiler();
|
||||||
public long permission;
|
public long permission;
|
||||||
Map<String, AtomicInteger> staticData;
|
Map<String, AtomicInteger> staticData;
|
||||||
private Map<String, Pair<Method, Object>> handlers;
|
private Map<String, Pair<Method, Object>> handlers;
|
||||||
@ -84,11 +84,8 @@ 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(
|
LOGGER.error("action ret is not void:"
|
||||||
"action ret is not void:"
|
+ obj.getClass().getCanonicalName() + "-->" + method.getName());
|
||||||
+ obj.getClass().getCanonicalName()
|
|
||||||
+ "-->"
|
|
||||||
+ method.getName());
|
|
||||||
|
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
@ -97,11 +94,9 @@ 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(
|
LOGGER.error("action ret is not void:"
|
||||||
"action ret is not void:"
|
+ obj.getClass().getCanonicalName() + "-->"
|
||||||
+ obj.getClass().getCanonicalName()
|
+ method.getName());
|
||||||
+ "-->"
|
|
||||||
+ method.getName());
|
|
||||||
|
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
@ -116,7 +111,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.info("handle : " + action + " ->" + JsonUtil.toJson(args));
|
||||||
|
|
||||||
if (null != action) {
|
if (null != action) {
|
||||||
@ -144,10 +139,8 @@ 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(
|
LOGGER.debug(pair.first.getDeclaringClass().getCanonicalName() + "->"
|
||||||
pair.first.getDeclaringClass().getCanonicalName()
|
+ pair.first.getName());
|
||||||
+ "->"
|
|
||||||
+ pair.first.getName());
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -49,12 +49,13 @@ 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, Unpooled.wrappedBuffer(bytes));
|
response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, OK,
|
||||||
|
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));
|
||||||
ctxField.channel().eventLoop().execute(this);
|
ctxField.channel().eventLoop().execute(this);
|
||||||
} // Just ignore
|
} // Just ignore
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,4 +74,4 @@ public class HttpResultCallback extends ResultCallback implements Runnable {
|
|||||||
public void setDecodeBase64() {
|
public void setDecodeBase64() {
|
||||||
decodeAsB64 = true;
|
decodeAsB64 = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,8 @@ public class HttpServerSentEventResultCallback extends HttpResultCallback implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeInitialHead() {
|
public void writeInitialHead() {
|
||||||
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1,
|
HttpResponse response =
|
||||||
HttpResponseStatus.OK);
|
new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
||||||
for (String key : extraHeaders.keySet())
|
for (String key : extraHeaders.keySet())
|
||||||
response.headers().add(key, extraHeaders.get(key));
|
response.headers().add(key, extraHeaders.get(key));
|
||||||
ctxField.writeAndFlush(response);
|
ctxField.writeAndFlush(response);
|
||||||
@ -63,13 +63,16 @@ public class HttpServerSentEventResultCallback extends HttpResultCallback implem
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
if (System.currentTimeMillis() - lastUpdate < 10000L) {
|
if (System.currentTimeMillis() - lastUpdate < 10000L) {
|
||||||
//reschedule
|
// reschedule
|
||||||
LOGGER.info("Reschedule time out");
|
LOGGER.info("Reschedule time out");
|
||||||
currentScheduler = scheduledThreadPool.schedule(this, 10, TimeUnit.SECONDS);
|
currentScheduler = scheduledThreadPool.schedule(this, 10, TimeUnit.SECONDS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!closed) {
|
if (!closed) {
|
||||||
final ByteBuf buffer = Unpooled.copiedBuffer("{\"action\":\"onDistributeFinish\",\"progress\":\"-1\",\"data\":\"timeout\"}" + "\n\n", StandardCharsets.UTF_8);
|
final ByteBuf buffer = Unpooled.copiedBuffer(
|
||||||
|
"{\"action\":\"onDistributeFinish\",\"progress\":\"-1\",\"data\":\"timeout\"}"
|
||||||
|
+ "\n\n",
|
||||||
|
StandardCharsets.UTF_8);
|
||||||
ctxField.writeAndFlush(new DefaultHttpContent(buffer));
|
ctxField.writeAndFlush(new DefaultHttpContent(buffer));
|
||||||
}
|
}
|
||||||
close();
|
close();
|
||||||
|
@ -15,10 +15,11 @@ public class ReplyUtil {
|
|||||||
resultCallback.onResult(ret);
|
resultCallback.onResult(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void replyWithStatus(ResultCallback resultCallback, String action, boolean status,Object data) {
|
public static void replyWithStatus(ResultCallback resultCallback, String action, boolean status,
|
||||||
|
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);
|
||||||
ret.put("data", data);
|
ret.put("data", data);
|
||||||
resultCallback.onResult(ret);
|
resultCallback.onResult(ret);
|
||||||
}
|
}
|
||||||
@ -27,4 +28,4 @@ public class ReplyUtil {
|
|||||||
if (json.has("requestID"))
|
if (json.has("requestID"))
|
||||||
response.responseID = json.get("requestID").getAsString();
|
response.responseID = json.get("requestID").getAsString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,33 +19,28 @@ 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 = new HashedWheelTimer(
|
public static final HashedWheelTimer timer =
|
||||||
Executors.defaultThreadFactory(),
|
new HashedWheelTimer(Executors.defaultThreadFactory(), 5, TimeUnit.MILLISECONDS, 2);
|
||||||
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<>();
|
||||||
|
|
||||||
public synchronized void wakeUp(String requestID, String result) {
|
public synchronized void wakeUp(String requestID, String result) {
|
||||||
ResultCallback ob = waitObj.get(requestID);
|
ResultCallback ob = waitObj.get(requestID);
|
||||||
// TODO 难怪之前这是注释的。
|
// TODO 难怪之前这是注释的。
|
||||||
waitObj.remove(requestID);
|
waitObj.remove(requestID);
|
||||||
// cancel timeout
|
// cancel timeout
|
||||||
if (ob != null) {
|
if (ob != null) {
|
||||||
ob.cancelTimeOut();
|
ob.cancelTimeOut();
|
||||||
ob.onResult(result);
|
ob.onResult(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void instrumentWakeUp(
|
public void instrumentWakeUp(String requestID,
|
||||||
String requestID,
|
InstrumentedResultCallback instrumentedResultCallback, JsonObject result) {
|
||||||
InstrumentedResultCallback instrumentedResultCallback,
|
|
||||||
JsonObject result) {
|
|
||||||
ResultCallback ob = waitObj.get(requestID);
|
ResultCallback ob = waitObj.get(requestID);
|
||||||
// TODO 难怪之前这是注释的。
|
// TODO 难怪之前这是注释的。
|
||||||
waitObj.remove(requestID);
|
waitObj.remove(requestID);
|
||||||
// cancel timeout
|
// cancel timeout
|
||||||
if (ob != null) {
|
if (ob != null) {
|
||||||
ob.cancelTimeOut();
|
ob.cancelTimeOut();
|
||||||
instrumentedResultCallback.onResult(ob, result);
|
instrumentedResultCallback.onResult(ob, result);
|
||||||
@ -61,7 +56,7 @@ public class SyncResult {
|
|||||||
if (!waitObj.containsKey(requestID)) {
|
if (!waitObj.containsKey(requestID)) {
|
||||||
CancelTask tt = new CancelTask(requestID);
|
CancelTask tt = new CancelTask(requestID);
|
||||||
Timeout timeout = timer.newTimeout(tt, timeOut, TimeUnit.SECONDS);
|
Timeout timeout = timer.newTimeout(tt, timeOut, TimeUnit.SECONDS);
|
||||||
// logger.debug("reqID:" + requestID + " createTimeout:" + timeout);
|
// logger.debug("reqID:" + requestID + " createTimeout:" + timeout);
|
||||||
cb.setTimeOut(timeout);
|
cb.setTimeOut(timeout);
|
||||||
waitObj.put(requestID, cb);
|
waitObj.put(requestID, cb);
|
||||||
} else {
|
} else {
|
||||||
|
@ -28,7 +28,8 @@ public class ArgParser {
|
|||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(ArgParser.class);
|
private static final Logger LOGGER = LogManager.getLogger(ArgParser.class);
|
||||||
|
|
||||||
public static JsonObject parseGetAndVerify(FullHttpRequest msg, VerifiedCallback cb) throws Exception {
|
public static JsonObject parseGetAndVerify(FullHttpRequest msg, VerifiedCallback cb)
|
||||||
|
throws Exception {
|
||||||
QueryStringDecoder decoderQuery = new QueryStringDecoder(msg.uri());
|
QueryStringDecoder decoderQuery = new QueryStringDecoder(msg.uri());
|
||||||
Map<String, List<String>> parameters = decoderQuery.parameters();
|
Map<String, List<String>> parameters = decoderQuery.parameters();
|
||||||
JsonObject transformedParam = new JsonObject();
|
JsonObject transformedParam = new JsonObject();
|
||||||
@ -41,7 +42,7 @@ public class ArgParser {
|
|||||||
// 匿名用户权限为0
|
// 匿名用户权限为0
|
||||||
transformedParam.addProperty("permission", 0);
|
transformedParam.addProperty("permission", 0);
|
||||||
transformedParam.remove("verifiedPubKey");
|
transformedParam.remove("verifiedPubKey");
|
||||||
// 验签 有pubKey就必须有sign
|
// 验签 有pubKey就必须有sign
|
||||||
String uri = URLDecoder.decode(msg.uri(), "UTF-8").split("\\?")[1];
|
String uri = URLDecoder.decode(msg.uri(), "UTF-8").split("\\?")[1];
|
||||||
int index = uri.lastIndexOf('&');
|
int index = uri.lastIndexOf('&');
|
||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
@ -49,17 +50,17 @@ public class ArgParser {
|
|||||||
return transformedParam;
|
return transformedParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void verifyParam(JsonObject transformedParam, String toVerifyStr, VerifiedCallback cb) {
|
private static void verifyParam(JsonObject transformedParam, String toVerifyStr,
|
||||||
|
VerifiedCallback cb) {
|
||||||
boolean verify = false;
|
boolean verify = false;
|
||||||
if (transformedParam.has("pubKey")) {
|
if (transformedParam.has("pubKey")) {
|
||||||
LOGGER.info("before verifying: " + toVerifyStr);
|
LOGGER.info("before verifying: " + toVerifyStr);
|
||||||
try {
|
try {
|
||||||
ECPublicKeyParameters pubKey =
|
ECPublicKeyParameters pubKey = BCECUtil.createECPublicKeyFromStrParameters(
|
||||||
BCECUtil.createECPublicKeyFromStrParameters(
|
transformedParam.get("pubKey").getAsString(), SM2Util.CURVE,
|
||||||
transformedParam.get("pubKey").getAsString(), SM2Util.CURVE, SM2Util.DOMAIN_PARAMS);
|
SM2Util.DOMAIN_PARAMS);
|
||||||
verify =
|
verify = SM2Util.verify(pubKey, toVerifyStr.getBytes(),
|
||||||
SM2Util.verify(
|
ByteUtils.fromHexString(transformedParam.get("sign").getAsString()));
|
||||||
pubKey, toVerifyStr.getBytes(), ByteUtils.fromHexString(transformedParam.get("sign").getAsString()));
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error(e.getMessage());
|
LOGGER.error(e.getMessage());
|
||||||
@ -71,7 +72,8 @@ public class ArgParser {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject parsePostAndVerify(FullHttpRequest msg, VerifiedCallback cb) throws Exception {
|
public static JsonObject parsePostAndVerify(FullHttpRequest msg, VerifiedCallback cb)
|
||||||
|
throws Exception {
|
||||||
ByteBuf content = msg.content();
|
ByteBuf content = msg.content();
|
||||||
JsonObject map =
|
JsonObject map =
|
||||||
JsonParser.parseReader(new InputStreamReader(new ByteBufInputStream(content)))
|
JsonParser.parseReader(new InputStreamReader(new ByteBufInputStream(content)))
|
||||||
@ -80,13 +82,15 @@ public class ArgParser {
|
|||||||
boolean isFirst = true;
|
boolean isFirst = true;
|
||||||
for (String key : map.keySet()) {
|
for (String key : map.keySet()) {
|
||||||
if (!key.equals("sign")) {
|
if (!key.equals("sign")) {
|
||||||
if (!isFirst) toSign.append("&");
|
if (!isFirst)
|
||||||
|
toSign.append("&");
|
||||||
isFirst = false;
|
isFirst = false;
|
||||||
toSign.append(key).append("=");
|
toSign.append(key).append("=");
|
||||||
JsonElement je = map.get(key);
|
JsonElement je = map.get(key);
|
||||||
if (je.isJsonPrimitive())
|
if (je.isJsonPrimitive())
|
||||||
toSign.append(je.getAsString());
|
toSign.append(je.getAsString());
|
||||||
else toSign.append(je.toString());
|
else
|
||||||
|
toSign.append(je.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
verifyParam(map, toSign.toString(), cb);
|
verifyParam(map, toSign.toString(), cb);
|
||||||
|
@ -24,7 +24,8 @@ 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 = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
HttpResponse response =
|
||||||
|
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,
|
||||||
@ -33,13 +34,14 @@ 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 = ctxField.write(new DefaultFileRegion(file.getChannel(), 0, file.length()),
|
ChannelFuture future =
|
||||||
ctxField.newProgressivePromise());
|
ctxField.write(new DefaultFileRegion(file.getChannel(), 0, file.length()),
|
||||||
|
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, long total) {
|
public void operationProgressed(ChannelProgressiveFuture future, long progress,
|
||||||
}
|
long total) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void operationComplete(ChannelProgressiveFuture future) throws Exception {
|
public void operationComplete(ChannelProgressiveFuture future) throws Exception {
|
||||||
|
@ -24,12 +24,8 @@ public class HttpFileHandleAdapter extends SimpleChannelInboundHandler<FullHttpR
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
|
public static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
|
||||||
FullHttpResponse response =
|
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, status,
|
||||||
new DefaultFullHttpResponse(
|
Unpooled.wrappedBuffer(("Failure: " + status + "\r\n").getBytes()));
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -61,11 +57,11 @@ public class HttpFileHandleAdapter extends SimpleChannelInboundHandler<FullHttpR
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
// 获取URI
|
// 获取URI
|
||||||
request.retain();
|
request.retain();
|
||||||
// System.out.println("[HttpFileHandlerAdapter]request.uri:" + request.uri());
|
// System.out.println("[HttpFileHandlerAdapter]request.uri:" + request.uri());
|
||||||
// String[] hoString = request.duplicate().toString().split("\n");
|
// String[] hoString = request.duplicate().toString().split("\n");
|
||||||
// if (request.uri().equals("/favicon.ico")) {
|
// if (request.uri().equals("/favicon.ico")) {
|
||||||
// request.setUri("/SCIDE/favicon.ico");
|
// request.setUri("/SCIDE/favicon.ico");
|
||||||
// }
|
// }
|
||||||
String uri = request.uri();
|
String uri = request.uri();
|
||||||
|
|
||||||
if (uri.contains("..")) {
|
if (uri.contains("..")) {
|
||||||
|
@ -1,15 +1,7 @@
|
|||||||
package org.bdware.server.http;
|
package org.bdware.server.http;
|
||||||
|
|
||||||
public enum HttpMethod {
|
public enum HttpMethod {
|
||||||
OPTIONS,
|
OPTIONS, GET, HEAD, POST, PUT, PATCH, DELETE, TRACE, CONNECT;
|
||||||
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) {
|
||||||
|
@ -80,21 +80,17 @@ 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(className.isEmpty() ? "null" : className).append(".")
|
||||||
.append(".").append(t.u.getName()).append("\n");
|
.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 =
|
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1,
|
||||||
new DefaultFullHttpResponse(
|
HttpResponseStatus.BAD_REQUEST, Unpooled.wrappedBuffer(
|
||||||
HTTP_1_1,
|
("Failure: " + HttpResponseStatus.BAD_REQUEST + "\r\n").getBytes()));
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package org.bdware.server.nodecenter;
|
package org.bdware.server.nodecenter;
|
||||||
|
|
||||||
public class Response {
|
public class Response {
|
||||||
public String responseID;
|
public String responseID;
|
||||||
public String action;
|
public String action;
|
||||||
public Object data;
|
public Object data;
|
||||||
public long executeTime;
|
public long executeTime;
|
||||||
public boolean isPrivate;
|
public boolean isPrivate;
|
||||||
}
|
}
|
||||||
|
@ -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>>() {
|
contracts = JsonUtil.fromJson(jsonStr, new TypeToken<List<ContractDesp>>() {}.getType());
|
||||||
}.getType());
|
// KeyValueDBUtil.instance.setValue(NCTables.NodesDB.toString(), pubKey,
|
||||||
// KeyValueDBUtil.instance.setValue(NCTables.NodesDB.toString(), pubKey, JsonUtil.toJson(this));
|
// JsonUtil.toJson(this));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,8 @@ 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) || desp.contractName.equals(contractIDOrName)) {
|
if (desp.contractID.equals(contractIDOrName)
|
||||||
|
|| desp.contractName.equals(contractIDOrName)) {
|
||||||
return desp.contractName;
|
return desp.contractName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,7 +45,8 @@ 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) || desp.contractName.equals(contractIDOrName))
|
if (desp.contractID.equals(contractIDOrName)
|
||||||
|
|| desp.contractName.equals(contractIDOrName))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,7 +56,8 @@ 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) || desp.contractName.equals(contractIDOrName)) {
|
if (desp.contractID.equals(contractIDOrName)
|
||||||
|
|| desp.contractName.equals(contractIDOrName)) {
|
||||||
if (desp.events.containsKey(event))
|
if (desp.events.containsKey(event))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -82,4 +85,4 @@ public class CMNodeBean {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,60 +1,54 @@
|
|||||||
package org.bdware.server.permission;
|
package org.bdware.server.permission;
|
||||||
|
|
||||||
public enum Permission {
|
public enum Permission {
|
||||||
// GetSessionID(0), GetRole(0), Login(0), // 默认权限设置为0
|
// GetSessionID(0), GetRole(0), Login(0), // 默认权限设置为0
|
||||||
// ApplyRole(1 << 0), // 匿名用户申请成为节点管理员(NodePortal)角色
|
// ApplyRole(1 << 0), // 匿名用户申请成为节点管理员(NodePortal)角色
|
||||||
// NodeStateList(1 << 1), // 中心节点查看节点管理员的所管理所有节点的状态
|
// NodeStateList(1 << 1), // 中心节点查看节点管理员的所管理所有节点的状态
|
||||||
// AuthNodeManager(1 << 2), // 授权节点管理员
|
// AuthNodeManager(1 << 2), // 授权节点管理员
|
||||||
// DeleteNodeManager(1 << 3), // 从网络中删除某个节点管理员
|
// DeleteNodeManager(1 << 3), // 从网络中删除某个节点管理员
|
||||||
// ListAllUsers(1 << 4), // ListAllUser
|
// ListAllUsers(1 << 4), // ListAllUser
|
||||||
// ListApplyUser(1 << 5), // ListApplyUser
|
// ListApplyUser(1 << 5), // ListApplyUser
|
||||||
// ListTrustCluster(1 << 6), // 查看可信执行集群列表
|
// ListTrustCluster(1 << 6), // 查看可信执行集群列表
|
||||||
// AssignTrustedCluster(1 << 7), // 分配可信执行集群
|
// AssignTrustedCluster(1 << 7), // 分配可信执行集群
|
||||||
//
|
//
|
||||||
// // ==================NodePotral===============
|
// // ==================NodePotral===============
|
||||||
// //ApplyNodeRole(1<<6),//申请节点角色
|
// //ApplyNodeRole(1<<6),//申请节点角色
|
||||||
// AuthNodeRole(1 << 8), // 授权角色
|
// AuthNodeRole(1 << 8), // 授权角色
|
||||||
// DeleteRole(1 << 9), // 从用户角色中删除某一种角色
|
// DeleteRole(1 << 9), // 从用户角色中删除某一种角色
|
||||||
// ListAllAuthUsers(1 << 10), // 查看已授权用户
|
// ListAllAuthUsers(1 << 10), // 查看已授权用户
|
||||||
// ListUnAuthUsers(1 << 11), // 查看未授权用户
|
// ListUnAuthUsers(1 << 11), // 查看未授权用户
|
||||||
//
|
//
|
||||||
// StartContract(1 << 12), ExecuteContract(1 << 13), StopContract(1 << 14), // stop和kill一样
|
// StartContract(1 << 12), ExecuteContract(1 << 13), StopContract(1 << 14), // stop和kill一样
|
||||||
// UploadContract(1 << 15), // 上传合约代码(修改代码、更新合约代码、保存代码)
|
// UploadContract(1 << 15), // 上传合约代码(修改代码、更新合约代码、保存代码)
|
||||||
// DownloadContract(1 << 16), // 下载合约代码
|
// DownloadContract(1 << 16), // 下载合约代码
|
||||||
// DeleteContract(1 << 17), // 删除合约代码
|
// DeleteContract(1 << 17), // 删除合约代码
|
||||||
//
|
//
|
||||||
// ContractCodeStatisticsList(1 << 18), // 查看合约代码统计数据(合约文件大小)
|
// ContractCodeStatisticsList(1 << 18), // 查看合约代码统计数据(合约文件大小)
|
||||||
// StaticAnalysis(1 << 19), // 静态分析
|
// StaticAnalysis(1 << 19), // 静态分析
|
||||||
// ConfigureContractPermission(1 << 20), // 配置合约权限
|
// ConfigureContractPermission(1 << 20), // 配置合约权限
|
||||||
// ContractProgressList(1L << 22L), // 查看合约进程(listContractProcess)
|
// ContractProgressList(1L << 22L), // 查看合约进程(listContractProcess)
|
||||||
//
|
//
|
||||||
// QueryActionLog(1L << 24L), // 增加listLog(时间戳)
|
// QueryActionLog(1L << 24L), // 增加listLog(时间戳)
|
||||||
// QueryUserStateLog(1L << 25L), // 查看节点日志
|
// QueryUserStateLog(1L << 25L), // 查看节点日志
|
||||||
// ListLocalNodeStatus(1L << 26L), // 节点状态(此节点)
|
// ListLocalNodeStatus(1L << 26L), // 节点状态(此节点)
|
||||||
// ListContractLog(1L << 27L), // 合约日志
|
// ListContractLog(1L << 27L), // 合约日志
|
||||||
//
|
//
|
||||||
// TimeTravel(1L << 28L), ManualDump(1L << 29L), // 手动dump
|
// TimeTravel(1L << 28L), ManualDump(1L << 29L), // 手动dump
|
||||||
// ForkContractStatus(1L << 30L), // 合约状态从别处迁移到自己本地
|
// ForkContractStatus(1L << 30L), // 合约状态从别处迁移到自己本地
|
||||||
// ConfigureNode(1L << 31L), // 配置节点信息
|
// ConfigureNode(1L << 31L), // 配置节点信息
|
||||||
// listProjects(1L << 32L),// 合约提供者
|
// listProjects(1L << 32L),// 合约提供者
|
||||||
|
|
||||||
|
|
||||||
// 新加的一些权限
|
// 新加的一些权限
|
||||||
// listLicence(1L<<33L)//证书列表 updateLicence权限也写成这个了,有没有必要分开
|
// listLicence(1L<<33L)//证书列表 updateLicence权限也写成这个了,有没有必要分开
|
||||||
|
|
||||||
// TODO: 20205/20 需要整理权限就权限和最新的权限
|
// TODO: 20205/20 需要整理权限就权限和最新的权限
|
||||||
|
|
||||||
// CenterManager (其他部分代码中出现的,暂未合并整理)
|
// CenterManager (其他部分代码中出现的,暂未合并整理)
|
||||||
ApplyRole(1 << 0),
|
ApplyRole(1 << 0), NodeStateList(1 << 1), AuthNodeManager(1 << 2), ListAllUsers(
|
||||||
NodeStateList(1 << 1),
|
1 << 3), ListApplyUser(1 << 4), DeleteNodeManager(1 << 5), ListTrustCluster(
|
||||||
AuthNodeManager(1 << 2),
|
1 << 6), AssignTrustedCluster(
|
||||||
ListAllUsers(1 << 3),
|
1 << 7), QueryActionLog(1 << 8), QueryUserStateLog(1 << 9),
|
||||||
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), // 其他地方代码中的权限
|
||||||
@ -90,4 +84,4 @@ public enum Permission {
|
|||||||
public long getValue() {
|
public long getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
package org.bdware.server.permission;
|
package org.bdware.server.permission;
|
||||||
|
|
||||||
public enum Role {
|
public enum Role {
|
||||||
CenterManager(0x3ffL),
|
CenterManager(0x3ffL), NodeManager(0xe41L), Node(0x1L), ContractProvider(
|
||||||
NodeManager(0xe41L),
|
0x3f000L), ContractInstanceManager(0x7ff10c0L), ContractUser(0x5c0000L), Anonymous(0);
|
||||||
Node(0x1L),
|
|
||||||
ContractProvider(0x3f000L),
|
|
||||||
ContractInstanceManager(0x7ff10c0L),
|
|
||||||
ContractUser(0x5c0000L),
|
|
||||||
Anonymous(0);
|
|
||||||
|
|
||||||
long value;
|
long value;
|
||||||
|
|
||||||
|
@ -5,13 +5,13 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.handler.codec.MessageToByteEncoder;
|
import io.netty.handler.codec.MessageToByteEncoder;
|
||||||
|
|
||||||
public class DelimiterBasedFrameEncoder extends MessageToByteEncoder<ByteBuf> {
|
public class DelimiterBasedFrameEncoder extends MessageToByteEncoder<ByteBuf> {
|
||||||
static byte[] delimiter = "wonbifoodie".getBytes();
|
static byte[] delimiter = "wonbifoodie".getBytes();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void encode(ChannelHandlerContext arg0, ByteBuf in, ByteBuf out) throws Exception {
|
protected void encode(ChannelHandlerContext arg0, ByteBuf in, ByteBuf out) throws Exception {
|
||||||
// System.out.println("[DelimiterBasedFrameEncoder] write:" +
|
// System.out.println("[DelimiterBasedFrameEncoder] write:" +
|
||||||
// in.readableBytes());
|
// in.readableBytes());
|
||||||
out.writeBytes(in);
|
out.writeBytes(in);
|
||||||
out.writeBytes(delimiter);
|
out.writeBytes(delimiter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,11 @@ 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
|
public class DelimiterCodec extends
|
||||||
extends CombinedChannelDuplexHandler<
|
CombinedChannelDuplexHandler<DelimiterBasedFrameDecoder, DelimiterBasedFrameEncoder> {
|
||||||
DelimiterBasedFrameDecoder, DelimiterBasedFrameEncoder> {
|
|
||||||
public DelimiterCodec() {
|
public DelimiterCodec() {
|
||||||
ByteBuf buf = Unpooled.wrappedBuffer(DelimiterBasedFrameEncoder.delimiter);
|
ByteBuf buf = Unpooled.wrappedBuffer(DelimiterBasedFrameEncoder.delimiter);
|
||||||
init(
|
init(new DelimiterBasedFrameDecoder(10 * 1024 * 1024, buf),
|
||||||
new DelimiterBasedFrameDecoder(10 * 1024 * 1024, buf),
|
|
||||||
new DelimiterBasedFrameEncoder());
|
new DelimiterBasedFrameEncoder());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,76 +25,78 @@ import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
|||||||
*/
|
*/
|
||||||
public class WebSocketIndexPageHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
|
public class WebSocketIndexPageHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
|
||||||
|
|
||||||
private final String websocketPath;
|
private final String websocketPath;
|
||||||
|
|
||||||
public WebSocketIndexPageHandler(String websocketPath) {
|
public WebSocketIndexPageHandler(String websocketPath) {
|
||||||
this.websocketPath = websocketPath;
|
this.websocketPath = websocketPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
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,
|
sendHttpResponse(ctx, req, new DefaultFullHttpResponse(req.protocolVersion(), NOT_FOUND,
|
||||||
new DefaultFullHttpResponse(req.protocolVersion(), NOT_FOUND, ctx.alloc().buffer(0)));
|
ctx.alloc().buffer(0)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!req.decoderResult().isSuccess()) {
|
if (!req.decoderResult().isSuccess()) {
|
||||||
sendHttpResponse(ctx, req,
|
sendHttpResponse(ctx, req, new DefaultFullHttpResponse(req.protocolVersion(),
|
||||||
new DefaultFullHttpResponse(req.protocolVersion(), BAD_REQUEST, ctx.alloc().buffer(0)));
|
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,
|
sendHttpResponse(ctx, req, new DefaultFullHttpResponse(req.protocolVersion(), FORBIDDEN,
|
||||||
new DefaultFullHttpResponse(req.protocolVersion(), FORBIDDEN, ctx.alloc().buffer(0)));
|
ctx.alloc().buffer(0)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the index page
|
// Send the index page
|
||||||
if ("/SCIDE/SCExecutor/".equals(req.uri()) || "/SCIDE/SCExecutor/index.html".equals(req.uri())) {
|
if ("/SCIDE/SCExecutor/".equals(req.uri())
|
||||||
String webSocketLocation = getWebSocketLocation(ctx.pipeline(), req, websocketPath);
|
|| "/SCIDE/SCExecutor/index.html".equals(req.uri())) {
|
||||||
ByteBuf content = WebSocketServerIndexPage.getContent(webSocketLocation);
|
String webSocketLocation = getWebSocketLocation(ctx.pipeline(), req, websocketPath);
|
||||||
FullHttpResponse res = new DefaultFullHttpResponse(req.protocolVersion(), OK, content);
|
ByteBuf content = WebSocketServerIndexPage.getContent(webSocketLocation);
|
||||||
res.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8");
|
FullHttpResponse res = new DefaultFullHttpResponse(req.protocolVersion(), OK, content);
|
||||||
HttpUtil.setContentLength(res, content.readableBytes());
|
res.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8");
|
||||||
sendHttpResponse(ctx, req, res);
|
HttpUtil.setContentLength(res, content.readableBytes());
|
||||||
} else {
|
sendHttpResponse(ctx, req, res);
|
||||||
sendHttpResponse(ctx, req,
|
} else {
|
||||||
new DefaultFullHttpResponse(req.protocolVersion(), NOT_FOUND, ctx.alloc().buffer(0)));
|
sendHttpResponse(ctx, req, new DefaultFullHttpResponse(req.protocolVersion(), NOT_FOUND,
|
||||||
}
|
ctx.alloc().buffer(0)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||||
cause.printStackTrace();
|
cause.printStackTrace();
|
||||||
ctx.close();
|
ctx.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendHttpResponse(ChannelHandlerContext ctx, FullHttpRequest req, FullHttpResponse res) {
|
private static void sendHttpResponse(ChannelHandlerContext ctx, FullHttpRequest req,
|
||||||
// Generate an error page if response getStatus code is not OK (200).
|
FullHttpResponse res) {
|
||||||
HttpResponseStatus responseStatus = res.status();
|
// Generate an error page if response getStatus code is not OK (200).
|
||||||
if (responseStatus.code() != 200) {
|
HttpResponseStatus responseStatus = res.status();
|
||||||
ByteBufUtil.writeUtf8(res.content(), responseStatus.toString());
|
if (responseStatus.code() != 200) {
|
||||||
HttpUtil.setContentLength(res, res.content().readableBytes());
|
ByteBufUtil.writeUtf8(res.content(), responseStatus.toString());
|
||||||
}
|
HttpUtil.setContentLength(res, res.content().readableBytes());
|
||||||
// Send the response and close the connection if necessary.
|
}
|
||||||
boolean keepAlive = HttpUtil.isKeepAlive(req) && responseStatus.code() == 200;
|
// Send the response and close the connection if necessary.
|
||||||
HttpUtil.setKeepAlive(res, keepAlive);
|
boolean keepAlive = HttpUtil.isKeepAlive(req) && responseStatus.code() == 200;
|
||||||
ChannelFuture future = ctx.writeAndFlush(res);
|
HttpUtil.setKeepAlive(res, keepAlive);
|
||||||
if (!keepAlive) {
|
ChannelFuture future = ctx.writeAndFlush(res);
|
||||||
future.addListener(ChannelFutureListener.CLOSE);
|
if (!keepAlive) {
|
||||||
}
|
future.addListener(ChannelFutureListener.CLOSE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static String getWebSocketLocation(ChannelPipeline cp, HttpRequest req, String path) {
|
private static String getWebSocketLocation(ChannelPipeline cp, HttpRequest req, String path) {
|
||||||
String protocol = "ws";
|
String protocol = "ws";
|
||||||
if (cp.get(SslHandler.class) != null) {
|
if (cp.get(SslHandler.class) != null) {
|
||||||
// SSL in use so use Secure WebSockets
|
// SSL in use so use Secure WebSockets
|
||||||
protocol = "wss";
|
protocol = "wss";
|
||||||
}
|
}
|
||||||
return protocol + "://" + req.headers().get(HttpHeaderNames.HOST) + path;
|
return protocol + "://" + req.headers().get(HttpHeaderNames.HOST) + path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,93 +9,33 @@ 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 =
|
String str = "<html><head><title>Web Socket Test</title></head>" + NEWLINE + "<body>"
|
||||||
"<html><head><title>Web Socket Test</title></head>"
|
+ NEWLINE + "<script type=\"text/javascript\">" + NEWLINE + "var socket;" + NEWLINE
|
||||||
+ NEWLINE
|
+ "if (!window.WebSocket) {" + NEWLINE + " window.WebSocket = window.MozWebSocket;"
|
||||||
+ "<body>"
|
+ NEWLINE + '}' + NEWLINE + "if (window.WebSocket) {" + NEWLINE
|
||||||
+ NEWLINE
|
+ " socket = new WebSocket(\"" + webSocketLocation + "\");" + NEWLINE
|
||||||
+ "<script type=\"text/javascript\">"
|
+ " socket.onmessage = function(event) {" + NEWLINE
|
||||||
+ NEWLINE
|
+ " var ta = document.getElementById('responseText');" + NEWLINE
|
||||||
+ "var socket;"
|
+ " ta.value = ta.value + '\\n' + event.data" + NEWLINE + " };" + NEWLINE
|
||||||
+ NEWLINE
|
+ " socket.onopen = function(event) {" + NEWLINE
|
||||||
+ "if (!window.WebSocket) {"
|
+ " var ta = document.getElementById('responseText');" + NEWLINE
|
||||||
+ NEWLINE
|
+ " ta.value = \"Web Socket opened!\";" + NEWLINE + " };" + NEWLINE
|
||||||
+ " window.WebSocket = window.MozWebSocket;"
|
+ " socket.onclose = function(event) {" + NEWLINE
|
||||||
+ NEWLINE
|
+ " var ta = document.getElementById('responseText');" + NEWLINE
|
||||||
+ '}'
|
+ " ta.value = ta.value + \"Web Socket closed\"; " + NEWLINE + " };" + NEWLINE
|
||||||
+ NEWLINE
|
+ "} else {" + NEWLINE + " alert(\"Your browser does not support Web Socket.\");"
|
||||||
+ "if (window.WebSocket) {"
|
+ NEWLINE + '}' + NEWLINE + NEWLINE + "function send(message) {" + NEWLINE
|
||||||
+ NEWLINE
|
+ " if (!window.WebSocket) { return; }" + NEWLINE
|
||||||
+ " socket = new WebSocket(\""
|
+ " if (socket.readyState == WebSocket.OPEN) {" + NEWLINE
|
||||||
+ webSocketLocation
|
+ " socket.send(message);" + NEWLINE + " } else {" + NEWLINE
|
||||||
+ "\");"
|
+ " alert(\"The socket is not open.\");" + NEWLINE + " }" + NEWLINE + '}'
|
||||||
+ NEWLINE
|
+ NEWLINE + "</script>" + NEWLINE + "<form onsubmit=\"return false;\">" + NEWLINE
|
||||||
+ " socket.onmessage = function(event) {"
|
+ "<input type=\"text\" name=\"message\" value=\"Hello, World!\"/>"
|
||||||
+ NEWLINE
|
+ "<input type=\"button\" value=\"Send Web Socket Data\"" + NEWLINE
|
||||||
+ " var ta = document.getElementById('responseText');"
|
+ " onclick=\"send(this.form.message.value)\" />" + NEWLINE
|
||||||
+ NEWLINE
|
+ "<h3>Output</h3>" + NEWLINE
|
||||||
+ " ta.value = ta.value + '\\n' + event.data"
|
+ "<textarea id=\"responseText\" style=\"width:500px;height:300px;\"></textarea>"
|
||||||
+ NEWLINE
|
+ NEWLINE + "</form>" + NEWLINE + "</body>" + NEWLINE + "</html>" + 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=\"button\" value=\"Send Web Socket Data\""
|
|
||||||
+ NEWLINE
|
|
||||||
+ " onclick=\"send(this.form.message.value)\" />"
|
|
||||||
+ NEWLINE
|
|
||||||
+ "<h3>Output</h3>"
|
|
||||||
+ NEWLINE
|
|
||||||
+ "<textarea id=\"responseText\" style=\"width:500px;height:300px;\"></textarea>"
|
|
||||||
+ NEWLINE
|
|
||||||
+ "</form>"
|
|
||||||
+ NEWLINE
|
|
||||||
+ "</body>"
|
|
||||||
+ NEWLINE
|
|
||||||
+ "</html>"
|
|
||||||
+ NEWLINE;
|
|
||||||
return Unpooled.wrappedBuffer(str.getBytes());
|
return Unpooled.wrappedBuffer(str.getBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public class IndexServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// NodeCenterServer.start(18001);
|
// NodeCenterServer.start(18001);
|
||||||
start(1614);
|
start(1614);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -44,7 +44,8 @@ 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()).addLast(new HttpObjectAggregator(65536))
|
arg0.pipeline().addLast(new HttpServerCodec())
|
||||||
|
.addLast(new HttpObjectAggregator(65536))
|
||||||
.addLast(new ChunkedWriteHandler()).addLast(serverHandler);
|
.addLast(new ChunkedWriteHandler()).addLast(serverHandler);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -20,8 +20,7 @@ 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,9 +40,9 @@ public class IndexAction {
|
|||||||
for (int i = 0; i < dataLength; i++)
|
for (int i = 0; i < dataLength; i++)
|
||||||
fout.write(1);
|
fout.write(1);
|
||||||
fout.close();
|
fout.close();
|
||||||
// LenVarTimeSerialIndex2 index = getIndexFile(fileName);
|
// LenVarTimeSerialIndex2 index = getIndexFile(fileName);
|
||||||
resultCallback.onResult(
|
resultCallback.onResult("{\"status\":\"Success\",\"dataLength\":" + dataLength
|
||||||
"{\"status\":\"Success\",\"dataLength\":" + dataLength + ",\".datasize\":" + f.length() + "}");
|
+ ",\".datasize\":" + f.length() + "}");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
@ -85,7 +84,8 @@ public class IndexAction {
|
|||||||
try {
|
try {
|
||||||
LenVarTimeSerialIndex2 index = getIndexFile(args.get("file").getAsString());
|
LenVarTimeSerialIndex2 index = getIndexFile(args.get("file").getAsString());
|
||||||
|
|
||||||
resultCallback.onResult("{\"dataSize\":" + index.dataSize + ",\"fileSize\":" + index.fileSize + "}");
|
resultCallback.onResult(
|
||||||
|
"{\"dataSize\":" + index.dataSize + ",\"fileSize\":" + index.fileSize + "}");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
|
@ -34,11 +34,10 @@ 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 = new ActionExecutor<>(
|
private static ActionExecutor<ResultCallback, JsonObject> actionExecutor =
|
||||||
Executors.newFixedThreadPool(5), new IndexAction());
|
new ActionExecutor<>(Executors.newFixedThreadPool(5), new IndexAction());
|
||||||
|
|
||||||
public IndexHttpHandler() {
|
public IndexHttpHandler() {}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelReadComplete(ChannelHandlerContext ctx) {
|
public void channelReadComplete(ChannelHandlerContext ctx) {
|
||||||
@ -58,8 +57,9 @@ 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 = new DefaultFullHttpResponse(msg.getProtocolVersion(), OK,
|
DefaultFullHttpResponse fullResponse =
|
||||||
Unpooled.wrappedBuffer(UNSUPPORTED_HTTP_METHOD.getBytes()));
|
new DefaultFullHttpResponse(msg.getProtocolVersion(), OK,
|
||||||
|
Unpooled.wrappedBuffer(UNSUPPORTED_HTTP_METHOD.getBytes()));
|
||||||
ChannelFuture f = ctx.write(fullResponse);
|
ChannelFuture f = ctx.write(fullResponse);
|
||||||
f.addListener(ChannelFutureListener.CLOSE);
|
f.addListener(ChannelFutureListener.CLOSE);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -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, OK,
|
DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
|
||||||
Unpooled.wrappedBuffer(ret));
|
OK, Unpooled.wrappedBuffer(ret));
|
||||||
ChannelFuture f = ctx.write(response);
|
ChannelFuture f = ctx.write(response);
|
||||||
f.addListener(ChannelFutureListener.CLOSE);
|
f.addListener(ChannelFutureListener.CLOSE);
|
||||||
return;
|
return;
|
||||||
|
@ -14,30 +14,22 @@ public class URIHandlerTest {
|
|||||||
handler.register(this);
|
handler.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@URIPath(
|
@URIPath(method = HttpMethod.OPTIONS, value = {"/"})
|
||||||
method = HttpMethod.OPTIONS,
|
|
||||||
value = {"/"})
|
|
||||||
public void h1(ChannelHandlerContext ctx, FullHttpRequest request) {
|
public void h1(ChannelHandlerContext ctx, FullHttpRequest request) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@URIPath(
|
@URIPath(method = HttpMethod.GET, value = {"/SCIDE/ABC/", "/SCIDE/CEEEE"})
|
||||||
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(
|
@URIPath(method = HttpMethod.GET, value = {"/"})
|
||||||
method = HttpMethod.GET,
|
|
||||||
value = {"/"})
|
|
||||||
public void h3(ChannelHandlerContext ctx, FullHttpRequest request) {
|
public void h3(ChannelHandlerContext ctx, FullHttpRequest request) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@URIPath(
|
@URIPath(method = HttpMethod.GET, value = {"/client"})
|
||||||
method = HttpMethod.GET,
|
|
||||||
value = {"/client"})
|
|
||||||
public void h4(ChannelHandlerContext ctx, FullHttpRequest request) {
|
public void h4(ChannelHandlerContext ctx, FullHttpRequest request) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -35,11 +35,12 @@ public class PermissionTest {
|
|||||||
setNodeManager.add(ManageNode);
|
setNodeManager.add(ManageNode);
|
||||||
setNodeManager.add(GetNodeInfo);
|
setNodeManager.add(GetNodeInfo);
|
||||||
setCenterManager.add(TakeScreenShot);
|
setCenterManager.add(TakeScreenShot);
|
||||||
long NodeManager = 0L;//2248150849
|
long NodeManager = 0L;// 2248150849
|
||||||
for (Permission p : setNodeManager) {
|
for (Permission p : setNodeManager) {
|
||||||
NodeManager |= p.getValue();
|
NodeManager |= p.getValue();
|
||||||
}
|
}
|
||||||
System.out.println("[NodeManager]" + String.format("0x%xL", NodeManager) + " " + NodeManager);
|
System.out
|
||||||
|
.println("[NodeManager]" + String.format("0x%xL", NodeManager) + " " + NodeManager);
|
||||||
|
|
||||||
EnumSet<Permission> setContractProvider = EnumSet.noneOf(Permission.class);
|
EnumSet<Permission> setContractProvider = EnumSet.noneOf(Permission.class);
|
||||||
// 合约提供者
|
// 合约提供者
|
||||||
@ -74,7 +75,8 @@ public class PermissionTest {
|
|||||||
for (Permission p : ContractInstanceManager) {
|
for (Permission p : ContractInstanceManager) {
|
||||||
ContractInstanceManagerVAL |= p.getValue();
|
ContractInstanceManagerVAL |= p.getValue();
|
||||||
}
|
}
|
||||||
System.out.println("[ContractInstanceManager]" + String.format("0x%xL", ContractInstanceManagerVAL));
|
System.out.println(
|
||||||
|
"[ContractInstanceManager]" + String.format("0x%xL", ContractInstanceManagerVAL));
|
||||||
|
|
||||||
EnumSet<Permission> ContractUser = EnumSet.noneOf(Permission.class);
|
EnumSet<Permission> ContractUser = EnumSet.noneOf(Permission.class);
|
||||||
// 合约使用者
|
// 合约使用者
|
||||||
|
@ -42,14 +42,9 @@ public class BDLedgerClient {
|
|||||||
public void send() {
|
public void send() {
|
||||||
String mockedFrom = "0xb60e8dd61c5d32be8058bb8eb970870f07233155";
|
String mockedFrom = "0xb60e8dd61c5d32be8058bb8eb970870f07233155";
|
||||||
|
|
||||||
LedgerProto.SendTransactionResponse ret2 =
|
LedgerProto.SendTransactionResponse ret2 = client.sendTransactionSync("default",
|
||||||
client.sendTransactionSync(
|
CommonProto.TransactionType.MESSAGE, mockedFrom, random.nextLong(), mockedFrom,
|
||||||
"default",
|
"Hellooooo".getBytes(StandardCharsets.UTF_8));
|
||||||
CommonProto.TransactionType.MESSAGE,
|
|
||||||
mockedFrom,
|
|
||||||
random.nextLong(),
|
|
||||||
mockedFrom,
|
|
||||||
"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));
|
||||||
}
|
}
|
||||||
@ -60,9 +55,7 @@ public class BDLedgerClient {
|
|||||||
// "ea508a07b79afc03c94a84ff190ca29f1153ef75"
|
// "ea508a07b79afc03c94a84ff190ca29f1153ef75"
|
||||||
// cb304919522a4acd8f2b23fadf993829ac40795a
|
// cb304919522a4acd8f2b23fadf993829ac40795a
|
||||||
QueryProto.GetBlocksResponse blocks =
|
QueryProto.GetBlocksResponse blocks =
|
||||||
client.getBlocksSync(
|
client.getBlocksSync("default", System.currentTimeMillis() - 23L * 3600L * 1000L,
|
||||||
"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",
|
||||||
@ -73,11 +66,10 @@ public class BDLedgerClient {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void queryTransaction() {
|
public void queryTransaction() {
|
||||||
// test2 31b50daa8d607c673af5ef449a4d78c70bf952d4
|
// test2 31b50daa8d607c673af5ef449a4d78c70bf952d4
|
||||||
// bdcontract cb304919522a4acd8f2b23fadf993829ac40795a
|
// bdcontract cb304919522a4acd8f2b23fadf993829ac40795a
|
||||||
QueryProto.GetTransactionByHashResponse result =
|
QueryProto.GetTransactionByHashResponse result = client.getTransactionByHashSync("default",
|
||||||
client.getTransactionByHashSync(
|
"78bf9fb27963b26bf2f8d558f20bf44559178b67");
|
||||||
"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()));
|
||||||
}
|
}
|
||||||
|
@ -11,86 +11,87 @@ import java.util.Scanner;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
public class CMHttpTest {
|
public class CMHttpTest {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// ManagerActionsTest();
|
// ManagerActionsTest();
|
||||||
CMActionTest();
|
CMActionTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CMActionTest() {
|
private static void CMActionTest() {
|
||||||
//http_load
|
// http_load
|
||||||
String host = "http://127.0.0.1:18000/SCIDE/CMManager?action=";
|
String host = "http://127.0.0.1:18000/SCIDE/CMManager?action=";
|
||||||
String url1 = host + "ping";
|
String url1 = host + "ping";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "listContractProcess";
|
url1 = host + "listContractProcess";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "writeDyjs&target=test1120.dyjs&contractID=123&content=empty";
|
url1 = host + "writeDyjs&target=test1120.dyjs&contractID=123&content=empty";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "executeContract&contractID=BDCoin&operation=totalSupply&arg=en";
|
url1 = host + "executeContract&contractID=BDCoin&operation=totalSupply&arg=en";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "getCodeByID&contractID=DORepo";
|
url1 = host + "getCodeByID&contractID=DORepo";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "getPublicKey";
|
url1 = host + "getPublicKey";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "dumpContract&contractID=DORepo&target=dumTest.dyjs";
|
url1 = host + "dumpContract&contractID=DORepo&target=dumTest.dyjs";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "loadMemory&contractID=DORepo&target=dumTest.dyjs";
|
url1 = host + "loadMemory&contractID=DORepo&target=dumTest.dyjs";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "killContractProcess&contractID=abc";
|
url1 = host + "killContractProcess&contractID=abc";
|
||||||
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=" + URLEncoder.encode("[\"algorithmExample.yjs\",\"AAA.yjs\"]");
|
url1 = host + "startContractBatched&fileList="
|
||||||
System.out.println(httpGet(url1));
|
+ URLEncoder.encode("[\"algorithmExample.yjs\",\"AAA.yjs\"]");
|
||||||
// url1 = host + "startContractInTempZips";
|
System.out.println(httpGet(url1));
|
||||||
// System.out.println(httpGet(url1));
|
// url1 = host + "startContractInTempZips";
|
||||||
|
// System.out.println(httpGet(url1));
|
||||||
}
|
|
||||||
|
|
||||||
private static void ManagerActionsTest() {
|
}
|
||||||
String host = "http://127.0.0.1:18000/SCIDE/CMManager?action=";
|
|
||||||
String url1 = host + "getEncodedUUID";
|
|
||||||
System.out.println(httpGet(url1));
|
|
||||||
url1 = host + "downloadUUID";
|
|
||||||
System.out.println(httpGet(url1));
|
|
||||||
url1 = host + "updateConfig&key=projectDir&val="
|
|
||||||
+ URLEncoder.encode("/Users/huaqiancai/java_workspace/SmartContract/contractExamples");
|
|
||||||
System.out.println(httpGet(url1));
|
|
||||||
url1 = host + "loadConfig";
|
|
||||||
System.out.println(httpGet(url1));
|
|
||||||
url1 = host + "getLicenceExpiredDate";
|
|
||||||
System.out.println(httpGet(url1));
|
|
||||||
url1 = host + "generatePrivateKey";
|
|
||||||
System.out.println(httpGet(url1));
|
|
||||||
|
|
||||||
}
|
private static void ManagerActionsTest() {
|
||||||
|
String host = "http://127.0.0.1:18000/SCIDE/CMManager?action=";
|
||||||
|
String url1 = host + "getEncodedUUID";
|
||||||
|
System.out.println(httpGet(url1));
|
||||||
|
url1 = host + "downloadUUID";
|
||||||
|
System.out.println(httpGet(url1));
|
||||||
|
url1 = host + "updateConfig&key=projectDir&val=" + URLEncoder
|
||||||
|
.encode("/Users/huaqiancai/java_workspace/SmartContract/contractExamples");
|
||||||
|
System.out.println(httpGet(url1));
|
||||||
|
url1 = host + "loadConfig";
|
||||||
|
System.out.println(httpGet(url1));
|
||||||
|
url1 = host + "getLicenceExpiredDate";
|
||||||
|
System.out.println(httpGet(url1));
|
||||||
|
url1 = host + "generatePrivateKey";
|
||||||
|
System.out.println(httpGet(url1));
|
||||||
|
|
||||||
static class Result {
|
}
|
||||||
int resposeCode;
|
|
||||||
String response;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String httpGet(String str) {
|
static class Result {
|
||||||
System.out.println("JavaScriptEntry httpGet:" + str);
|
int resposeCode;
|
||||||
Result r = new Result();
|
String response;
|
||||||
try {
|
}
|
||||||
URL url = new URL(str);
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
public static String httpGet(String str) {
|
||||||
r.resposeCode = connection.getResponseCode();
|
System.out.println("JavaScriptEntry httpGet:" + str);
|
||||||
InputStream input = connection.getInputStream();
|
Result r = new Result();
|
||||||
Scanner sc = new Scanner(input);
|
try {
|
||||||
StringBuilder sb = new StringBuilder();
|
URL url = new URL(str);
|
||||||
for (; sc.hasNextLine();) {
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
sb.append(sc.nextLine()).append("\n");
|
r.resposeCode = connection.getResponseCode();
|
||||||
}
|
InputStream input = connection.getInputStream();
|
||||||
sc.close();
|
Scanner sc = new Scanner(input);
|
||||||
r.response = sb.toString();
|
StringBuilder sb = new StringBuilder();
|
||||||
return new Gson().toJson(r);
|
for (; sc.hasNextLine();) {
|
||||||
} catch (Throwable e) {
|
sb.append(sc.nextLine()).append("\n");
|
||||||
r.resposeCode = 505;
|
}
|
||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
sc.close();
|
||||||
e.printStackTrace(new PrintStream(bo));
|
r.response = sb.toString();
|
||||||
r.response = bo.toString();
|
return new Gson().toJson(r);
|
||||||
return new Gson().toJson(r);
|
} catch (Throwable e) {
|
||||||
}
|
r.resposeCode = 505;
|
||||||
}
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
|
e.printStackTrace(new PrintStream(bo));
|
||||||
|
r.response = bo.toString();
|
||||||
|
return new Gson().toJson(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,12 @@ import com.google.gson.reflect.TypeToken;
|
|||||||
import org.bdware.sc.bean.ContractDesp;
|
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 = "{\"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";
|
String jsonStr =
|
||||||
JsonObject jo = new JsonParser().parse(jsonStr).getAsJsonObject();
|
"{\"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";
|
||||||
List<ContractDesp> contracts = new Gson().fromJson(jo.get("contracts").getAsString(),
|
JsonObject jo = new JsonParser().parse(jsonStr).getAsJsonObject();
|
||||||
new TypeToken<List<ContractDesp>>() {
|
List<ContractDesp> contracts = new Gson().fromJson(jo.get("contracts").getAsString(),
|
||||||
}.getType());
|
new TypeToken<List<ContractDesp>>() {}.getType());
|
||||||
System.out.println(new GsonBuilder().setPrettyPrinting().create().toJson(contracts));
|
System.out.println(new GsonBuilder().setPrettyPrinting().create().toJson(contracts));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,100 +12,102 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class HttpPostFormTest {
|
public class HttpPostFormTest {
|
||||||
|
|
||||||
public static void postForm(String url, Map<String, String> params) {
|
public static void postForm(String url, Map<String, String> params) {
|
||||||
|
|
||||||
String responseMessage = "";
|
String responseMessage = "";
|
||||||
StringBuffer response = new StringBuffer();
|
StringBuffer response = new StringBuffer();
|
||||||
HttpURLConnection httpConnection = null;
|
HttpURLConnection httpConnection = null;
|
||||||
OutputStreamWriter out = null;
|
OutputStreamWriter out = null;
|
||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
try {
|
try {
|
||||||
URL urlPost = new URL(url);
|
URL urlPost = new URL(url);
|
||||||
httpConnection = (HttpURLConnection) urlPost.openConnection();
|
httpConnection = (HttpURLConnection) urlPost.openConnection();
|
||||||
httpConnection.setDoOutput(true);
|
httpConnection.setDoOutput(true);
|
||||||
httpConnection.setDoInput(true);
|
httpConnection.setDoInput(true);
|
||||||
httpConnection.setRequestMethod("POST");
|
httpConnection.setRequestMethod("POST");
|
||||||
httpConnection.setUseCaches(false);
|
httpConnection.setUseCaches(false);
|
||||||
httpConnection.setInstanceFollowRedirects(true);
|
httpConnection.setInstanceFollowRedirects(true);
|
||||||
httpConnection.setRequestProperty("Connection", "Keep-Alive");
|
httpConnection.setRequestProperty("Connection", "Keep-Alive");
|
||||||
httpConnection.setRequestProperty("Charset", "UTF-8");
|
httpConnection.setRequestProperty("Charset", "UTF-8");
|
||||||
// 设置边界
|
// 设置边界
|
||||||
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", "application/x-www-form-urlencoded;boundary=" + BOUNDARY);
|
httpConnection.setRequestProperty("Content-Type",
|
||||||
|
"application/x-www-form-urlencoded;boundary=" + BOUNDARY);
|
||||||
|
|
||||||
// 连接,从postUrl.openConnection()至此的配置必须要在connect之前完成,
|
// 连接,从postUrl.openConnection()至此的配置必须要在connect之前完成,
|
||||||
// 要注意的是connection.getOutputStream会隐含的进行connect。
|
// 要注意的是connection.getOutputStream会隐含的进行connect。
|
||||||
// 实际上只是建立了一个与服务器的tcp连接,并没有实际发送http请求。
|
// 实际上只是建立了一个与服务器的tcp连接,并没有实际发送http请求。
|
||||||
|
|
||||||
httpConnection.connect();
|
httpConnection.connect();
|
||||||
out = new OutputStreamWriter(httpConnection.getOutputStream(), "UTF-8");
|
out = new OutputStreamWriter(httpConnection.getOutputStream(), "UTF-8");
|
||||||
|
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
int count = params.size();
|
int count = params.size();
|
||||||
for (String key : params.keySet()) {
|
for (String key : params.keySet()) {
|
||||||
sb.append(key + "=" + URLEncoder.encode(params.get(key)));
|
sb.append(key + "=" + URLEncoder.encode(params.get(key)));
|
||||||
count--;
|
count--;
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
sb.append("&");
|
sb.append("&");
|
||||||
}
|
}
|
||||||
out.write(sb.toString());
|
out.write(sb.toString());
|
||||||
System.out.println("send_url:" + url);
|
System.out.println("send_url:" + url);
|
||||||
System.out.println("send_data:" + sb.toString());
|
System.out.println("send_data:" + sb.toString());
|
||||||
// flush and close
|
// flush and close
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (null != out) {
|
if (null != out) {
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
if (null != reader) {
|
if (null != reader) {
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
if (null != httpConnection) {
|
if (null != httpConnection) {
|
||||||
httpConnection.disconnect();
|
httpConnection.disconnect();
|
||||||
}
|
}
|
||||||
} catch (Exception e2) {
|
} catch (Exception e2) {
|
||||||
e2.printStackTrace();
|
e2.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream(), "UTF-8"));
|
reader = new BufferedReader(
|
||||||
while ((responseMessage = reader.readLine()) != null) {
|
new InputStreamReader(httpConnection.getInputStream(), "UTF-8"));
|
||||||
response.append(responseMessage);
|
while ((responseMessage = reader.readLine()) != null) {
|
||||||
response.append("\n");
|
response.append(responseMessage);
|
||||||
}
|
response.append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
if (!"failure".equals(response.toString())) {
|
if (!"failure".equals(response.toString())) {
|
||||||
System.out.println("success");
|
System.out.println("success");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("failue");
|
System.out.println("failue");
|
||||||
}
|
}
|
||||||
// 将该url的配置信息缓存起来
|
// 将该url的配置信息缓存起来
|
||||||
System.out.println(response.toString());
|
System.out.println(response.toString());
|
||||||
System.out.println(httpConnection.getResponseCode());
|
System.out.println(httpConnection.getResponseCode());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String url = "http://47.106.38.23:13081/register";
|
String url = "http://47.106.38.23:13081/register";
|
||||||
|
|
||||||
Map<String, String> params = new HashMap<String, String>();
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
String sucFix = System.currentTimeMillis() + "_ContractLog";
|
String sucFix = System.currentTimeMillis() + "_ContractLog";
|
||||||
params.put("DOI", "86.5000.470/" + sucFix);
|
params.put("DOI", "86.5000.470/" + sucFix);
|
||||||
params.put("Description", "Contract Log");
|
params.put("Description", "Contract Log");
|
||||||
params.put("Interface", "");
|
params.put("Interface", "");
|
||||||
params.put("Address", "");
|
params.put("Address", "");
|
||||||
params.put("PublicKey", "");
|
params.put("PublicKey", "");
|
||||||
params.put("Signature", "");
|
params.put("Signature", "");
|
||||||
// http://47.106.38.23:8080/idsystem/doDetail.html?doi=86.5000.470/1570626378959_ContractLog
|
// http://47.106.38.23:8080/idsystem/doDetail.html?doi=86.5000.470/1570626378959_ContractLog
|
||||||
postForm(url, params);
|
postForm(url, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package org.bdware.server.test;
|
package org.bdware.server.test;
|
||||||
|
|
||||||
public class LongParseTest {
|
public class LongParseTest {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String str = "6151".toUpperCase();
|
String str = "6151".toUpperCase();
|
||||||
Long.parseUnsignedLong(str, 16);
|
Long.parseUnsignedLong(str, 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,74 +11,75 @@ import java.util.Scanner;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
public class NCHttpTest {
|
public class NCHttpTest {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// ManagerActionsTest();
|
// ManagerActionsTest();
|
||||||
CMActionTest();
|
CMActionTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CMActionTest() {
|
private static void CMActionTest() {
|
||||||
String host = "http://127.0.0.1:18001/SCIDE/NodeCenter?action=";
|
String host = "http://127.0.0.1:18001/SCIDE/NodeCenter?action=";
|
||||||
String url1 = host + "ping";
|
String url1 = host + "ping";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "setNodeID";
|
url1 = host + "setNodeID";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "listCMInfo";
|
url1 = host + "listCMInfo";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "updateContract";
|
url1 = host + "updateContract";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
|
|
||||||
url1 = host + "executeContractOnOtherNodes&requestID=33333&contractRequest={\"contractID\":\"BDCoin\",\"action\":\"totalSupply\",\"arg\":\"n\"}";
|
url1 = host
|
||||||
System.out.println(httpGet(url1));
|
+ "executeContractOnOtherNodes&requestID=33333&contractRequest={\"contractID\":\"BDCoin\",\"action\":\"totalSupply\",\"arg\":\"n\"}";
|
||||||
// url1 = host + "startContractInTempZips";
|
System.out.println(httpGet(url1));
|
||||||
// System.out.println(httpGet(url1));
|
// url1 = host + "startContractInTempZips";
|
||||||
|
// System.out.println(httpGet(url1));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ManagerActionsTest() {
|
private static void ManagerActionsTest() {
|
||||||
String host = "http://127.0.0.1:18000/SCIDE/CMManager?action=";
|
String host = "http://127.0.0.1:18000/SCIDE/CMManager?action=";
|
||||||
String url1 = host + "getEncodedUUID";
|
String url1 = host + "getEncodedUUID";
|
||||||
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="
|
url1 = host + "updateConfig&key=projectDir&val=" + URLEncoder
|
||||||
+ URLEncoder.encode("/Users/huaqiancai/java_workspace/SmartContract/contractExamples");
|
.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));
|
||||||
url1 = host + "getLicenceExpiredDate";
|
url1 = host + "getLicenceExpiredDate";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
url1 = host + "generatePrivateKey";
|
url1 = host + "generatePrivateKey";
|
||||||
System.out.println(httpGet(url1));
|
System.out.println(httpGet(url1));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Result {
|
static class Result {
|
||||||
int resposeCode;
|
int resposeCode;
|
||||||
String response;
|
String response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String httpGet(String str) {
|
public static String httpGet(String str) {
|
||||||
System.out.println("JavaScriptEntry httpGet:" + str);
|
System.out.println("JavaScriptEntry httpGet:" + str);
|
||||||
Result r = new Result();
|
Result r = new Result();
|
||||||
try {
|
try {
|
||||||
URL url = new URL(str);
|
URL url = new URL(str);
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
r.resposeCode = connection.getResponseCode();
|
r.resposeCode = connection.getResponseCode();
|
||||||
InputStream input = connection.getInputStream();
|
InputStream input = connection.getInputStream();
|
||||||
Scanner sc = new Scanner(input);
|
Scanner sc = new Scanner(input);
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (; sc.hasNextLine();) {
|
for (; sc.hasNextLine();) {
|
||||||
sb.append(sc.nextLine()).append("\n");
|
sb.append(sc.nextLine()).append("\n");
|
||||||
}
|
}
|
||||||
sc.close();
|
sc.close();
|
||||||
r.response = sb.toString();
|
r.response = sb.toString();
|
||||||
return new Gson().toJson(r);
|
return new Gson().toJson(r);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
r.resposeCode = 505;
|
r.resposeCode = 505;
|
||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
e.printStackTrace(new PrintStream(bo));
|
e.printStackTrace(new PrintStream(bo));
|
||||||
r.response = bo.toString();
|
r.response = bo.toString();
|
||||||
return new Gson().toJson(r);
|
return new Gson().toJson(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
package org.bdware.server.test;
|
package org.bdware.server.test;
|
||||||
|
|
||||||
public class StringTest {
|
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) 0xff, (byte) 0xff,
|
byte[] arr = new byte[] {(byte) 0x1, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x2,
|
||||||
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x89, (byte) 0x7f, (byte) 0x51, (byte) 0x8c, (byte) 0x50,
|
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x89,
|
||||||
(byte) 0xbb, (byte) 0xd0, (byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xe9, (byte) 0xf4, (byte) 0xf8,
|
(byte) 0x7f, (byte) 0x51, (byte) 0x8c, (byte) 0x50, (byte) 0xbb, (byte) 0xd0,
|
||||||
(byte) 0xfc, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x4, (byte) 0xff, (byte) 0xff, (byte) 0xff,
|
(byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xe9, (byte) 0xf4, (byte) 0xf8,
|
||||||
(byte) 0xff, (byte) 0xff, (byte) 0x89, (byte) 0x7f, (byte) 0x51, (byte) 0x8c, (byte) 0x3e, (byte) 0xf4,
|
(byte) 0xfc, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x4, (byte) 0xff,
|
||||||
(byte) 0x8, (byte) 0x40, (byte) 0x9f, (byte) 0x84, (byte) 0x50, (byte) 0xbb, (byte) 0xd0, (byte) 0x7f,
|
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x89, (byte) 0x7f,
|
||||||
(byte) 0xff, (byte) 0xff, (byte) 0xe9, (byte) 0xf4, (byte) 0xf8, (byte) 0xfc, (byte) 0xf8, (byte) 0xfc,
|
(byte) 0x51, (byte) 0x8c, (byte) 0x3e, (byte) 0xf4, (byte) 0x8, (byte) 0x40,
|
||||||
(byte) 0x0 };
|
(byte) 0x9f, (byte) 0x84, (byte) 0x50, (byte) 0xbb, (byte) 0xd0, (byte) 0x7f,
|
||||||
System.out.println(new String(arr));
|
(byte) 0xff, (byte) 0xff, (byte) 0xe9, (byte) 0xf4, (byte) 0xf8, (byte) 0xfc,
|
||||||
String str = "042668227e8283cc132863cf7b83489f81056c87a19f878515d6787db7f86da7145ae05926b8e8053e59f93afdddc8705d7e17a5293b60a124a2e842d3c77cf74f";
|
(byte) 0xf8, (byte) 0xfc, (byte) 0x0};
|
||||||
System.out.println(str.hashCode());
|
System.out.println(new String(arr));
|
||||||
}
|
String str =
|
||||||
|
"042668227e8283cc132863cf7b83489f81056c87a19f878515d6787db7f86da7145ae05926b8e8053e59f93afdddc8705d7e17a5293b60a124a2e842d3c77cf74f";
|
||||||
|
System.out.println(str.hashCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user