diff --git a/nutzboot-core/src/main/java/org/nutz/boot/config/impl/YamlConfigureLoader.java b/nutzboot-core/src/main/java/org/nutz/boot/config/impl/YamlConfigureLoader.java index 55bffea7..41ffc6c8 100644 --- a/nutzboot-core/src/main/java/org/nutz/boot/config/impl/YamlConfigureLoader.java +++ b/nutzboot-core/src/main/java/org/nutz/boot/config/impl/YamlConfigureLoader.java @@ -10,10 +10,7 @@ import org.nutz.log.Log; import org.nutz.log.Logs; import org.yaml.snakeyaml.Yaml; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -61,7 +58,7 @@ public class YamlConfigureLoader extends AbstractConfigureLoader { // 加载指定profile,如果有的话 if (conf.has("nutz.profiles.active")) { String profile = conf.get("nutz.profiles.active"); - String _path = path.substring(0, path.lastIndexOf('.')) + "-" + profile + ".yml"; + String _path = path.substring(0, path.lastIndexOf('.')) + "-" + profile + ".yaml"; readYamlPath(_path); } // 如果conf内含有nutz.boot.configure.yaml.dir配置,则读取该目录下的所有配置文件 @@ -87,7 +84,7 @@ public class YamlConfigureLoader extends AbstractConfigureLoader { if (Strings.isBlank(conf.get("app.build.version"))) { InputStream ins = resourceLoader.get("build.version"); if (ins != null) { - yamlToProperties(new Yaml().loadAs(Streams.utf8r(ins), Map.class)); + conf.load(new InputStreamReader(ins), false); } } } diff --git a/nutzboot-starter/nutzboot-starter-feign/pom.xml b/nutzboot-starter/nutzboot-starter-feign/pom.xml index 279a2ca1..7b5c9f59 100644 --- a/nutzboot-starter/nutzboot-starter-feign/pom.xml +++ b/nutzboot-starter/nutzboot-starter-feign/pom.xml @@ -60,17 +60,22 @@ com.netflix.ribbon ribbon-loadbalancer - 2.2.4 + 2.7.18 com.netflix.ribbon ribbon-core - 2.2.4 + 2.7.18 + + + com.netflix.ribbon + ribbon-archaius + 2.7.18 com.netflix.ribbon ribbon-eureka - 2.2.4 + 2.7.18 provided diff --git a/nutzboot-starter/nutzboot-starter-nacos-config/src/main/java/org/nutz/boot/starter/nacos/NacosConfigureLoader.java b/nutzboot-starter/nutzboot-starter-nacos-config/src/main/java/org/nutz/boot/starter/nacos/NacosConfigureLoader.java index 6c7cfecc..ae7125d1 100644 --- a/nutzboot-starter/nutzboot-starter-nacos-config/src/main/java/org/nutz/boot/starter/nacos/NacosConfigureLoader.java +++ b/nutzboot-starter/nutzboot-starter-nacos-config/src/main/java/org/nutz/boot/starter/nacos/NacosConfigureLoader.java @@ -1,40 +1,27 @@ package org.nutz.boot.starter.nacos; -import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY; -import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME; -import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT; -import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_RETRY_TIME; -import static com.alibaba.nacos.api.PropertyKeyConst.CONTEXT_PATH; -import static com.alibaba.nacos.api.PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG; -import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE; -import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT; -import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT_PORT; -import static com.alibaba.nacos.api.PropertyKeyConst.MAX_RETRY; -import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE; -import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY; -import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import java.util.concurrent.Executor; - +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.config.ConfigService; import org.nutz.boot.AppContext; import org.nutz.boot.annotation.PropDoc; -import org.nutz.boot.config.impl.PropertiesConfigureLoader; import org.nutz.ioc.impl.PropertiesProxy; import org.nutz.ioc.loader.annotation.Inject; import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.json.Json; +import org.nutz.json.JsonFormat; import org.nutz.lang.Lang; import org.nutz.lang.Strings; import org.nutz.lang.stream.StringInputStream; import org.nutz.lang.util.NutMap; import org.nutz.log.Log; import org.nutz.log.Logs; +import org.yaml.snakeyaml.Yaml; -import com.alibaba.nacos.api.NacosFactory; -import com.alibaba.nacos.api.config.ConfigService; +import java.io.IOException; +import java.util.*; +import java.util.concurrent.Executor; + +import static com.alibaba.nacos.api.PropertyKeyConst.*; /** * @author wentao @@ -45,8 +32,8 @@ import com.alibaba.nacos.api.config.ConfigService; * @email wizzer.cn@gmail.com * @date 2019-03-06 21:45 */ -@IocBean -public class NacosConfigureLoader extends PropertiesConfigureLoader { +@IocBean(create = "init") +public class NacosConfigureLoader { /** * 获取日志对象 */ @@ -111,13 +98,16 @@ public class NacosConfigureLoader extends PropertiesConfigureLoader { @Inject protected AppContext appContext; - + + @Inject + private PropertiesProxy conf; + protected ConfigService configService; private List configListenerList; public void addConfigListener(ConfigListener configListener) { - if(null == configListenerList) { + if (null == configListenerList) { configListenerList = new ArrayList<>(); } configListenerList.add(configListener); @@ -127,6 +117,10 @@ public class NacosConfigureLoader extends PropertiesConfigureLoader { if ("json".equals(contentType)) { NutMap configMap = new NutMap(content); conf.putAll(configMap); + } else if ("yaml".equals(contentType)) { + Map result = new HashMap<>(); + buildFlattenedMap(result, new Yaml().loadAs(content, Map.class), ""); + conf.putAll(result); } else if ("xml".equals(contentType)) { Properties properties = new Properties(); try { @@ -144,37 +138,69 @@ public class NacosConfigureLoader extends PropertiesConfigureLoader { throw Lang.makeThrow("nacos.config.data_type is not found or not recognize,only json,xml and properties are support!"); } } - + + private void buildFlattenedMap(Map result, Map source, String path) { + for (Map.Entry entry : source.entrySet()) { + String key = Strings.sNull(entry.getKey()); + if (Strings.isNotBlank(path)) { + if (key.startsWith("[")) { + key = path + key; + } else { + key = path + "." + key; + } + } + Object value = entry.getValue(); + if (value instanceof Map) { + @SuppressWarnings("unchecked") + Map map = (Map) value; + buildFlattenedMap(result, map, key); + } else if (value instanceof Collection) { + @SuppressWarnings("unchecked") + Collection collection = (Collection) value; + StringBuilder val = new StringBuilder(); + for (Object object : collection) { + String str = Strings.sNull(object); + if (str.startsWith("{") && str.endsWith("}")) { + val.append(Json.toJson(object, JsonFormat.compact())).append("\n"); + } else { + val.append(str).append("\n"); + } + } + result.put(key, val.toString()); + } else { + result.put(key, Strings.sNull(value)); + } + } + } + protected String dataId; protected String group; - @Override public void init() throws Exception { - super.init(); dataId = conf.get(NACOS_DATA_ID, conf.get("nutz.application.name", "nutzboot")); group = conf.get(NACOS_GROUP, "DEFAULT_GROUP"); configService = NacosFactory.createConfigService(getNacosConfigProperties()); String configInfo = configService.getConfigAndSignListener(dataId, group, 5000, new com.alibaba.nacos.api.config.listener.Listener() { - public Executor getExecutor() { - return null; - } + public Executor getExecutor() { + return null; + } - @Override - public void receiveConfigInfo(String configInfo) { - updateConfigString(configInfo); - if(null != configListenerList) { + @Override + public void receiveConfigInfo(String configInfo) { + updateConfigString(configInfo); + if (null != configListenerList) { for (ConfigListener configListener : configListenerList) { configListener.reloadConfig(); } } - } + } }); updateConfigString(configInfo); } - + protected void updateConfigString(String configInfo) { - log.debugf("get nacos config:%s", configInfo); + log.debugf("get nacos config:%s", configInfo); String dataType = conf.get(NACOS_DATA_TYPE, "properties"); if (Strings.isNotBlank(configInfo)) { setConfig(configInfo, dataType, conf); @@ -204,17 +230,17 @@ public class NacosConfigureLoader extends PropertiesConfigureLoader { } return properties; } - - @IocBean(name="nacosConfigService") + + @IocBean(name = "nacosConfigService") public ConfigService getConfigService() { - return configService; + return configService; } - + public String getDataId() { - return dataId; - } - + return dataId; + } + public String getGroup() { - return group; - } + return group; + } } diff --git a/nutzboot-starter/nutzboot-starter-nacos-config/src/main/resources/META-INF/nutz/org.nutz.boot.config.ConfigureLoader b/nutzboot-starter/nutzboot-starter-nacos-config/src/main/resources/META-INF/nutz/org.nutz.boot.config.ConfigureLoader deleted file mode 100644 index b882fe7f..00000000 --- a/nutzboot-starter/nutzboot-starter-nacos-config/src/main/resources/META-INF/nutz/org.nutz.boot.config.ConfigureLoader +++ /dev/null @@ -1 +0,0 @@ -org.nutz.boot.starter.nacos.NacosConfigureLoader diff --git a/nutzboot-starter/nutzboot-starter-nutz-mvc/src/main/java/org/nutz/boot/starter/nutz/mvc/NbMvcLoading.java b/nutzboot-starter/nutzboot-starter-nutz-mvc/src/main/java/org/nutz/boot/starter/nutz/mvc/NbMvcLoading.java index 578ed8e1..40ccdc0d 100644 --- a/nutzboot-starter/nutzboot-starter-nutz-mvc/src/main/java/org/nutz/boot/starter/nutz/mvc/NbMvcLoading.java +++ b/nutzboot-starter/nutzboot-starter-nutz-mvc/src/main/java/org/nutz/boot/starter/nutz/mvc/NbMvcLoading.java @@ -1,28 +1,27 @@ package org.nutz.boot.starter.nutz.mvc; -import java.util.Set; - import org.nutz.boot.AppContext; import org.nutz.boot.starter.nutz.mvc.api.ActionLoaderFace; import org.nutz.ioc.Ioc; import org.nutz.lang.Stopwatch; +import org.nutz.lang.Strings; import org.nutz.log.Log; import org.nutz.log.Logs; -import org.nutz.mvc.EntryDeterminer; -import org.nutz.mvc.LoadingException; -import org.nutz.mvc.Mvcs; -import org.nutz.mvc.NutConfig; -import org.nutz.mvc.Setup; -import org.nutz.mvc.UrlMapping; +import org.nutz.mvc.*; +import org.nutz.mvc.annotation.ChainBy; import org.nutz.mvc.annotation.Localization; +import org.nutz.mvc.impl.Loadings; +import org.nutz.mvc.impl.NutActionChainMaker; import org.nutz.mvc.impl.NutLoading; +import java.util.Set; + public class NbMvcLoading extends NutLoading { private static final Log log = Logs.get(); protected AppContext appContext = AppContext.getDefault(); - + public UrlMapping load(NutConfig config) { config.setMainModule(appContext.getMainClass()); return super.load(config); @@ -49,6 +48,21 @@ public class NbMvcLoading extends NutLoading { return modules; } + protected ActionChainMaker createChainMaker(NutConfig config, Class mainModule) { + ActionChainMaker maker; + String chain = config.getInitParameter("chain"); + if (Strings.isNotBlank(chain)) { + maker = new NutActionChainMaker(chain); + } else { + ChainBy ann = mainModule.getAnnotation(ChainBy.class); + maker = null == ann ? new NutActionChainMaker(new String[]{}) + : Loadings.evalObj(config, ann.type(), ann.args()); + } + if (log.isDebugEnabled()) + log.debugf("@ChainBy(%s)", maker.getClass().getName()); + return maker; + } + public void depose(NutConfig config) { if (log.isInfoEnabled()) log.infof("Nutz.Mvc[%s] is deposing ...", config.getAppName()); @@ -59,8 +73,7 @@ public class NbMvcLoading extends NutLoading { Setup setup = config.getAttributeAs(Setup.class, Setup.class.getName()); if (null != setup) setup.destroy(config); - } - catch (Exception e) { + } catch (Exception e) { throw new LoadingException(e); } diff --git a/nutzboot-starter/nutzboot-starter-nutz-mvc/src/main/java/org/nutz/boot/starter/nutz/mvc/NutFilterStarter.java b/nutzboot-starter/nutzboot-starter-nutz-mvc/src/main/java/org/nutz/boot/starter/nutz/mvc/NutFilterStarter.java index ae21575b..45133066 100644 --- a/nutzboot-starter/nutzboot-starter-nutz-mvc/src/main/java/org/nutz/boot/starter/nutz/mvc/NutFilterStarter.java +++ b/nutzboot-starter/nutzboot-starter-nutz-mvc/src/main/java/org/nutz/boot/starter/nutz/mvc/NutFilterStarter.java @@ -30,7 +30,8 @@ public class NutFilterStarter implements WebFilterFace { public static final String PROP_EXCLUSIONS = "nutz.mvc.exclusions"; @PropDoc(value="指定NutFilter执行顺序", defaultValue="") public static final String PROP_WEB_FILTER_ORDER_NUTZ = "web.filter.order.nutz"; - + @PropDoc(value="指定Chain文件路径", defaultValue="") + public static final String PROP_WEB_FILTER_CHAIN = "web.filter.chain.path"; @Inject protected PropertiesProxy conf; @@ -73,6 +74,7 @@ public class NutFilterStarter implements WebFilterFace { } } params.put("exclusions", conf.get(PROP_EXCLUSIONS, "") + sb); + params.put("chain", conf.get(PROP_WEB_FILTER_CHAIN, "")); return params; } diff --git a/pom.xml b/pom.xml index 8ff96e67..34078d77 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ 1.7.30 1.7.30 1.2.3 - 2.6.7 + 2.6.9 1.7.2 9.4.34.v20201102 8.5.57 @@ -29,7 +29,7 @@ 2.2.3.Final 1.7 2.6.2 - 9.5.1 + 11.1 1.5.12 3.2.0 1.2.1 @@ -49,8 +49,8 @@ 0.4.1 1.2.0 3.12.3 - 3.5.2 - 1.1.4 + 3.5.6 + 2.0.0 1.6.0 2.1.1 4.1.0 @@ -538,6 +538,11 @@ nutzboot-starter-feign ${nutzboot.version} + + org.nutz + nutzboot-starter-ftp + ${nutzboot.version} + org.nutz nutzboot-starter-nutz-mvc