From 33f89264a622ed01e04a4b6f1cd788c10b15113e Mon Sep 17 00:00:00 2001 From: Redkale <8730487+redkale@users.noreply.github.com> Date: Thu, 29 Nov 2018 13:54:14 +0800 Subject: [PATCH] --- .../boot/watch/ServiceWatchService.java | 12 ++++++++---- .../boot/watch/SourceWatchService.java | 19 ++++++++++++++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/org/redkale/boot/watch/ServiceWatchService.java b/src/org/redkale/boot/watch/ServiceWatchService.java index 6953fac7c..e20baf579 100644 --- a/src/org/redkale/boot/watch/ServiceWatchService.java +++ b/src/org/redkale/boot/watch/ServiceWatchService.java @@ -170,25 +170,29 @@ public class ServiceWatchService extends AbstractWatchService { } @RestMapping(name = "load", auth = false, comment = "动态增加Service") - public RetResult loadService(String type, @RestUploadFile(maxLength = 10 * 1024 * 1024, fileNameReg = "\\.jar$") byte[] jar) { + public RetResult loadService(@RestParam(name = "type", comment = "Service的类名") String type, + @RestUploadFile(maxLength = 10 * 1024 * 1024, fileNameReg = "\\.jar$") byte[] jar) { //待开发 return RetResult.success(); } @RestMapping(name = "reload", auth = false, comment = "重新加载Service") - public RetResult reloadService(String name, String type) { + public RetResult reloadService(@RestParam(name = "name", comment = "Service的资源名") String name, + @RestParam(name = "type", comment = "Service的类名") String type) { //待开发 return RetResult.success(); } @RestMapping(name = "stop", auth = false, comment = "动态停止Service") - public RetResult stopService(String name, String type) { + public RetResult stopService(@RestParam(name = "name", comment = "Service的资源名") String name, + @RestParam(name = "type", comment = "Service的类名") String type) { //待开发 return RetResult.success(); } @RestMapping(name = "find", auth = false, comment = "查找Service") - public RetResult find(String name, String type) { + public RetResult find(@RestParam(name = "name", comment = "Service的资源名") String name, + @RestParam(name = "type", comment = "Service的类名") String type) { //待开发 return RetResult.success(); } diff --git a/src/org/redkale/boot/watch/SourceWatchService.java b/src/org/redkale/boot/watch/SourceWatchService.java index dfdedd145..9b6199970 100644 --- a/src/org/redkale/boot/watch/SourceWatchService.java +++ b/src/org/redkale/boot/watch/SourceWatchService.java @@ -5,9 +5,9 @@ */ package org.redkale.boot.watch; -import java.io.IOException; +import java.io.*; import java.lang.reflect.Method; -import java.util.Properties; +import java.util.*; import javax.annotation.Resource; import org.redkale.boot.Application; import org.redkale.net.http.*; @@ -16,6 +16,7 @@ import org.redkale.source.*; import org.redkale.util.*; /** + * WATCH服务, 操作DataSource源 * * @author zhangjx */ @@ -31,13 +32,25 @@ public class SourceWatchService extends AbstractWatchService { @Comment("PoolSource调用change方法失败") public static final int RET_SOURCE_METHOD_INVOKE_NOT_EXISTS = 1605_0003; + @Resource(name = "APP_HOME") + protected File home; + @Resource protected Application application; @RestMapping(name = "change", auth = false, comment = "动态更改DataSource的配置") public RetResult addNode(@RestParam(name = "name", comment = "DataSource的标识") final String name, - @RestParam(name = "properties", comment = "配置") final Properties properties) throws IOException { + @RestParam(name = "properties", comment = "配置") Properties properties, + @RestParam(name = "xmlpath", comment = "配置文件路径") String xmlpath) throws IOException { if (name == null) return new RetResult(RET_WATCH_PARAMS_ILLEGAL, "not found param (name)"); + if (properties == null && xmlpath != null) { + File f = new File(xmlpath); + if (!f.isFile()) f = new File(home, xmlpath); + if (!f.isFile()) return new RetResult(RET_WATCH_PARAMS_ILLEGAL, "not found file (" + xmlpath + ")"); + FileInputStream in = new FileInputStream(f); + Map map = DataSources.loadPersistenceXml(in); + properties = map.get(name); + } if (properties == null) return new RetResult(RET_WATCH_PARAMS_ILLEGAL, "not found param (properties)"); DataSource source = null; for (DataSource s : application.getDataSources()) {