diff --git a/src/org/redkale/boot/watch/AbstractWatchService.java b/src/org/redkale/boot/watch/AbstractWatchService.java index f4a993e4b..29d385c2e 100644 --- a/src/org/redkale/boot/watch/AbstractWatchService.java +++ b/src/org/redkale/boot/watch/AbstractWatchService.java @@ -17,4 +17,7 @@ public abstract class AbstractWatchService extends AbstractService implements Wa @Comment("缺少参数") public static final int RET_WATCH_PARAMS_ILLEGAL = 1600_0001; + + @Comment("执行异常") + public static final int RET_WATCH_RUN_EXCEPTION = 1600_0002; } diff --git a/src/org/redkale/boot/watch/FilterWatchService.java b/src/org/redkale/boot/watch/FilterWatchService.java index 1c0d4f31d..054292a80 100644 --- a/src/org/redkale/boot/watch/FilterWatchService.java +++ b/src/org/redkale/boot/watch/FilterWatchService.java @@ -33,7 +33,7 @@ public class FilterWatchService extends AbstractWatchService { public static final int RET_FILTER_JAR_ILLEGAL = 1601_0005; @Resource - private Application application; + protected Application application; @RestMapping(name = "addfilter", auth = false, comment = "动态增加Filter") public RetResult addFilter(@RestUploadFile(maxLength = 10 * 1024 * 1024, fileNameReg = "\\.jar$") byte[] jar, diff --git a/src/org/redkale/boot/watch/ServerWatchService.java b/src/org/redkale/boot/watch/ServerWatchService.java index 74a21e5b4..a23ec6f3c 100644 --- a/src/org/redkale/boot/watch/ServerWatchService.java +++ b/src/org/redkale/boot/watch/ServerWatchService.java @@ -24,7 +24,7 @@ public class ServerWatchService extends AbstractWatchService { public static final int RET_SERVER_NOT_EXISTS = 1602_0001; @Resource - private Application application; + protected Application application; @RestMapping(name = "info", comment = "单个Server信息查询") public RetResult info(@RestParam(name = "#port:") int port) { diff --git a/src/org/redkale/boot/watch/ServiceWatchService.java b/src/org/redkale/boot/watch/ServiceWatchService.java index 45886dcc4..6c58f16e3 100644 --- a/src/org/redkale/boot/watch/ServiceWatchService.java +++ b/src/org/redkale/boot/watch/ServiceWatchService.java @@ -5,10 +5,13 @@ */ package org.redkale.boot.watch; +import java.lang.reflect.Field; +import java.util.List; import javax.annotation.Resource; -import org.redkale.boot.Application; -import org.redkale.net.TransportFactory; +import org.redkale.boot.*; import org.redkale.net.http.*; +import org.redkale.service.RetResult; +import org.redkale.util.*; /** *

@@ -19,12 +22,52 @@ import org.redkale.net.http.*; @RestService(name = "service", catalog = "watch", repair = false) public class ServiceWatchService extends AbstractWatchService { - @Resource - private Application application; + @Comment("没有找到目标Service") + public static final int RET_SERVICE_DEST_NOT_EXISTS = 1603_0001; @Resource - private TransportFactory transportFactory; + protected Application application; + @RestMapping(name = "findfield", auth = false, comment = "查询Service中指定字段的内容") + @RestConvert(type = void.class) + public RetResult findfield(String name, String type, String field) { + if (name == null) name = ""; + if (type == null) type = ""; + if (field == null) field = ""; + type = type.trim(); + field = field.trim(); + if (type.isEmpty()) return new RetResult(RET_WATCH_PARAMS_ILLEGAL, "not found param `type`"); + if (field.isEmpty()) return new RetResult(RET_WATCH_PARAMS_ILLEGAL, "not found param `field`"); + final String name0 = name; + final String type0 = type; + Object dest = null; + for (NodeServer ns : application.getNodeServers()) { + ResourceFactory resFactory = ns.getResourceFactory(); + List list = resFactory.query((n, s) -> name0.equals(n) && s.getClass().getName().endsWith(type0)); + if (list == null || list.isEmpty()) continue; + dest = list.get(0); + } + if (dest == null) return new RetResult(RET_SERVICE_DEST_NOT_EXISTS, "not found servie (name=" + name + ", type=" + type + ")"); + Class clazz = dest.getClass(); + Throwable t = null; + try { + Field fieldObj = null; + do { + try { + fieldObj = clazz.getDeclaredField(field); + break; + } catch (Exception e) { + if (t == null) t = e; + } + } while ((clazz = clazz.getSuperclass()) != Object.class); + if (fieldObj == null) return new RetResult(RET_WATCH_RUN_EXCEPTION, "run exception (" + String.valueOf(t) + ")"); + fieldObj.setAccessible(true); + return new RetResult(fieldObj.get(dest)); + } catch (Throwable t2) { + return new RetResult(RET_WATCH_RUN_EXCEPTION, "run exception (" + t2.toString() + ")"); + } + } +// // @RestMapping(name = "load", auth = false, comment = "动态增加Service") // public RetResult loadService(String type, @RestUploadFile(maxLength = 10 * 1024 * 1024, fileNameReg = "\\.jar$") byte[] jar) { // //待开发 diff --git a/src/org/redkale/boot/watch/ServletWatchService.java b/src/org/redkale/boot/watch/ServletWatchService.java index 6d787c503..b74404b13 100644 --- a/src/org/redkale/boot/watch/ServletWatchService.java +++ b/src/org/redkale/boot/watch/ServletWatchService.java @@ -20,10 +20,10 @@ import org.redkale.net.http.*; public class ServletWatchService extends AbstractWatchService { @Resource - private Application application; + protected Application application; @Resource - private TransportFactory transportFactory; + protected TransportFactory transportFactory; // // @RestMapping(name = "load", auth = false, comment = "动态增加Servlet") // public RetResult loadServlet(String type, @RestUploadFile(maxLength = 10 * 1024 * 1024, fileNameReg = "\\.jar$") byte[] jar) { diff --git a/src/org/redkale/boot/watch/SourceWatchService.java b/src/org/redkale/boot/watch/SourceWatchService.java index 17904e696..a6697d51b 100644 --- a/src/org/redkale/boot/watch/SourceWatchService.java +++ b/src/org/redkale/boot/watch/SourceWatchService.java @@ -32,7 +32,7 @@ public class SourceWatchService extends AbstractWatchService { public static final int RET_SOURCE_METHOD_INVOKE_NOT_EXISTS = 1605_0003; @Resource - private Application application; + protected Application application; @RestMapping(name = "change", auth = false, comment = "动态更改DataSource的配置") public RetResult addNode(@RestParam(name = "name", comment = "DataSource的标识") final String name, diff --git a/src/org/redkale/boot/watch/TransportWatchService.java b/src/org/redkale/boot/watch/TransportWatchService.java index e76e2365b..c2e1111b9 100644 --- a/src/org/redkale/boot/watch/TransportWatchService.java +++ b/src/org/redkale/boot/watch/TransportWatchService.java @@ -36,10 +36,10 @@ public class TransportWatchService extends AbstractWatchService { public static final int RET_TRANSPORT_ADDR_EXISTS = 1606_0003; @Resource - private Application application; + protected Application application; @Resource - private TransportFactory transportFactory; + protected TransportFactory transportFactory; @RestMapping(name = "listnodes", auth = false, comment = "获取所有Node节点") public List listNodes() {