diff --git a/.gitignore b/.gitignore index 44e637c..17427be 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ .factorypath .idea /fizz-gateway-community.iml +*.iml diff --git a/fizz-bootstrap/pom.xml b/fizz-bootstrap/pom.xml index 8db531c..a01fa2a 100644 --- a/fizz-bootstrap/pom.xml +++ b/fizz-bootstrap/pom.xml @@ -46,7 +46,13 @@ fizz-spring-boot-starter ${project.version} - + + + + + org.reflections + reflections + ${reflections.version} + + org.apache.curator curator-client @@ -279,5 +285,13 @@ repo file://${project.basedir}/../repo + + sonatype-snapshots + SonaType Snapshots + https://oss.sonatype.org/content/repositories/snapshots + + true + + \ No newline at end of file diff --git a/fizz-core/src/main/java/we/fizz/ConfigLoader.java b/fizz-core/src/main/java/we/fizz/ConfigLoader.java index 632d6bd..86598ea 100644 --- a/fizz-core/src/main/java/we/fizz/ConfigLoader.java +++ b/fizz-core/src/main/java/we/fizz/ConfigLoader.java @@ -31,15 +31,10 @@ import org.apache.commons.io.FileUtils; import org.noear.snack.ONode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.ReactiveStringRedisTemplate; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; -import we.fizz.input.extension.grpc.GrpcInput; -import we.fizz.input.extension.dubbo.DubboInput; -import we.fizz.input.extension.mysql.MySQLInput; -import we.fizz.input.extension.request.RequestInput; import we.flume.clients.log4j2appender.LogService; import we.util.Constants; import we.util.ReactorUtils; @@ -55,11 +50,7 @@ import java.io.IOException; import java.io.Serializable; import java.lang.ref.SoftReference; import java.nio.charset.StandardCharsets; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; /** @@ -147,10 +138,6 @@ public class ConfigLoader { public Pipeline createPipeline(String configStr) throws IOException { ONode cfgNode = ONode.loadStr(configStr); - InputFactory.registerInput(RequestInput.TYPE, RequestInput.class); - InputFactory.registerInput(MySQLInput.TYPE, MySQLInput.class); - InputFactory.registerInput(GrpcInput.TYPE, GrpcInput.class); - InputFactory.registerInput(DubboInput.TYPE, DubboInput.class); Pipeline pipeline = new Pipeline(); pipeline.setApplicationContext(appContext); @@ -213,8 +200,10 @@ public class ConfigLoader { @PostConstruct public synchronized void init() throws Exception { this.refreshLocalCache(); + InputFactory.loadInputClasses(); } + public synchronized void refreshLocalCache() throws Exception { if (formalPathPrefix == null) { formalPathPrefix = appContext.getEnvironment().getProperty("gateway.prefix", "/proxy"); @@ -372,6 +361,8 @@ public class ConfigLoader { } } String key = method.toUpperCase() + ":" + path; + // config file entry ,if you want modify the aggregate config json but not use the interface of fizz, + // you can just read the config ,transform to json format and modify it if (aggregateResources.containsKey(key) && aggregateResources.get(key) != null) { String configStr = aggregateResources.get(key); Input input = null; diff --git a/fizz-core/src/main/java/we/fizz/Step.java b/fizz-core/src/main/java/we/fizz/Step.java index 2a7e9e0..bb85c26 100644 --- a/fizz-core/src/main/java/we/fizz/Step.java +++ b/fizz-core/src/main/java/we/fizz/Step.java @@ -44,6 +44,7 @@ import we.fizz.component.IComponent; import we.fizz.component.StepContextPosition; import we.fizz.component.circle.Circle; import we.fizz.component.condition.Condition; +import we.fizz.exception.FizzRuntimeException; import we.fizz.input.Input; import we.fizz.input.InputConfig; import we.fizz.input.InputContext; diff --git a/fizz-core/src/main/java/we/fizz/input/IInput.java b/fizz-core/src/main/java/we/fizz/input/IInput.java index 5709c0f..5b02c74 100644 --- a/fizz-core/src/main/java/we/fizz/input/IInput.java +++ b/fizz-core/src/main/java/we/fizz/input/IInput.java @@ -7,6 +7,7 @@ import we.fizz.StepContext; import we.fizz.StepResponse; import java.lang.ref.SoftReference; +import java.lang.reflect.Field; import java.util.Map; public interface IInput { diff --git a/fizz-core/src/main/java/we/fizz/input/Input.java b/fizz-core/src/main/java/we/fizz/input/Input.java index a5c8ec1..f8e3952 100644 --- a/fizz-core/src/main/java/we/fizz/input/Input.java +++ b/fizz-core/src/main/java/we/fizz/input/Input.java @@ -17,8 +17,11 @@ package we.fizz.input; import java.lang.ref.SoftReference; +import java.lang.reflect.Field; import java.util.Map; + +import org.reflections.Reflections; import org.springframework.context.ConfigurableApplicationContext; import reactor.core.publisher.Mono; import we.fizz.Step; @@ -95,4 +98,14 @@ public class Input { return InputConfig.class; } + public static void initialize(Classclazz) throws IllegalAccessException { + Field field = null; + try { + field = clazz.getDeclaredField("TYPE"); + InputFactory.registerInput((InputType) field.get(null), clazz); + } catch (NoSuchFieldException e) { + // doing nothing is right + } + } + } diff --git a/fizz-core/src/main/java/we/fizz/input/InputFactory.java b/fizz-core/src/main/java/we/fizz/input/InputFactory.java index c0b611b..4a269b1 100644 --- a/fizz-core/src/main/java/we/fizz/input/InputFactory.java +++ b/fizz-core/src/main/java/we/fizz/input/InputFactory.java @@ -18,6 +18,7 @@ package we.fizz.input; import we.fizz.component.ComponentHelper; +import org.reflections.Reflections; import we.fizz.exception.FizzRuntimeException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -25,6 +26,7 @@ import java.lang.reflect.Method; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; /** * @@ -61,8 +63,9 @@ public class InputFactory { inputConfig.setComponents(ComponentHelper.buildComponents((List>) config.get("components"))); inputConfig.parse(); return inputConfig; + } else { + throw new FizzRuntimeException("can't find input config type:" + type); } - return null; } public static Input createInput(String type) { @@ -79,8 +82,17 @@ public class InputFactory { } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new FizzRuntimeException(e.getMessage()); } + } else { + throw new FizzRuntimeException("can't find input type:" + type); } - return null; } + public static void loadInputClasses() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + Reflections reflections = new Reflections("we.fizz.input"); + Set> subTypes = reflections.getSubTypesOf(Input.class); + for (ClassinputType : subTypes){ + Method initializeMethod = inputType.getMethod("initialize", Class.class); + initializeMethod.invoke(null, inputType); + } + } } diff --git a/fizz-core/src/main/java/we/fizz/input/extension/mysql/MySQLInput.java b/fizz-core/src/main/java/we/fizz/input/extension/mysql/MySQLInput.java deleted file mode 100644 index bb64ff8..0000000 --- a/fizz-core/src/main/java/we/fizz/input/extension/mysql/MySQLInput.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2020 the original author or authors. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package we.fizz.input.extension.mysql; - -import we.fizz.input.IInput; -import we.fizz.input.Input; -import we.fizz.input.InputType; - - - - - -/** - * - * @author linwaiwai - * - */ - -public class MySQLInput extends Input implements IInput { - static public InputType TYPE = new InputType("MYSQL"); - public static Class inputConfigClass (){ - return MySQLInputConfig.class; - } - -} diff --git a/fizz-core/src/main/java/we/fizz/input/extension/mysql/MySQLInputConfig.java b/fizz-core/src/main/java/we/fizz/input/extension/mysql/MySQLInputConfig.java deleted file mode 100644 index 129a925..0000000 --- a/fizz-core/src/main/java/we/fizz/input/extension/mysql/MySQLInputConfig.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2020 the original author or authors. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package we.fizz.input.extension.mysql; - -import we.fizz.input.InputConfig; - -import java.util.Map; - -/** - * - * @author linwaiwai - * - */ -public class MySQLInputConfig extends InputConfig { - - public MySQLInputConfig(Map configBody) { - super(configBody); - } - -} diff --git a/pom.xml b/pom.xml index be1fb34..01afc1c 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,8 @@ 3.4.6 4.0.1 3.5.9 + 0.8.2 + 0.9.12 @@ -39,6 +41,7 @@ fizz-plugin fizz-spring-boot-starter +